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