legacy_message.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568
  1. // Copyright 2018 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package impl
  5. import (
  6. "fmt"
  7. "reflect"
  8. "strings"
  9. "sync"
  10. "google.golang.org/protobuf/internal/descopts"
  11. ptag "google.golang.org/protobuf/internal/encoding/tag"
  12. "google.golang.org/protobuf/internal/errors"
  13. "google.golang.org/protobuf/internal/filedesc"
  14. "google.golang.org/protobuf/internal/strs"
  15. "google.golang.org/protobuf/reflect/protoreflect"
  16. "google.golang.org/protobuf/runtime/protoiface"
  17. )
  18. // legacyWrapMessage wraps v as a protoreflect.Message,
  19. // where v must be a *struct kind and not implement the v2 API already.
  20. func legacyWrapMessage(v reflect.Value) protoreflect.Message {
  21. t := v.Type()
  22. if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
  23. return aberrantMessage{v: v}
  24. }
  25. mt := legacyLoadMessageInfo(t, "")
  26. return mt.MessageOf(v.Interface())
  27. }
  28. // legacyLoadMessageType dynamically loads a protoreflect.Type for t,
  29. // where t must be not implement the v2 API already.
  30. // The provided name is used if it cannot be determined from the message.
  31. func legacyLoadMessageType(t reflect.Type, name protoreflect.FullName) protoreflect.MessageType {
  32. if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
  33. return aberrantMessageType{t}
  34. }
  35. return legacyLoadMessageInfo(t, name)
  36. }
  37. var legacyMessageTypeCache sync.Map // map[reflect.Type]*MessageInfo
  38. // legacyLoadMessageInfo dynamically loads a *MessageInfo for t,
  39. // where t must be a *struct kind and not implement the v2 API already.
  40. // The provided name is used if it cannot be determined from the message.
  41. func legacyLoadMessageInfo(t reflect.Type, name protoreflect.FullName) *MessageInfo {
  42. // Fast-path: check if a MessageInfo is cached for this concrete type.
  43. if mt, ok := legacyMessageTypeCache.Load(t); ok {
  44. return mt.(*MessageInfo)
  45. }
  46. // Slow-path: derive message descriptor and initialize MessageInfo.
  47. mi := &MessageInfo{
  48. Desc: legacyLoadMessageDesc(t, name),
  49. GoReflectType: t,
  50. }
  51. var hasMarshal, hasUnmarshal bool
  52. v := reflect.Zero(t).Interface()
  53. if _, hasMarshal = v.(legacyMarshaler); hasMarshal {
  54. mi.methods.Marshal = legacyMarshal
  55. // We have no way to tell whether the type's Marshal method
  56. // supports deterministic serialization or not, but this
  57. // preserves the v1 implementation's behavior of always
  58. // calling Marshal methods when present.
  59. mi.methods.Flags |= protoiface.SupportMarshalDeterministic
  60. }
  61. if _, hasUnmarshal = v.(legacyUnmarshaler); hasUnmarshal {
  62. mi.methods.Unmarshal = legacyUnmarshal
  63. }
  64. if _, hasMerge := v.(legacyMerger); hasMerge || (hasMarshal && hasUnmarshal) {
  65. mi.methods.Merge = legacyMerge
  66. }
  67. if mi, ok := legacyMessageTypeCache.LoadOrStore(t, mi); ok {
  68. return mi.(*MessageInfo)
  69. }
  70. return mi
  71. }
  72. var legacyMessageDescCache sync.Map // map[reflect.Type]protoreflect.MessageDescriptor
  73. // LegacyLoadMessageDesc returns an MessageDescriptor derived from the Go type,
  74. // which should be a *struct kind and must not implement the v2 API already.
  75. //
  76. // This is exported for testing purposes.
  77. func LegacyLoadMessageDesc(t reflect.Type) protoreflect.MessageDescriptor {
  78. return legacyLoadMessageDesc(t, "")
  79. }
  80. func legacyLoadMessageDesc(t reflect.Type, name protoreflect.FullName) protoreflect.MessageDescriptor {
  81. // Fast-path: check if a MessageDescriptor is cached for this concrete type.
  82. if mi, ok := legacyMessageDescCache.Load(t); ok {
  83. return mi.(protoreflect.MessageDescriptor)
  84. }
  85. // Slow-path: initialize MessageDescriptor from the raw descriptor.
  86. mv := reflect.Zero(t).Interface()
  87. if _, ok := mv.(protoreflect.ProtoMessage); ok {
  88. panic(fmt.Sprintf("%v already implements proto.Message", t))
  89. }
  90. mdV1, ok := mv.(messageV1)
  91. if !ok {
  92. return aberrantLoadMessageDesc(t, name)
  93. }
  94. // If this is a dynamic message type where there isn't a 1-1 mapping between
  95. // Go and protobuf types, calling the Descriptor method on the zero value of
  96. // the message type isn't likely to work. If it panics, swallow the panic and
  97. // continue as if the Descriptor method wasn't present.
  98. b, idxs := func() ([]byte, []int) {
  99. defer func() {
  100. recover()
  101. }()
  102. return mdV1.Descriptor()
  103. }()
  104. if b == nil {
  105. return aberrantLoadMessageDesc(t, name)
  106. }
  107. // If the Go type has no fields, then this might be a proto3 empty message
  108. // from before the size cache was added. If there are any fields, check to
  109. // see that at least one of them looks like something we generated.
  110. if t.Elem().Kind() == reflect.Struct {
  111. if nfield := t.Elem().NumField(); nfield > 0 {
  112. hasProtoField := false
  113. for i := 0; i < nfield; i++ {
  114. f := t.Elem().Field(i)
  115. if f.Tag.Get("protobuf") != "" || f.Tag.Get("protobuf_oneof") != "" || strings.HasPrefix(f.Name, "XXX_") {
  116. hasProtoField = true
  117. break
  118. }
  119. }
  120. if !hasProtoField {
  121. return aberrantLoadMessageDesc(t, name)
  122. }
  123. }
  124. }
  125. md := legacyLoadFileDesc(b).Messages().Get(idxs[0])
  126. for _, i := range idxs[1:] {
  127. md = md.Messages().Get(i)
  128. }
  129. if name != "" && md.FullName() != name {
  130. panic(fmt.Sprintf("mismatching message name: got %v, want %v", md.FullName(), name))
  131. }
  132. if md, ok := legacyMessageDescCache.LoadOrStore(t, md); ok {
  133. return md.(protoreflect.MessageDescriptor)
  134. }
  135. return md
  136. }
  137. var (
  138. aberrantMessageDescLock sync.Mutex
  139. aberrantMessageDescCache map[reflect.Type]protoreflect.MessageDescriptor
  140. )
  141. // aberrantLoadMessageDesc returns an MessageDescriptor derived from the Go type,
  142. // which must not implement protoreflect.ProtoMessage or messageV1.
  143. //
  144. // This is a best-effort derivation of the message descriptor using the protobuf
  145. // tags on the struct fields.
  146. func aberrantLoadMessageDesc(t reflect.Type, name protoreflect.FullName) protoreflect.MessageDescriptor {
  147. aberrantMessageDescLock.Lock()
  148. defer aberrantMessageDescLock.Unlock()
  149. if aberrantMessageDescCache == nil {
  150. aberrantMessageDescCache = make(map[reflect.Type]protoreflect.MessageDescriptor)
  151. }
  152. return aberrantLoadMessageDescReentrant(t, name)
  153. }
  154. func aberrantLoadMessageDescReentrant(t reflect.Type, name protoreflect.FullName) protoreflect.MessageDescriptor {
  155. // Fast-path: check if an MessageDescriptor is cached for this concrete type.
  156. if md, ok := aberrantMessageDescCache[t]; ok {
  157. return md
  158. }
  159. // Slow-path: construct a descriptor from the Go struct type (best-effort).
  160. // Cache the MessageDescriptor early on so that we can resolve internal
  161. // cyclic references.
  162. md := &filedesc.Message{L2: new(filedesc.MessageL2)}
  163. md.L0.FullName = aberrantDeriveMessageName(t, name)
  164. md.L0.ParentFile = filedesc.SurrogateProto2
  165. aberrantMessageDescCache[t] = md
  166. if t.Kind() != reflect.Ptr || t.Elem().Kind() != reflect.Struct {
  167. return md
  168. }
  169. // Try to determine if the message is using proto3 by checking scalars.
  170. for i := 0; i < t.Elem().NumField(); i++ {
  171. f := t.Elem().Field(i)
  172. if tag := f.Tag.Get("protobuf"); tag != "" {
  173. switch f.Type.Kind() {
  174. case reflect.Bool, reflect.Int32, reflect.Int64, reflect.Uint32, reflect.Uint64, reflect.Float32, reflect.Float64, reflect.String:
  175. md.L0.ParentFile = filedesc.SurrogateProto3
  176. }
  177. for _, s := range strings.Split(tag, ",") {
  178. if s == "proto3" {
  179. md.L0.ParentFile = filedesc.SurrogateProto3
  180. }
  181. }
  182. }
  183. }
  184. // Obtain a list of oneof wrapper types.
  185. var oneofWrappers []reflect.Type
  186. methods := make([]reflect.Method, 0, 2)
  187. if m, ok := t.MethodByName("XXX_OneofFuncs"); ok {
  188. methods = append(methods, m)
  189. }
  190. if m, ok := t.MethodByName("XXX_OneofWrappers"); ok {
  191. methods = append(methods, m)
  192. }
  193. for _, fn := range methods {
  194. for _, v := range fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))}) {
  195. if vs, ok := v.Interface().([]interface{}); ok {
  196. for _, v := range vs {
  197. oneofWrappers = append(oneofWrappers, reflect.TypeOf(v))
  198. }
  199. }
  200. }
  201. }
  202. // Obtain a list of the extension ranges.
  203. if fn, ok := t.MethodByName("ExtensionRangeArray"); ok {
  204. vs := fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0]
  205. for i := 0; i < vs.Len(); i++ {
  206. v := vs.Index(i)
  207. md.L2.ExtensionRanges.List = append(md.L2.ExtensionRanges.List, [2]protoreflect.FieldNumber{
  208. protoreflect.FieldNumber(v.FieldByName("Start").Int()),
  209. protoreflect.FieldNumber(v.FieldByName("End").Int() + 1),
  210. })
  211. md.L2.ExtensionRangeOptions = append(md.L2.ExtensionRangeOptions, nil)
  212. }
  213. }
  214. // Derive the message fields by inspecting the struct fields.
  215. for i := 0; i < t.Elem().NumField(); i++ {
  216. f := t.Elem().Field(i)
  217. if tag := f.Tag.Get("protobuf"); tag != "" {
  218. tagKey := f.Tag.Get("protobuf_key")
  219. tagVal := f.Tag.Get("protobuf_val")
  220. aberrantAppendField(md, f.Type, tag, tagKey, tagVal)
  221. }
  222. if tag := f.Tag.Get("protobuf_oneof"); tag != "" {
  223. n := len(md.L2.Oneofs.List)
  224. md.L2.Oneofs.List = append(md.L2.Oneofs.List, filedesc.Oneof{})
  225. od := &md.L2.Oneofs.List[n]
  226. od.L0.FullName = md.FullName().Append(protoreflect.Name(tag))
  227. od.L0.ParentFile = md.L0.ParentFile
  228. od.L0.Parent = md
  229. od.L0.Index = n
  230. for _, t := range oneofWrappers {
  231. if t.Implements(f.Type) {
  232. f := t.Elem().Field(0)
  233. if tag := f.Tag.Get("protobuf"); tag != "" {
  234. aberrantAppendField(md, f.Type, tag, "", "")
  235. fd := &md.L2.Fields.List[len(md.L2.Fields.List)-1]
  236. fd.L1.ContainingOneof = od
  237. od.L1.Fields.List = append(od.L1.Fields.List, fd)
  238. }
  239. }
  240. }
  241. }
  242. }
  243. return md
  244. }
  245. func aberrantDeriveMessageName(t reflect.Type, name protoreflect.FullName) protoreflect.FullName {
  246. if name.IsValid() {
  247. return name
  248. }
  249. func() {
  250. defer func() { recover() }() // swallow possible nil panics
  251. if m, ok := reflect.Zero(t).Interface().(interface{ XXX_MessageName() string }); ok {
  252. name = protoreflect.FullName(m.XXX_MessageName())
  253. }
  254. }()
  255. if name.IsValid() {
  256. return name
  257. }
  258. if t.Kind() == reflect.Ptr {
  259. t = t.Elem()
  260. }
  261. return AberrantDeriveFullName(t)
  262. }
  263. func aberrantAppendField(md *filedesc.Message, goType reflect.Type, tag, tagKey, tagVal string) {
  264. t := goType
  265. isOptional := t.Kind() == reflect.Ptr && t.Elem().Kind() != reflect.Struct
  266. isRepeated := t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8
  267. if isOptional || isRepeated {
  268. t = t.Elem()
  269. }
  270. fd := ptag.Unmarshal(tag, t, placeholderEnumValues{}).(*filedesc.Field)
  271. // Append field descriptor to the message.
  272. n := len(md.L2.Fields.List)
  273. md.L2.Fields.List = append(md.L2.Fields.List, *fd)
  274. fd = &md.L2.Fields.List[n]
  275. fd.L0.FullName = md.FullName().Append(fd.Name())
  276. fd.L0.ParentFile = md.L0.ParentFile
  277. fd.L0.Parent = md
  278. fd.L0.Index = n
  279. if fd.L1.IsWeak || fd.L1.HasPacked {
  280. fd.L1.Options = func() protoreflect.ProtoMessage {
  281. opts := descopts.Field.ProtoReflect().New()
  282. if fd.L1.IsWeak {
  283. opts.Set(opts.Descriptor().Fields().ByName("weak"), protoreflect.ValueOfBool(true))
  284. }
  285. if fd.L1.HasPacked {
  286. opts.Set(opts.Descriptor().Fields().ByName("packed"), protoreflect.ValueOfBool(fd.L1.IsPacked))
  287. }
  288. return opts.Interface()
  289. }
  290. }
  291. // Populate Enum and Message.
  292. if fd.Enum() == nil && fd.Kind() == protoreflect.EnumKind {
  293. switch v := reflect.Zero(t).Interface().(type) {
  294. case protoreflect.Enum:
  295. fd.L1.Enum = v.Descriptor()
  296. default:
  297. fd.L1.Enum = LegacyLoadEnumDesc(t)
  298. }
  299. }
  300. if fd.Message() == nil && (fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind) {
  301. switch v := reflect.Zero(t).Interface().(type) {
  302. case protoreflect.ProtoMessage:
  303. fd.L1.Message = v.ProtoReflect().Descriptor()
  304. case messageV1:
  305. fd.L1.Message = LegacyLoadMessageDesc(t)
  306. default:
  307. if t.Kind() == reflect.Map {
  308. n := len(md.L1.Messages.List)
  309. md.L1.Messages.List = append(md.L1.Messages.List, filedesc.Message{L2: new(filedesc.MessageL2)})
  310. md2 := &md.L1.Messages.List[n]
  311. md2.L0.FullName = md.FullName().Append(protoreflect.Name(strs.MapEntryName(string(fd.Name()))))
  312. md2.L0.ParentFile = md.L0.ParentFile
  313. md2.L0.Parent = md
  314. md2.L0.Index = n
  315. md2.L1.IsMapEntry = true
  316. md2.L2.Options = func() protoreflect.ProtoMessage {
  317. opts := descopts.Message.ProtoReflect().New()
  318. opts.Set(opts.Descriptor().Fields().ByName("map_entry"), protoreflect.ValueOfBool(true))
  319. return opts.Interface()
  320. }
  321. aberrantAppendField(md2, t.Key(), tagKey, "", "")
  322. aberrantAppendField(md2, t.Elem(), tagVal, "", "")
  323. fd.L1.Message = md2
  324. break
  325. }
  326. fd.L1.Message = aberrantLoadMessageDescReentrant(t, "")
  327. }
  328. }
  329. }
  330. type placeholderEnumValues struct {
  331. protoreflect.EnumValueDescriptors
  332. }
  333. func (placeholderEnumValues) ByNumber(n protoreflect.EnumNumber) protoreflect.EnumValueDescriptor {
  334. return filedesc.PlaceholderEnumValue(protoreflect.FullName(fmt.Sprintf("UNKNOWN_%d", n)))
  335. }
  336. // legacyMarshaler is the proto.Marshaler interface superseded by protoiface.Methoder.
  337. type legacyMarshaler interface {
  338. Marshal() ([]byte, error)
  339. }
  340. // legacyUnmarshaler is the proto.Unmarshaler interface superseded by protoiface.Methoder.
  341. type legacyUnmarshaler interface {
  342. Unmarshal([]byte) error
  343. }
  344. // legacyMerger is the proto.Merger interface superseded by protoiface.Methoder.
  345. type legacyMerger interface {
  346. Merge(protoiface.MessageV1)
  347. }
  348. var aberrantProtoMethods = &protoiface.Methods{
  349. Marshal: legacyMarshal,
  350. Unmarshal: legacyUnmarshal,
  351. Merge: legacyMerge,
  352. // We have no way to tell whether the type's Marshal method
  353. // supports deterministic serialization or not, but this
  354. // preserves the v1 implementation's behavior of always
  355. // calling Marshal methods when present.
  356. Flags: protoiface.SupportMarshalDeterministic,
  357. }
  358. func legacyMarshal(in protoiface.MarshalInput) (protoiface.MarshalOutput, error) {
  359. v := in.Message.(unwrapper).protoUnwrap()
  360. marshaler, ok := v.(legacyMarshaler)
  361. if !ok {
  362. return protoiface.MarshalOutput{}, errors.New("%T does not implement Marshal", v)
  363. }
  364. out, err := marshaler.Marshal()
  365. if in.Buf != nil {
  366. out = append(in.Buf, out...)
  367. }
  368. return protoiface.MarshalOutput{
  369. Buf: out,
  370. }, err
  371. }
  372. func legacyUnmarshal(in protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
  373. v := in.Message.(unwrapper).protoUnwrap()
  374. unmarshaler, ok := v.(legacyUnmarshaler)
  375. if !ok {
  376. return protoiface.UnmarshalOutput{}, errors.New("%T does not implement Unmarshal", v)
  377. }
  378. return protoiface.UnmarshalOutput{}, unmarshaler.Unmarshal(in.Buf)
  379. }
  380. func legacyMerge(in protoiface.MergeInput) protoiface.MergeOutput {
  381. // Check whether this supports the legacy merger.
  382. dstv := in.Destination.(unwrapper).protoUnwrap()
  383. merger, ok := dstv.(legacyMerger)
  384. if ok {
  385. merger.Merge(Export{}.ProtoMessageV1Of(in.Source))
  386. return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
  387. }
  388. // If legacy merger is unavailable, implement merge in terms of
  389. // a marshal and unmarshal operation.
  390. srcv := in.Source.(unwrapper).protoUnwrap()
  391. marshaler, ok := srcv.(legacyMarshaler)
  392. if !ok {
  393. return protoiface.MergeOutput{}
  394. }
  395. dstv = in.Destination.(unwrapper).protoUnwrap()
  396. unmarshaler, ok := dstv.(legacyUnmarshaler)
  397. if !ok {
  398. return protoiface.MergeOutput{}
  399. }
  400. if !in.Source.IsValid() {
  401. // Legacy Marshal methods may not function on nil messages.
  402. // Check for a typed nil source only after we confirm that
  403. // legacy Marshal/Unmarshal methods are present, for
  404. // consistency.
  405. return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
  406. }
  407. b, err := marshaler.Marshal()
  408. if err != nil {
  409. return protoiface.MergeOutput{}
  410. }
  411. err = unmarshaler.Unmarshal(b)
  412. if err != nil {
  413. return protoiface.MergeOutput{}
  414. }
  415. return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
  416. }
  417. // aberrantMessageType implements MessageType for all types other than pointer-to-struct.
  418. type aberrantMessageType struct {
  419. t reflect.Type
  420. }
  421. func (mt aberrantMessageType) New() protoreflect.Message {
  422. if mt.t.Kind() == reflect.Ptr {
  423. return aberrantMessage{reflect.New(mt.t.Elem())}
  424. }
  425. return aberrantMessage{reflect.Zero(mt.t)}
  426. }
  427. func (mt aberrantMessageType) Zero() protoreflect.Message {
  428. return aberrantMessage{reflect.Zero(mt.t)}
  429. }
  430. func (mt aberrantMessageType) GoType() reflect.Type {
  431. return mt.t
  432. }
  433. func (mt aberrantMessageType) Descriptor() protoreflect.MessageDescriptor {
  434. return LegacyLoadMessageDesc(mt.t)
  435. }
  436. // aberrantMessage implements Message for all types other than pointer-to-struct.
  437. //
  438. // When the underlying type implements legacyMarshaler or legacyUnmarshaler,
  439. // the aberrant Message can be marshaled or unmarshaled. Otherwise, there is
  440. // not much that can be done with values of this type.
  441. type aberrantMessage struct {
  442. v reflect.Value
  443. }
  444. // Reset implements the v1 proto.Message.Reset method.
  445. func (m aberrantMessage) Reset() {
  446. if mr, ok := m.v.Interface().(interface{ Reset() }); ok {
  447. mr.Reset()
  448. return
  449. }
  450. if m.v.Kind() == reflect.Ptr && !m.v.IsNil() {
  451. m.v.Elem().Set(reflect.Zero(m.v.Type().Elem()))
  452. }
  453. }
  454. func (m aberrantMessage) ProtoReflect() protoreflect.Message {
  455. return m
  456. }
  457. func (m aberrantMessage) Descriptor() protoreflect.MessageDescriptor {
  458. return LegacyLoadMessageDesc(m.v.Type())
  459. }
  460. func (m aberrantMessage) Type() protoreflect.MessageType {
  461. return aberrantMessageType{m.v.Type()}
  462. }
  463. func (m aberrantMessage) New() protoreflect.Message {
  464. if m.v.Type().Kind() == reflect.Ptr {
  465. return aberrantMessage{reflect.New(m.v.Type().Elem())}
  466. }
  467. return aberrantMessage{reflect.Zero(m.v.Type())}
  468. }
  469. func (m aberrantMessage) Interface() protoreflect.ProtoMessage {
  470. return m
  471. }
  472. func (m aberrantMessage) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
  473. return
  474. }
  475. func (m aberrantMessage) Has(protoreflect.FieldDescriptor) bool {
  476. return false
  477. }
  478. func (m aberrantMessage) Clear(protoreflect.FieldDescriptor) {
  479. panic("invalid Message.Clear on " + string(m.Descriptor().FullName()))
  480. }
  481. func (m aberrantMessage) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
  482. if fd.Default().IsValid() {
  483. return fd.Default()
  484. }
  485. panic("invalid Message.Get on " + string(m.Descriptor().FullName()))
  486. }
  487. func (m aberrantMessage) Set(protoreflect.FieldDescriptor, protoreflect.Value) {
  488. panic("invalid Message.Set on " + string(m.Descriptor().FullName()))
  489. }
  490. func (m aberrantMessage) Mutable(protoreflect.FieldDescriptor) protoreflect.Value {
  491. panic("invalid Message.Mutable on " + string(m.Descriptor().FullName()))
  492. }
  493. func (m aberrantMessage) NewField(protoreflect.FieldDescriptor) protoreflect.Value {
  494. panic("invalid Message.NewField on " + string(m.Descriptor().FullName()))
  495. }
  496. func (m aberrantMessage) WhichOneof(protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
  497. panic("invalid Message.WhichOneof descriptor on " + string(m.Descriptor().FullName()))
  498. }
  499. func (m aberrantMessage) GetUnknown() protoreflect.RawFields {
  500. return nil
  501. }
  502. func (m aberrantMessage) SetUnknown(protoreflect.RawFields) {
  503. // SetUnknown discards its input on messages which don't support unknown field storage.
  504. }
  505. func (m aberrantMessage) IsValid() bool {
  506. if m.v.Kind() == reflect.Ptr {
  507. return !m.v.IsNil()
  508. }
  509. return false
  510. }
  511. func (m aberrantMessage) ProtoMethods() *protoiface.Methods {
  512. return aberrantProtoMethods
  513. }
  514. func (m aberrantMessage) protoUnwrap() interface{} {
  515. return m.v.Interface()
  516. }