message.go 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551
  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. "sort"
  9. "strconv"
  10. "strings"
  11. "sync"
  12. "sync/atomic"
  13. pvalue "google.golang.org/protobuf/internal/value"
  14. pref "google.golang.org/protobuf/reflect/protoreflect"
  15. piface "google.golang.org/protobuf/runtime/protoiface"
  16. )
  17. // MessageInfo provides protobuf related functionality for a given Go type
  18. // that represents a message. A given instance of MessageInfo is tied to
  19. // exactly one Go type, which must be a pointer to a struct type.
  20. type MessageInfo struct {
  21. // GoType is the underlying message Go type and must be populated.
  22. // Once set, this field must never be mutated.
  23. GoType reflect.Type // pointer to struct
  24. // PBType is the underlying message descriptor type and must be populated.
  25. // Once set, this field must never be mutated.
  26. PBType pref.MessageType
  27. initMu sync.Mutex // protects all unexported fields
  28. initDone uint32
  29. // Keep a separate slice of fields for efficient field encoding in tag order
  30. // and because iterating over a slice is substantially faster than a map.
  31. fields map[pref.FieldNumber]*fieldInfo
  32. fieldsOrdered []*fieldInfo
  33. oneofs map[pref.Name]*oneofInfo
  34. getUnknown func(pointer) pref.RawFields
  35. setUnknown func(pointer, pref.RawFields)
  36. extensionMap func(pointer) *extensionMap
  37. unknownFields func(*messageDataType) pref.UnknownFields
  38. extensionFields func(*messageDataType) pref.KnownFields
  39. methods piface.Methods
  40. sizecacheOffset offset
  41. extensionOffset offset
  42. unknownOffset offset
  43. extensionFieldInfosMu sync.RWMutex
  44. extensionFieldInfos map[pref.ExtensionType]*extensionFieldInfo
  45. }
  46. var prefMessageType = reflect.TypeOf((*pref.Message)(nil)).Elem()
  47. // getMessageInfo returns the MessageInfo (if any) for a type.
  48. //
  49. // We find the MessageInfo by calling the ProtoReflect method on the type's
  50. // zero value and looking at the returned type to see if it is a
  51. // messageReflectWrapper. Note that the MessageInfo may still be uninitialized
  52. // at this point.
  53. func getMessageInfo(mt reflect.Type) (mi *MessageInfo, ok bool) {
  54. method, ok := mt.MethodByName("ProtoReflect")
  55. if !ok {
  56. return nil, false
  57. }
  58. if method.Type.NumIn() != 1 || method.Type.NumOut() != 1 || method.Type.Out(0) != prefMessageType {
  59. return nil, false
  60. }
  61. ret := reflect.Zero(mt).Method(method.Index).Call(nil)
  62. m, ok := ret[0].Elem().Interface().(*messageReflectWrapper)
  63. if !ok {
  64. return nil, ok
  65. }
  66. return m.mi, true
  67. }
  68. func (mi *MessageInfo) init() {
  69. // This function is called in the hot path. Inline the sync.Once
  70. // logic, since allocating a closure for Once.Do is expensive.
  71. // Keep init small to ensure that it can be inlined.
  72. if atomic.LoadUint32(&mi.initDone) == 1 {
  73. return
  74. }
  75. mi.initOnce()
  76. }
  77. func (mi *MessageInfo) initOnce() {
  78. mi.initMu.Lock()
  79. defer mi.initMu.Unlock()
  80. if mi.initDone == 1 {
  81. return
  82. }
  83. t := mi.GoType
  84. if t.Kind() != reflect.Ptr && t.Elem().Kind() != reflect.Struct {
  85. panic(fmt.Sprintf("got %v, want *struct kind", t))
  86. }
  87. si := mi.makeStructInfo(t.Elem())
  88. mi.makeKnownFieldsFunc(si)
  89. mi.makeUnknownFieldsFunc(t.Elem())
  90. mi.makeExtensionFieldsFunc(t.Elem())
  91. mi.makeMethods(t.Elem())
  92. atomic.StoreUint32(&mi.initDone, 1)
  93. }
  94. type (
  95. SizeCache = int32
  96. UnknownFields = []byte
  97. ExtensionFields = map[int32]ExtensionField
  98. )
  99. var (
  100. sizecacheType = reflect.TypeOf(SizeCache(0))
  101. unknownFieldsType = reflect.TypeOf(UnknownFields(nil))
  102. extensionFieldsType = reflect.TypeOf(ExtensionFields(nil))
  103. )
  104. func (mi *MessageInfo) makeMethods(t reflect.Type) {
  105. mi.sizecacheOffset = invalidOffset
  106. if fx, _ := t.FieldByName("XXX_sizecache"); fx.Type == sizecacheType {
  107. mi.sizecacheOffset = offsetOf(fx)
  108. }
  109. mi.unknownOffset = invalidOffset
  110. if fx, _ := t.FieldByName("XXX_unrecognized"); fx.Type == unknownFieldsType {
  111. mi.unknownOffset = offsetOf(fx)
  112. }
  113. mi.extensionOffset = invalidOffset
  114. if fx, _ := t.FieldByName("XXX_InternalExtensions"); fx.Type == extensionFieldsType {
  115. mi.extensionOffset = offsetOf(fx)
  116. } else if fx, _ = t.FieldByName("XXX_extensions"); fx.Type == extensionFieldsType {
  117. mi.extensionOffset = offsetOf(fx)
  118. }
  119. mi.methods.Flags = piface.MethodFlagDeterministicMarshal
  120. mi.methods.MarshalAppend = mi.marshalAppend
  121. mi.methods.Size = mi.size
  122. }
  123. type structInfo struct {
  124. fieldsByNumber map[pref.FieldNumber]reflect.StructField
  125. oneofsByName map[pref.Name]reflect.StructField
  126. oneofWrappersByType map[reflect.Type]pref.FieldNumber
  127. oneofWrappersByNumber map[pref.FieldNumber]reflect.Type
  128. }
  129. func (mi *MessageInfo) makeStructInfo(t reflect.Type) structInfo {
  130. // Generate a mapping of field numbers and names to Go struct field or type.
  131. si := structInfo{
  132. fieldsByNumber: map[pref.FieldNumber]reflect.StructField{},
  133. oneofsByName: map[pref.Name]reflect.StructField{},
  134. oneofWrappersByType: map[reflect.Type]pref.FieldNumber{},
  135. oneofWrappersByNumber: map[pref.FieldNumber]reflect.Type{},
  136. }
  137. fieldLoop:
  138. for i := 0; i < t.NumField(); i++ {
  139. f := t.Field(i)
  140. for _, s := range strings.Split(f.Tag.Get("protobuf"), ",") {
  141. if len(s) > 0 && strings.Trim(s, "0123456789") == "" {
  142. n, _ := strconv.ParseUint(s, 10, 64)
  143. si.fieldsByNumber[pref.FieldNumber(n)] = f
  144. continue fieldLoop
  145. }
  146. }
  147. if s := f.Tag.Get("protobuf_oneof"); len(s) > 0 {
  148. si.oneofsByName[pref.Name(s)] = f
  149. continue fieldLoop
  150. }
  151. }
  152. var oneofWrappers []interface{}
  153. if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofFuncs"); ok {
  154. oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[3].Interface().([]interface{})
  155. }
  156. if fn, ok := reflect.PtrTo(t).MethodByName("XXX_OneofWrappers"); ok {
  157. oneofWrappers = fn.Func.Call([]reflect.Value{reflect.Zero(fn.Type.In(0))})[0].Interface().([]interface{})
  158. }
  159. for _, v := range oneofWrappers {
  160. tf := reflect.TypeOf(v).Elem()
  161. f := tf.Field(0)
  162. for _, s := range strings.Split(f.Tag.Get("protobuf"), ",") {
  163. if len(s) > 0 && strings.Trim(s, "0123456789") == "" {
  164. n, _ := strconv.ParseUint(s, 10, 64)
  165. si.oneofWrappersByType[tf] = pref.FieldNumber(n)
  166. si.oneofWrappersByNumber[pref.FieldNumber(n)] = tf
  167. break
  168. }
  169. }
  170. }
  171. return si
  172. }
  173. // makeKnownFieldsFunc generates functions for operations that can be performed
  174. // on each protobuf message field. It takes in a reflect.Type representing the
  175. // Go struct and matches message fields with struct fields.
  176. //
  177. // This code assumes that the struct is well-formed and panics if there are
  178. // any discrepancies.
  179. func (mi *MessageInfo) makeKnownFieldsFunc(si structInfo) {
  180. mi.fields = map[pref.FieldNumber]*fieldInfo{}
  181. mi.fieldsOrdered = make([]*fieldInfo, 0, mi.PBType.Fields().Len())
  182. for i := 0; i < mi.PBType.Descriptor().Fields().Len(); i++ {
  183. fd := mi.PBType.Descriptor().Fields().Get(i)
  184. fs := si.fieldsByNumber[fd.Number()]
  185. var fi fieldInfo
  186. switch {
  187. case fd.ContainingOneof() != nil:
  188. fi = fieldInfoForOneof(fd, si.oneofsByName[fd.ContainingOneof().Name()], si.oneofWrappersByNumber[fd.Number()])
  189. // There is one fieldInfo for each proto message field, but only one struct
  190. // field for all message fields in a oneof. We install the encoder functions
  191. // on the fieldInfo for the first field in the oneof.
  192. //
  193. // A slightly simpler approach would be to have each fieldInfo's encoder
  194. // handle the case where that field is set, but this would require more
  195. // checks against the current oneof type than a single map lookup.
  196. if fd.ContainingOneof().Fields().Get(0).Name() == fd.Name() {
  197. fi.funcs = makeOneofFieldCoder(si.oneofsByName[fd.ContainingOneof().Name()], fd.ContainingOneof(), si.fieldsByNumber, si.oneofWrappersByNumber)
  198. }
  199. case fd.IsMap():
  200. fi = fieldInfoForMap(fd, fs)
  201. case fd.IsList():
  202. fi = fieldInfoForList(fd, fs)
  203. case fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind:
  204. fi = fieldInfoForMessage(fd, fs)
  205. default:
  206. fi = fieldInfoForScalar(fd, fs)
  207. }
  208. fi.num = fd.Number()
  209. mi.fields[fd.Number()] = &fi
  210. mi.fieldsOrdered = append(mi.fieldsOrdered, &fi)
  211. }
  212. sort.Slice(mi.fieldsOrdered, func(i, j int) bool {
  213. return mi.fieldsOrdered[i].num < mi.fieldsOrdered[j].num
  214. })
  215. mi.oneofs = map[pref.Name]*oneofInfo{}
  216. for i := 0; i < mi.PBType.Descriptor().Oneofs().Len(); i++ {
  217. od := mi.PBType.Descriptor().Oneofs().Get(i)
  218. mi.oneofs[od.Name()] = makeOneofInfo(od, si.oneofsByName[od.Name()], si.oneofWrappersByType)
  219. }
  220. }
  221. func (mi *MessageInfo) makeUnknownFieldsFunc(t reflect.Type) {
  222. mi.unknownFields = makeLegacyUnknownFieldsFunc(t)
  223. mi.getUnknown = func(pointer) pref.RawFields { return nil }
  224. mi.setUnknown = func(pointer, pref.RawFields) { return }
  225. fu, _ := t.FieldByName("XXX_unrecognized")
  226. if fu.Type == unknownFieldsType {
  227. fieldOffset := offsetOf(fu)
  228. mi.getUnknown = func(p pointer) pref.RawFields {
  229. if p.IsNil() {
  230. return nil
  231. }
  232. rv := p.Apply(fieldOffset).AsValueOf(unknownFieldsType)
  233. return pref.RawFields(*rv.Interface().(*[]byte))
  234. }
  235. mi.setUnknown = func(p pointer, b pref.RawFields) {
  236. if p.IsNil() {
  237. panic("invalid SetUnknown on nil Message")
  238. }
  239. rv := p.Apply(fieldOffset).AsValueOf(unknownFieldsType)
  240. *rv.Interface().(*[]byte) = []byte(b)
  241. }
  242. } else {
  243. mi.getUnknown = func(pointer) pref.RawFields {
  244. return nil
  245. }
  246. mi.setUnknown = func(p pointer, _ pref.RawFields) {
  247. if p.IsNil() {
  248. panic("invalid SetUnknown on nil Message")
  249. }
  250. }
  251. }
  252. }
  253. func (mi *MessageInfo) makeExtensionFieldsFunc(t reflect.Type) {
  254. mi.extensionFields = makeLegacyExtensionFieldsFunc(t)
  255. fx, _ := t.FieldByName("XXX_extensions")
  256. if fx.Type != extensionFieldsType {
  257. fx, _ = t.FieldByName("XXX_InternalExtensions")
  258. }
  259. if fx.Type == extensionFieldsType {
  260. fieldOffset := offsetOf(fx)
  261. mi.extensionMap = func(p pointer) *extensionMap {
  262. v := p.Apply(fieldOffset).AsValueOf(extensionFieldsType)
  263. return (*extensionMap)(v.Interface().(*map[int32]ExtensionField))
  264. }
  265. } else {
  266. mi.extensionMap = func(pointer) *extensionMap {
  267. return (*extensionMap)(nil)
  268. }
  269. }
  270. }
  271. func (mi *MessageInfo) MessageOf(p interface{}) pref.Message {
  272. return (*messageReflectWrapper)(mi.dataTypeOf(p))
  273. }
  274. func (mi *MessageInfo) Methods() *piface.Methods {
  275. mi.init()
  276. return &mi.methods
  277. }
  278. func (mi *MessageInfo) dataTypeOf(p interface{}) *messageDataType {
  279. // TODO: Remove this check? This API is primarily used by generated code,
  280. // and should not violate this assumption. Leave this check in for now to
  281. // provide some sanity checks during development. This can be removed if
  282. // it proves to be detrimental to performance.
  283. if reflect.TypeOf(p) != mi.GoType {
  284. panic(fmt.Sprintf("type mismatch: got %T, want %v", p, mi.GoType))
  285. }
  286. return &messageDataType{pointerOfIface(p), mi}
  287. }
  288. // messageDataType is a tuple of a pointer to the message data and
  289. // a pointer to the message type.
  290. //
  291. // TODO: Unfortunately, we need to close over a pointer and MessageInfo,
  292. // which incurs an an allocation. This pair is similar to a Go interface,
  293. // which is essentially a tuple of the same thing. We can make this efficient
  294. // with reflect.NamedOf (see https://golang.org/issues/16522).
  295. //
  296. // With that hypothetical API, we could dynamically create a new named type
  297. // that has the same underlying type as MessageInfo.GoType, and
  298. // dynamically create methods that close over MessageInfo.
  299. // Since the new type would have the same underlying type, we could directly
  300. // convert between pointers of those types, giving us an efficient way to swap
  301. // out the method set.
  302. //
  303. // Barring the ability to dynamically create named types, the workaround is
  304. // 1. either to accept the cost of an allocation for this wrapper struct or
  305. // 2. generate more types and methods, at the expense of binary size increase.
  306. type messageDataType struct {
  307. p pointer
  308. mi *MessageInfo
  309. }
  310. type messageReflectWrapper messageDataType
  311. func (m *messageReflectWrapper) Descriptor() pref.MessageDescriptor {
  312. return m.mi.PBType.Descriptor()
  313. }
  314. func (m *messageReflectWrapper) New() pref.Message {
  315. return m.mi.PBType.New()
  316. }
  317. func (m *messageReflectWrapper) Interface() pref.ProtoMessage {
  318. if m, ok := m.ProtoUnwrap().(pref.ProtoMessage); ok {
  319. return m
  320. }
  321. return (*messageIfaceWrapper)(m)
  322. }
  323. func (m *messageReflectWrapper) ProtoUnwrap() interface{} {
  324. return m.p.AsIfaceOf(m.mi.GoType.Elem())
  325. }
  326. func (m *messageReflectWrapper) Len() (cnt int) {
  327. m.mi.init()
  328. for _, fi := range m.mi.fields {
  329. if fi.has(m.p) {
  330. cnt++
  331. }
  332. }
  333. return cnt + m.mi.extensionMap(m.p).Len()
  334. }
  335. func (m *messageReflectWrapper) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
  336. m.mi.init()
  337. for _, fi := range m.mi.fields {
  338. if fi.has(m.p) {
  339. if !f(fi.fieldDesc, fi.get(m.p)) {
  340. return
  341. }
  342. }
  343. }
  344. m.mi.extensionMap(m.p).Range(f)
  345. }
  346. func (m *messageReflectWrapper) Has(fd pref.FieldDescriptor) bool {
  347. if fi, xt := m.checkField(fd); fi != nil {
  348. return fi.has(m.p)
  349. } else {
  350. return m.mi.extensionMap(m.p).Has(xt)
  351. }
  352. }
  353. func (m *messageReflectWrapper) Clear(fd pref.FieldDescriptor) {
  354. if fi, xt := m.checkField(fd); fi != nil {
  355. fi.clear(m.p)
  356. } else {
  357. m.mi.extensionMap(m.p).Clear(xt)
  358. }
  359. }
  360. func (m *messageReflectWrapper) Get(fd pref.FieldDescriptor) pref.Value {
  361. if fi, xt := m.checkField(fd); fi != nil {
  362. return fi.get(m.p)
  363. } else {
  364. return m.mi.extensionMap(m.p).Get(xt)
  365. }
  366. }
  367. func (m *messageReflectWrapper) Set(fd pref.FieldDescriptor, v pref.Value) {
  368. if fi, xt := m.checkField(fd); fi != nil {
  369. fi.set(m.p, v)
  370. } else {
  371. m.mi.extensionMap(m.p).Set(xt, v)
  372. }
  373. }
  374. func (m *messageReflectWrapper) Mutable(fd pref.FieldDescriptor) pref.Value {
  375. if fi, xt := m.checkField(fd); fi != nil {
  376. return fi.mutable(m.p)
  377. } else {
  378. return m.mi.extensionMap(m.p).Mutable(xt)
  379. }
  380. }
  381. func (m *messageReflectWrapper) NewMessage(fd pref.FieldDescriptor) pref.Message {
  382. if fi, xt := m.checkField(fd); fi != nil {
  383. return fi.newMessage()
  384. } else {
  385. return xt.New().Message()
  386. }
  387. }
  388. func (m *messageReflectWrapper) WhichOneof(od pref.OneofDescriptor) pref.FieldDescriptor {
  389. m.mi.init()
  390. if oi := m.mi.oneofs[od.Name()]; oi != nil && oi.oneofDesc == od {
  391. return od.Fields().ByNumber(oi.which(m.p))
  392. }
  393. panic("invalid oneof descriptor")
  394. }
  395. func (m *messageReflectWrapper) GetUnknown() pref.RawFields {
  396. m.mi.init()
  397. return m.mi.getUnknown(m.p)
  398. }
  399. func (m *messageReflectWrapper) SetUnknown(b pref.RawFields) {
  400. m.mi.init()
  401. m.mi.setUnknown(m.p, b)
  402. }
  403. // checkField verifies that the provided field descriptor is valid.
  404. // Exactly one of the returned values is populated.
  405. func (m *messageReflectWrapper) checkField(fd pref.FieldDescriptor) (*fieldInfo, pref.ExtensionType) {
  406. m.mi.init()
  407. if fi := m.mi.fields[fd.Number()]; fi != nil {
  408. if fi.fieldDesc != fd {
  409. panic("mismatching field descriptor")
  410. }
  411. return fi, nil
  412. }
  413. if fd.IsExtension() {
  414. if fd.ContainingMessage().FullName() != m.mi.PBType.FullName() {
  415. // TODO: Should this be exact containing message descriptor match?
  416. panic("mismatching containing message")
  417. }
  418. if !m.mi.PBType.ExtensionRanges().Has(fd.Number()) {
  419. panic("invalid extension field")
  420. }
  421. return nil, fd.(pref.ExtensionType)
  422. }
  423. panic("invalid field descriptor")
  424. }
  425. type extensionMap map[int32]ExtensionField
  426. func (m *extensionMap) Len() int {
  427. if m != nil {
  428. return len(*m)
  429. }
  430. return 0
  431. }
  432. func (m *extensionMap) Range(f func(pref.FieldDescriptor, pref.Value) bool) {
  433. if m != nil {
  434. for _, x := range *m {
  435. xt := x.GetType()
  436. if !f(xt, xt.ValueOf(x.GetValue())) {
  437. return
  438. }
  439. }
  440. }
  441. }
  442. func (m *extensionMap) Has(xt pref.ExtensionType) (ok bool) {
  443. if m != nil {
  444. _, ok = (*m)[int32(xt.Number())]
  445. }
  446. return ok
  447. }
  448. func (m *extensionMap) Clear(xt pref.ExtensionType) {
  449. delete(*m, int32(xt.Number()))
  450. }
  451. func (m *extensionMap) Get(xt pref.ExtensionType) pref.Value {
  452. if m != nil {
  453. if x, ok := (*m)[int32(xt.Number())]; ok {
  454. return xt.ValueOf(x.GetValue())
  455. }
  456. }
  457. if !isComposite(xt) {
  458. return defaultValueOf(xt)
  459. }
  460. return frozenValueOf(xt.New())
  461. }
  462. func (m *extensionMap) Set(xt pref.ExtensionType, v pref.Value) {
  463. if *m == nil {
  464. *m = make(map[int32]ExtensionField)
  465. }
  466. var x ExtensionField
  467. x.SetType(xt)
  468. x.SetEagerValue(xt.InterfaceOf(v))
  469. (*m)[int32(xt.Number())] = x
  470. }
  471. func (m *extensionMap) Mutable(xt pref.ExtensionType) pref.Value {
  472. if !isComposite(xt) {
  473. panic("invalid Mutable on field with non-composite type")
  474. }
  475. if x, ok := (*m)[int32(xt.Number())]; ok {
  476. return xt.ValueOf(x.GetValue())
  477. }
  478. v := xt.New()
  479. m.Set(xt, v)
  480. return v
  481. }
  482. func isComposite(fd pref.FieldDescriptor) bool {
  483. return fd.Kind() == pref.MessageKind || fd.Kind() == pref.GroupKind || fd.IsList() || fd.IsMap()
  484. }
  485. var _ pvalue.Unwrapper = (*messageReflectWrapper)(nil)
  486. type messageIfaceWrapper messageDataType
  487. func (m *messageIfaceWrapper) ProtoReflect() pref.Message {
  488. return (*messageReflectWrapper)(m)
  489. }
  490. func (m *messageIfaceWrapper) XXX_Methods() *piface.Methods {
  491. // TODO: Consider not recreating this on every call.
  492. m.mi.init()
  493. return &piface.Methods{
  494. Flags: piface.MethodFlagDeterministicMarshal,
  495. MarshalAppend: m.marshalAppend,
  496. Size: m.size,
  497. }
  498. }
  499. func (m *messageIfaceWrapper) ProtoUnwrap() interface{} {
  500. return m.p.AsIfaceOf(m.mi.GoType.Elem())
  501. }
  502. func (m *messageIfaceWrapper) marshalAppend(b []byte, _ pref.ProtoMessage, opts piface.MarshalOptions) ([]byte, error) {
  503. return m.mi.marshalAppendPointer(b, m.p, newMarshalOptions(opts))
  504. }
  505. func (m *messageIfaceWrapper) size(msg pref.ProtoMessage) (size int) {
  506. return m.mi.sizePointer(m.p, 0)
  507. }