package impl
import (
ptag
)
func ( reflect.Value) protoreflect.Message {
:= .Type()
if .Kind() != reflect.Ptr || .Elem().Kind() != reflect.Struct {
return aberrantMessage{v: }
}
:= legacyLoadMessageInfo(, "")
return .MessageOf(.Interface())
}
func ( reflect.Type, protoreflect.FullName) protoreflect.MessageType {
if .Kind() != reflect.Ptr || .Elem().Kind() != reflect.Struct {
return aberrantMessageType{}
}
return legacyLoadMessageInfo(, )
}
var legacyMessageTypeCache sync.Map
func ( reflect.Type, protoreflect.FullName) *MessageInfo {
if , := legacyMessageTypeCache.Load(); {
return .(*MessageInfo)
}
:= &MessageInfo{
Desc: legacyLoadMessageDesc(, ),
GoReflectType: ,
}
var , bool
:= reflect.Zero().Interface()
if _, = .(legacyMarshaler); {
.methods.Marshal = legacyMarshal
.methods.Flags |= protoiface.SupportMarshalDeterministic
}
if _, = .(legacyUnmarshaler); {
.methods.Unmarshal = legacyUnmarshal
}
if , := .(legacyMerger); || ( && ) {
.methods.Merge = legacyMerge
}
if , := legacyMessageTypeCache.LoadOrStore(, ); {
return .(*MessageInfo)
}
return
}
var legacyMessageDescCache sync.Map
func ( reflect.Type) protoreflect.MessageDescriptor {
return legacyLoadMessageDesc(, "")
}
func ( reflect.Type, protoreflect.FullName) protoreflect.MessageDescriptor {
if , := legacyMessageDescCache.Load(); {
return .(protoreflect.MessageDescriptor)
}
:= reflect.Zero().Interface()
if , := .(protoreflect.ProtoMessage); {
panic(fmt.Sprintf("%v already implements proto.Message", ))
}
, := .(messageV1)
if ! {
return aberrantLoadMessageDesc(, )
}
, := func() ([]byte, []int) {
defer func() {
recover()
}()
return .Descriptor()
}()
if == nil {
return aberrantLoadMessageDesc(, )
}
if .Elem().Kind() == reflect.Struct {
if := .Elem().NumField(); > 0 {
:= false
for := 0; < ; ++ {
:= .Elem().Field()
if .Tag.Get("protobuf") != "" || .Tag.Get("protobuf_oneof") != "" || strings.HasPrefix(.Name, "XXX_") {
= true
break
}
}
if ! {
return aberrantLoadMessageDesc(, )
}
}
}
:= legacyLoadFileDesc().Messages().Get([0])
for , := range [1:] {
= .Messages().Get()
}
if != "" && .FullName() != {
panic(fmt.Sprintf("mismatching message name: got %v, want %v", .FullName(), ))
}
if , := legacyMessageDescCache.LoadOrStore(, ); {
return .(protoreflect.MessageDescriptor)
}
return
}
var (
aberrantMessageDescLock sync.Mutex
aberrantMessageDescCache map[reflect.Type]protoreflect.MessageDescriptor
)
func ( reflect.Type, protoreflect.FullName) protoreflect.MessageDescriptor {
aberrantMessageDescLock.Lock()
defer aberrantMessageDescLock.Unlock()
if aberrantMessageDescCache == nil {
aberrantMessageDescCache = make(map[reflect.Type]protoreflect.MessageDescriptor)
}
return aberrantLoadMessageDescReentrant(, )
}
func ( reflect.Type, protoreflect.FullName) protoreflect.MessageDescriptor {
if , := aberrantMessageDescCache[]; {
return
}
:= &filedesc.Message{L2: new(filedesc.MessageL2)}
.L0.FullName = aberrantDeriveMessageName(, )
.L0.ParentFile = filedesc.SurrogateProto2
aberrantMessageDescCache[] =
if .Kind() != reflect.Ptr || .Elem().Kind() != reflect.Struct {
return
}
for := 0; < .Elem().NumField(); ++ {
:= .Elem().Field()
if := .Tag.Get("protobuf"); != "" {
switch .Type.Kind() {
case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
.L0.ParentFile = filedesc.SurrogateProto3
}
for , := range strings.Split(, ",") {
if == "proto3" {
.L0.ParentFile = filedesc.SurrogateProto3
}
}
}
}
var []reflect.Type
for , := range []string{"XXX_OneofFuncs", "XXX_OneofWrappers"} {
if , := .MethodByName(); {
for , := range .Func.Call([]reflect.Value{reflect.Zero(.Type.In(0))}) {
if , := .Interface().([]interface{}); {
for , := range {
= append(, reflect.TypeOf())
}
}
}
}
}
if , := .MethodByName("ExtensionRangeArray"); {
:= .Func.Call([]reflect.Value{reflect.Zero(.Type.In(0))})[0]
for := 0; < .Len(); ++ {
:= .Index()
.L2.ExtensionRanges.List = append(.L2.ExtensionRanges.List, [2]protoreflect.FieldNumber{
protoreflect.FieldNumber(.FieldByName("Start").Int()),
protoreflect.FieldNumber(.FieldByName("End").Int() + 1),
})
.L2.ExtensionRangeOptions = append(.L2.ExtensionRangeOptions, nil)
}
}
for := 0; < .Elem().NumField(); ++ {
:= .Elem().Field()
if := .Tag.Get("protobuf"); != "" {
:= .Tag.Get("protobuf_key")
:= .Tag.Get("protobuf_val")
aberrantAppendField(, .Type, , , )
}
if := .Tag.Get("protobuf_oneof"); != "" {
:= len(.L2.Oneofs.List)
.L2.Oneofs.List = append(.L2.Oneofs.List, filedesc.Oneof{})
:= &.L2.Oneofs.List[]
.L0.FullName = .FullName().Append(protoreflect.Name())
.L0.ParentFile = .L0.ParentFile
.L0.Parent =
.L0.Index =
for , := range {
if .Implements(.Type) {
:= .Elem().Field(0)
if := .Tag.Get("protobuf"); != "" {
aberrantAppendField(, .Type, , "", "")
:= &.L2.Fields.List[len(.L2.Fields.List)-1]
.L1.ContainingOneof =
.L1.Fields.List = append(.L1.Fields.List, )
}
}
}
}
}
return
}
func ( reflect.Type, protoreflect.FullName) protoreflect.FullName {
if .IsValid() {
return
}
func() {
defer func() { recover() }()
if , := reflect.Zero().Interface().(interface{ () string }); {
= protoreflect.FullName(.())
}
}()
if .IsValid() {
return
}
if .Kind() == reflect.Ptr {
= .Elem()
}
return AberrantDeriveFullName()
}
func ( *filedesc.Message, reflect.Type, , , string) {
:=
:= .Kind() == reflect.Ptr && .Elem().Kind() != reflect.Struct
:= .Kind() == reflect.Slice && .Elem().Kind() != reflect.Uint8
if || {
= .Elem()
}
:= ptag.Unmarshal(, , placeholderEnumValues{}).(*filedesc.Field)
:= len(.L2.Fields.List)
.L2.Fields.List = append(.L2.Fields.List, *)
= &.L2.Fields.List[]
.L0.FullName = .FullName().Append(.Name())
.L0.ParentFile = .L0.ParentFile
.L0.Parent =
.L0.Index =
if .L1.IsWeak || .L1.HasPacked {
.L1.Options = func() protoreflect.ProtoMessage {
:= descopts.Field.ProtoReflect().New()
if .L1.IsWeak {
.Set(.Descriptor().Fields().ByName("weak"), protoreflect.ValueOfBool(true))
}
if .L1.HasPacked {
.Set(.Descriptor().Fields().ByName("packed"), protoreflect.ValueOfBool(.L1.IsPacked))
}
return .Interface()
}
}
if .Enum() == nil && .Kind() == protoreflect.EnumKind {
switch v := reflect.Zero().Interface().(type) {
case protoreflect.Enum:
.L1.Enum = .Descriptor()
default:
.L1.Enum = LegacyLoadEnumDesc()
}
}
if .Message() == nil && (.Kind() == protoreflect.MessageKind || .Kind() == protoreflect.GroupKind) {
switch v := reflect.Zero().Interface().(type) {
case protoreflect.ProtoMessage:
.L1.Message = .ProtoReflect().Descriptor()
case messageV1:
.L1.Message = LegacyLoadMessageDesc()
default:
if .Kind() == reflect.Map {
:= len(.L1.Messages.List)
.L1.Messages.List = append(.L1.Messages.List, filedesc.Message{L2: new(filedesc.MessageL2)})
:= &.L1.Messages.List[]
.L0.FullName = .FullName().Append(protoreflect.Name(strs.MapEntryName(string(.Name()))))
.L0.ParentFile = .L0.ParentFile
.L0.Parent =
.L0.Index =
.L1.IsMapEntry = true
.L2.Options = func() protoreflect.ProtoMessage {
:= descopts.Message.ProtoReflect().New()
.Set(.Descriptor().Fields().ByName("map_entry"), protoreflect.ValueOfBool(true))
return .Interface()
}
(, .Key(), , "", "")
(, .Elem(), , "", "")
.L1.Message =
break
}
.L1.Message = aberrantLoadMessageDescReentrant(, "")
}
}
}
type placeholderEnumValues struct {
protoreflect.EnumValueDescriptors
}
func (placeholderEnumValues) ( protoreflect.EnumNumber) protoreflect.EnumValueDescriptor {
return filedesc.PlaceholderEnumValue(protoreflect.FullName(fmt.Sprintf("UNKNOWN_%d", )))
}
type legacyMarshaler interface {
Marshal() ([]byte, error)
}
type legacyUnmarshaler interface {
Unmarshal([]byte) error
}
type legacyMerger interface {
Merge(protoiface.MessageV1)
}
var aberrantProtoMethods = &protoiface.Methods{
Marshal: legacyMarshal,
Unmarshal: legacyUnmarshal,
Merge: legacyMerge,
Flags: protoiface.SupportMarshalDeterministic,
}
func ( protoiface.MarshalInput) (protoiface.MarshalOutput, error) {
:= .Message.(unwrapper).protoUnwrap()
, := .(legacyMarshaler)
if ! {
return protoiface.MarshalOutput{}, errors.New("%T does not implement Marshal", )
}
, := .Marshal()
if .Buf != nil {
= append(.Buf, ...)
}
return protoiface.MarshalOutput{
Buf: ,
},
}
func ( protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
:= .Message.(unwrapper).protoUnwrap()
, := .(legacyUnmarshaler)
if ! {
return protoiface.UnmarshalOutput{}, errors.New("%T does not implement Unmarshal", )
}
return protoiface.UnmarshalOutput{}, .Unmarshal(.Buf)
}
func ( protoiface.MergeInput) protoiface.MergeOutput {
:= .Destination.(unwrapper).protoUnwrap()
, := .(legacyMerger)
if {
.Merge(Export{}.ProtoMessageV1Of(.Source))
return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
}
:= .Source.(unwrapper).protoUnwrap()
, := .(legacyMarshaler)
if ! {
return protoiface.MergeOutput{}
}
= .Destination.(unwrapper).protoUnwrap()
, := .(legacyUnmarshaler)
if ! {
return protoiface.MergeOutput{}
}
if !.Source.IsValid() {
return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
}
, := .Marshal()
if != nil {
return protoiface.MergeOutput{}
}
= .Unmarshal()
if != nil {
return protoiface.MergeOutput{}
}
return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
}
type aberrantMessageType struct {
t reflect.Type
}
func ( aberrantMessageType) () protoreflect.Message {
if .t.Kind() == reflect.Ptr {
return aberrantMessage{reflect.New(.t.Elem())}
}
return aberrantMessage{reflect.Zero(.t)}
}
func ( aberrantMessageType) () protoreflect.Message {
return aberrantMessage{reflect.Zero(.t)}
}
func ( aberrantMessageType) () reflect.Type {
return .t
}
func ( aberrantMessageType) () protoreflect.MessageDescriptor {
return LegacyLoadMessageDesc(.t)
}
type aberrantMessage struct {
v reflect.Value
}
func ( aberrantMessage) () {
if , := .v.Interface().(interface{ () }); {
.()
return
}
if .v.Kind() == reflect.Ptr && !.v.IsNil() {
.v.Elem().Set(reflect.Zero(.v.Type().Elem()))
}
}
func ( aberrantMessage) () protoreflect.Message {
return
}
func ( aberrantMessage) () protoreflect.MessageDescriptor {
return LegacyLoadMessageDesc(.v.Type())
}
func ( aberrantMessage) () protoreflect.MessageType {
return aberrantMessageType{.v.Type()}
}
func ( aberrantMessage) () protoreflect.Message {
if .v.Type().Kind() == reflect.Ptr {
return aberrantMessage{reflect.New(.v.Type().Elem())}
}
return aberrantMessage{reflect.Zero(.v.Type())}
}
func ( aberrantMessage) () protoreflect.ProtoMessage {
return
}
func ( aberrantMessage) ( func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
return
}
func ( aberrantMessage) (protoreflect.FieldDescriptor) bool {
return false
}
func ( aberrantMessage) (protoreflect.FieldDescriptor) {
panic("invalid Message.Clear on " + string(.Descriptor().FullName()))
}
func ( aberrantMessage) ( protoreflect.FieldDescriptor) protoreflect.Value {
if .Default().IsValid() {
return .Default()
}
panic("invalid Message.Get on " + string(.Descriptor().FullName()))
}
func ( aberrantMessage) (protoreflect.FieldDescriptor, protoreflect.Value) {
panic("invalid Message.Set on " + string(.Descriptor().FullName()))
}
func ( aberrantMessage) (protoreflect.FieldDescriptor) protoreflect.Value {
panic("invalid Message.Mutable on " + string(.Descriptor().FullName()))
}
func ( aberrantMessage) (protoreflect.FieldDescriptor) protoreflect.Value {
panic("invalid Message.NewField on " + string(.Descriptor().FullName()))
}
func ( aberrantMessage) (protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
panic("invalid Message.WhichOneof descriptor on " + string(.Descriptor().FullName()))
}
func ( aberrantMessage) () protoreflect.RawFields {
return nil
}
func ( aberrantMessage) (protoreflect.RawFields) {
}
func ( aberrantMessage) () bool {
if .v.Kind() == reflect.Ptr {
return !.v.IsNil()
}
return false
}
func ( aberrantMessage) () *protoiface.Methods {
return aberrantProtoMethods
}
func ( aberrantMessage) () interface{} {
return .v.Interface()
}