legacy_message.go 18 KB

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