您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

564 行
18 KiB

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