legacy_message.go 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572
  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. md.L1.EditionFeatures = md.L0.ParentFile.L1.EditionFeatures
  185. // Obtain a list of oneof wrapper types.
  186. var oneofWrappers []reflect.Type
  187. methods := make([]reflect.Method, 0, 2)
  188. if m, ok := t.MethodByName("XXX_OneofFuncs"); ok {
  189. methods = append(methods, m)
  190. }
  191. if m, ok := t.MethodByName("XXX_OneofWrappers"); ok {
  192. methods = append(methods, m)
  193. }
  194. for _, fn := range methods {
  195. for _, v := range fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))}) {
  196. if vs, ok := v.Interface().([]any); ok {
  197. for _, v := range vs {
  198. oneofWrappers = append(oneofWrappers, reflect.TypeOf(v))
  199. }
  200. }
  201. }
  202. }
  203. // Obtain a list of the extension ranges.
  204. if fn, ok := t.MethodByName("ExtensionRangeArray"); ok {
  205. vs := fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0]
  206. for i := 0; i < vs.Len(); i++ {
  207. v := vs.Index(i)
  208. md.L2.ExtensionRanges.List = append(md.L2.ExtensionRanges.List, [2]protoreflect.FieldNumber{
  209. protoreflect.FieldNumber(v.FieldByName("Start").Int()),
  210. protoreflect.FieldNumber(v.FieldByName("End").Int() + 1),
  211. })
  212. md.L2.ExtensionRangeOptions = append(md.L2.ExtensionRangeOptions, nil)
  213. }
  214. }
  215. // Derive the message fields by inspecting the struct fields.
  216. for i := 0; i < t.Elem().NumField(); i++ {
  217. f := t.Elem().Field(i)
  218. if tag := f.Tag.Get("protobuf"); tag != "" {
  219. tagKey := f.Tag.Get("protobuf_key")
  220. tagVal := f.Tag.Get("protobuf_val")
  221. aberrantAppendField(md, f.Type, tag, tagKey, tagVal)
  222. }
  223. if tag := f.Tag.Get("protobuf_oneof"); tag != "" {
  224. n := len(md.L2.Oneofs.List)
  225. md.L2.Oneofs.List = append(md.L2.Oneofs.List, filedesc.Oneof{})
  226. od := &md.L2.Oneofs.List[n]
  227. od.L0.FullName = md.FullName().Append(protoreflect.Name(tag))
  228. od.L0.ParentFile = md.L0.ParentFile
  229. od.L1.EditionFeatures = md.L1.EditionFeatures
  230. od.L0.Parent = md
  231. od.L0.Index = n
  232. for _, t := range oneofWrappers {
  233. if t.Implements(f.Type) {
  234. f := t.Elem().Field(0)
  235. if tag := f.Tag.Get("protobuf"); tag != "" {
  236. aberrantAppendField(md, f.Type, tag, "", "")
  237. fd := &md.L2.Fields.List[len(md.L2.Fields.List)-1]
  238. fd.L1.ContainingOneof = od
  239. fd.L1.EditionFeatures = od.L1.EditionFeatures
  240. od.L1.Fields.List = append(od.L1.Fields.List, fd)
  241. }
  242. }
  243. }
  244. }
  245. }
  246. return md
  247. }
  248. func aberrantDeriveMessageName(t reflect.Type, name protoreflect.FullName) protoreflect.FullName {
  249. if name.IsValid() {
  250. return name
  251. }
  252. func() {
  253. defer func() { recover() }() // swallow possible nil panics
  254. if m, ok := reflect.Zero(t).Interface().(interface{ XXX_MessageName() string }); ok {
  255. name = protoreflect.FullName(m.XXX_MessageName())
  256. }
  257. }()
  258. if name.IsValid() {
  259. return name
  260. }
  261. if t.Kind() == reflect.Ptr {
  262. t = t.Elem()
  263. }
  264. return AberrantDeriveFullName(t)
  265. }
  266. func aberrantAppendField(md *filedesc.Message, goType reflect.Type, tag, tagKey, tagVal string) {
  267. t := goType
  268. isOptional := t.Kind() == reflect.Ptr && t.Elem().Kind() != reflect.Struct
  269. isRepeated := t.Kind() == reflect.Slice && t.Elem().Kind() != reflect.Uint8
  270. if isOptional || isRepeated {
  271. t = t.Elem()
  272. }
  273. fd := ptag.Unmarshal(tag, t, placeholderEnumValues{}).(*filedesc.Field)
  274. // Append field descriptor to the message.
  275. n := len(md.L2.Fields.List)
  276. md.L2.Fields.List = append(md.L2.Fields.List, *fd)
  277. fd = &md.L2.Fields.List[n]
  278. fd.L0.FullName = md.FullName().Append(fd.Name())
  279. fd.L0.ParentFile = md.L0.ParentFile
  280. fd.L0.Parent = md
  281. fd.L0.Index = n
  282. if fd.L1.IsWeak || fd.L1.EditionFeatures.IsPacked {
  283. fd.L1.Options = func() protoreflect.ProtoMessage {
  284. opts := descopts.Field.ProtoReflect().New()
  285. if fd.L1.IsWeak {
  286. opts.Set(opts.Descriptor().Fields().ByName("weak"), protoreflect.ValueOfBool(true))
  287. }
  288. if fd.L1.EditionFeatures.IsPacked {
  289. opts.Set(opts.Descriptor().Fields().ByName("packed"), protoreflect.ValueOfBool(fd.L1.EditionFeatures.IsPacked))
  290. }
  291. return opts.Interface()
  292. }
  293. }
  294. // Populate Enum and Message.
  295. if fd.Enum() == nil && fd.Kind() == protoreflect.EnumKind {
  296. switch v := reflect.Zero(t).Interface().(type) {
  297. case protoreflect.Enum:
  298. fd.L1.Enum = v.Descriptor()
  299. default:
  300. fd.L1.Enum = LegacyLoadEnumDesc(t)
  301. }
  302. }
  303. if fd.Message() == nil && (fd.Kind() == protoreflect.MessageKind || fd.Kind() == protoreflect.GroupKind) {
  304. switch v := reflect.Zero(t).Interface().(type) {
  305. case protoreflect.ProtoMessage:
  306. fd.L1.Message = v.ProtoReflect().Descriptor()
  307. case messageV1:
  308. fd.L1.Message = LegacyLoadMessageDesc(t)
  309. default:
  310. if t.Kind() == reflect.Map {
  311. n := len(md.L1.Messages.List)
  312. md.L1.Messages.List = append(md.L1.Messages.List, filedesc.Message{L2: new(filedesc.MessageL2)})
  313. md2 := &md.L1.Messages.List[n]
  314. md2.L0.FullName = md.FullName().Append(protoreflect.Name(strs.MapEntryName(string(fd.Name()))))
  315. md2.L0.ParentFile = md.L0.ParentFile
  316. md2.L0.Parent = md
  317. md2.L0.Index = n
  318. md2.L1.EditionFeatures = md.L1.EditionFeatures
  319. md2.L1.IsMapEntry = true
  320. md2.L2.Options = func() protoreflect.ProtoMessage {
  321. opts := descopts.Message.ProtoReflect().New()
  322. opts.Set(opts.Descriptor().Fields().ByName("map_entry"), protoreflect.ValueOfBool(true))
  323. return opts.Interface()
  324. }
  325. aberrantAppendField(md2, t.Key(), tagKey, "", "")
  326. aberrantAppendField(md2, t.Elem(), tagVal, "", "")
  327. fd.L1.Message = md2
  328. break
  329. }
  330. fd.L1.Message = aberrantLoadMessageDescReentrant(t, "")
  331. }
  332. }
  333. }
  334. type placeholderEnumValues struct {
  335. protoreflect.EnumValueDescriptors
  336. }
  337. func (placeholderEnumValues) ByNumber(n protoreflect.EnumNumber) protoreflect.EnumValueDescriptor {
  338. return filedesc.PlaceholderEnumValue(protoreflect.FullName(fmt.Sprintf("UNKNOWN_%d", n)))
  339. }
  340. // legacyMarshaler is the proto.Marshaler interface superseded by protoiface.Methoder.
  341. type legacyMarshaler interface {
  342. Marshal() ([]byte, error)
  343. }
  344. // legacyUnmarshaler is the proto.Unmarshaler interface superseded by protoiface.Methoder.
  345. type legacyUnmarshaler interface {
  346. Unmarshal([]byte) error
  347. }
  348. // legacyMerger is the proto.Merger interface superseded by protoiface.Methoder.
  349. type legacyMerger interface {
  350. Merge(protoiface.MessageV1)
  351. }
  352. var aberrantProtoMethods = &protoiface.Methods{
  353. Marshal: legacyMarshal,
  354. Unmarshal: legacyUnmarshal,
  355. Merge: legacyMerge,
  356. // We have no way to tell whether the type's Marshal method
  357. // supports deterministic serialization or not, but this
  358. // preserves the v1 implementation's behavior of always
  359. // calling Marshal methods when present.
  360. Flags: protoiface.SupportMarshalDeterministic,
  361. }
  362. func legacyMarshal(in protoiface.MarshalInput) (protoiface.MarshalOutput, error) {
  363. v := in.Message.(unwrapper).protoUnwrap()
  364. marshaler, ok := v.(legacyMarshaler)
  365. if !ok {
  366. return protoiface.MarshalOutput{}, errors.New("%T does not implement Marshal", v)
  367. }
  368. out, err := marshaler.Marshal()
  369. if in.Buf != nil {
  370. out = append(in.Buf, out...)
  371. }
  372. return protoiface.MarshalOutput{
  373. Buf: out,
  374. }, err
  375. }
  376. func legacyUnmarshal(in protoiface.UnmarshalInput) (protoiface.UnmarshalOutput, error) {
  377. v := in.Message.(unwrapper).protoUnwrap()
  378. unmarshaler, ok := v.(legacyUnmarshaler)
  379. if !ok {
  380. return protoiface.UnmarshalOutput{}, errors.New("%T does not implement Unmarshal", v)
  381. }
  382. return protoiface.UnmarshalOutput{}, unmarshaler.Unmarshal(in.Buf)
  383. }
  384. func legacyMerge(in protoiface.MergeInput) protoiface.MergeOutput {
  385. // Check whether this supports the legacy merger.
  386. dstv := in.Destination.(unwrapper).protoUnwrap()
  387. merger, ok := dstv.(legacyMerger)
  388. if ok {
  389. merger.Merge(Export{}.ProtoMessageV1Of(in.Source))
  390. return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
  391. }
  392. // If legacy merger is unavailable, implement merge in terms of
  393. // a marshal and unmarshal operation.
  394. srcv := in.Source.(unwrapper).protoUnwrap()
  395. marshaler, ok := srcv.(legacyMarshaler)
  396. if !ok {
  397. return protoiface.MergeOutput{}
  398. }
  399. dstv = in.Destination.(unwrapper).protoUnwrap()
  400. unmarshaler, ok := dstv.(legacyUnmarshaler)
  401. if !ok {
  402. return protoiface.MergeOutput{}
  403. }
  404. if !in.Source.IsValid() {
  405. // Legacy Marshal methods may not function on nil messages.
  406. // Check for a typed nil source only after we confirm that
  407. // legacy Marshal/Unmarshal methods are present, for
  408. // consistency.
  409. return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
  410. }
  411. b, err := marshaler.Marshal()
  412. if err != nil {
  413. return protoiface.MergeOutput{}
  414. }
  415. err = unmarshaler.Unmarshal(b)
  416. if err != nil {
  417. return protoiface.MergeOutput{}
  418. }
  419. return protoiface.MergeOutput{Flags: protoiface.MergeComplete}
  420. }
  421. // aberrantMessageType implements MessageType for all types other than pointer-to-struct.
  422. type aberrantMessageType struct {
  423. t reflect.Type
  424. }
  425. func (mt aberrantMessageType) New() protoreflect.Message {
  426. if mt.t.Kind() == reflect.Ptr {
  427. return aberrantMessage{reflect.New(mt.t.Elem())}
  428. }
  429. return aberrantMessage{reflect.Zero(mt.t)}
  430. }
  431. func (mt aberrantMessageType) Zero() protoreflect.Message {
  432. return aberrantMessage{reflect.Zero(mt.t)}
  433. }
  434. func (mt aberrantMessageType) GoType() reflect.Type {
  435. return mt.t
  436. }
  437. func (mt aberrantMessageType) Descriptor() protoreflect.MessageDescriptor {
  438. return LegacyLoadMessageDesc(mt.t)
  439. }
  440. // aberrantMessage implements Message for all types other than pointer-to-struct.
  441. //
  442. // When the underlying type implements legacyMarshaler or legacyUnmarshaler,
  443. // the aberrant Message can be marshaled or unmarshaled. Otherwise, there is
  444. // not much that can be done with values of this type.
  445. type aberrantMessage struct {
  446. v reflect.Value
  447. }
  448. // Reset implements the v1 proto.Message.Reset method.
  449. func (m aberrantMessage) Reset() {
  450. if mr, ok := m.v.Interface().(interface{ Reset() }); ok {
  451. mr.Reset()
  452. return
  453. }
  454. if m.v.Kind() == reflect.Ptr && !m.v.IsNil() {
  455. m.v.Elem().Set(reflect.Zero(m.v.Type().Elem()))
  456. }
  457. }
  458. func (m aberrantMessage) ProtoReflect() protoreflect.Message {
  459. return m
  460. }
  461. func (m aberrantMessage) Descriptor() protoreflect.MessageDescriptor {
  462. return LegacyLoadMessageDesc(m.v.Type())
  463. }
  464. func (m aberrantMessage) Type() protoreflect.MessageType {
  465. return aberrantMessageType{m.v.Type()}
  466. }
  467. func (m aberrantMessage) New() protoreflect.Message {
  468. if m.v.Type().Kind() == reflect.Ptr {
  469. return aberrantMessage{reflect.New(m.v.Type().Elem())}
  470. }
  471. return aberrantMessage{reflect.Zero(m.v.Type())}
  472. }
  473. func (m aberrantMessage) Interface() protoreflect.ProtoMessage {
  474. return m
  475. }
  476. func (m aberrantMessage) Range(f func(protoreflect.FieldDescriptor, protoreflect.Value) bool) {
  477. return
  478. }
  479. func (m aberrantMessage) Has(protoreflect.FieldDescriptor) bool {
  480. return false
  481. }
  482. func (m aberrantMessage) Clear(protoreflect.FieldDescriptor) {
  483. panic("invalid Message.Clear on " + string(m.Descriptor().FullName()))
  484. }
  485. func (m aberrantMessage) Get(fd protoreflect.FieldDescriptor) protoreflect.Value {
  486. if fd.Default().IsValid() {
  487. return fd.Default()
  488. }
  489. panic("invalid Message.Get on " + string(m.Descriptor().FullName()))
  490. }
  491. func (m aberrantMessage) Set(protoreflect.FieldDescriptor, protoreflect.Value) {
  492. panic("invalid Message.Set on " + string(m.Descriptor().FullName()))
  493. }
  494. func (m aberrantMessage) Mutable(protoreflect.FieldDescriptor) protoreflect.Value {
  495. panic("invalid Message.Mutable on " + string(m.Descriptor().FullName()))
  496. }
  497. func (m aberrantMessage) NewField(protoreflect.FieldDescriptor) protoreflect.Value {
  498. panic("invalid Message.NewField on " + string(m.Descriptor().FullName()))
  499. }
  500. func (m aberrantMessage) WhichOneof(protoreflect.OneofDescriptor) protoreflect.FieldDescriptor {
  501. panic("invalid Message.WhichOneof descriptor on " + string(m.Descriptor().FullName()))
  502. }
  503. func (m aberrantMessage) GetUnknown() protoreflect.RawFields {
  504. return nil
  505. }
  506. func (m aberrantMessage) SetUnknown(protoreflect.RawFields) {
  507. // SetUnknown discards its input on messages which don't support unknown field storage.
  508. }
  509. func (m aberrantMessage) IsValid() bool {
  510. if m.v.Kind() == reflect.Ptr {
  511. return !m.v.IsNil()
  512. }
  513. return false
  514. }
  515. func (m aberrantMessage) ProtoMethods() *protoiface.Methods {
  516. return aberrantProtoMethods
  517. }
  518. func (m aberrantMessage) protoUnwrap() any {
  519. return m.v.Interface()
  520. }