lib.go 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692
  1. // Copyright 2010 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 proto marshals and unmarshals protocol buffer messages as the
  5. // wire-format and text-format. For more information, see:
  6. // https://developers.google.com/protocol-buffers/docs/gotutorial
  7. package proto
  8. import (
  9. "fmt"
  10. "log"
  11. "reflect"
  12. "sort"
  13. "strconv"
  14. "sync"
  15. protoV2 "google.golang.org/protobuf/proto"
  16. "google.golang.org/protobuf/runtime/protoiface"
  17. "google.golang.org/protobuf/runtime/protoimpl"
  18. )
  19. // requiredNotSetError is an error type returned by either Marshal or Unmarshal.
  20. // Marshal reports this when a required field is not initialized.
  21. // Unmarshal reports this when a required field is missing from the wire data.
  22. type requiredNotSetError struct{ field string }
  23. func (e *requiredNotSetError) Error() string {
  24. if e.field == "" {
  25. return fmt.Sprintf("proto: required field not set")
  26. }
  27. return fmt.Sprintf("proto: required field %q not set", e.field)
  28. }
  29. func (e *requiredNotSetError) RequiredNotSet() bool {
  30. return true
  31. }
  32. type invalidUTF8Error struct{ field string }
  33. func (e *invalidUTF8Error) Error() string {
  34. if e.field == "" {
  35. return "proto: invalid UTF-8 detected"
  36. }
  37. return fmt.Sprintf("proto: field %q contains invalid UTF-8", e.field)
  38. }
  39. func (e *invalidUTF8Error) InvalidUTF8() bool {
  40. return true
  41. }
  42. // errInvalidUTF8 is a sentinel error to identify fields with invalid UTF-8.
  43. // This error should not be exposed to the external API as such errors should
  44. // be recreated with the field information.
  45. var errInvalidUTF8 = &invalidUTF8Error{}
  46. // isNonFatal reports whether the error is either a RequiredNotSet error
  47. // or a InvalidUTF8 error.
  48. func isNonFatal(err error) bool {
  49. if re, ok := err.(interface{ RequiredNotSet() bool }); ok && re.RequiredNotSet() {
  50. return true
  51. }
  52. if re, ok := err.(interface{ InvalidUTF8() bool }); ok && re.InvalidUTF8() {
  53. return true
  54. }
  55. return false
  56. }
  57. type nonFatal struct{ E error }
  58. // Merge merges err into nf and reports whether it was successful.
  59. // Otherwise it returns false for any fatal non-nil errors.
  60. func (nf *nonFatal) Merge(err error) (ok bool) {
  61. if err == nil {
  62. return true // not an error
  63. }
  64. if !isNonFatal(err) {
  65. return false // fatal error
  66. }
  67. if nf.E == nil {
  68. nf.E = err // store first instance of non-fatal error
  69. }
  70. return true
  71. }
  72. // Message is implemented by generated protocol buffer messages.
  73. type Message = protoiface.MessageV1
  74. var protoMessageType = reflect.TypeOf((*Message)(nil)).Elem()
  75. var marshalerType = reflect.TypeOf((*Marshaler)(nil)).Elem()
  76. type (
  77. oneofFuncsIface interface {
  78. XXX_OneofFuncs() (func(Message, *Buffer) error, func(Message, int, int, *Buffer) (bool, error), func(Message) int, []interface{})
  79. }
  80. oneofWrappersIface interface {
  81. XXX_OneofWrappers() []interface{}
  82. }
  83. )
  84. // oneofWrappers returns a list of oneof wrappers for t,
  85. // which must be a named struct type.
  86. func oneofWrappers(t reflect.Type) []interface{} {
  87. var oos []interface{}
  88. switch m := reflect.Zero(reflect.PtrTo(t)).Interface().(type) {
  89. case oneofFuncsIface:
  90. _, _, _, oos = m.XXX_OneofFuncs()
  91. case oneofWrappersIface:
  92. oos = m.XXX_OneofWrappers()
  93. case protoV2.Message:
  94. if m, ok := m.ProtoReflect().(interface{ ProtoMessageInfo() *protoimpl.MessageInfo }); ok {
  95. oos = m.ProtoMessageInfo().OneofWrappers
  96. }
  97. }
  98. return oos
  99. }
  100. // unknownFieldsValue retrieves the value for unknown fields from v,
  101. // which must be a name struct type.
  102. func unknownFieldsValue(v reflect.Value) reflect.Value {
  103. if vf := v.FieldByName("XXX_unrecognized"); vf.IsValid() {
  104. return vf
  105. }
  106. if vf := fieldByName(v, "unknownFields"); vf.IsValid() {
  107. return vf
  108. }
  109. return reflect.Value{}
  110. }
  111. // extensionFieldsValue retrieves the value for extension fields from v,
  112. // which must be a name struct type.
  113. func extensionFieldsValue(v reflect.Value) reflect.Value {
  114. if vf := v.FieldByName("XXX_InternalExtensions"); vf.IsValid() {
  115. return vf
  116. }
  117. if vf := v.FieldByName("XXX_extensions"); vf.IsValid() {
  118. return vf
  119. }
  120. if vf := fieldByName(v, "extensionFields"); vf.IsValid() {
  121. return vf
  122. }
  123. return reflect.Value{}
  124. }
  125. // exporterFunc retrieves the field exporter function for t,
  126. // which must be a named struct type.
  127. func exporterFunc(t reflect.Type) func(interface{}, int) interface{} {
  128. if m, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(protoV2.Message); ok {
  129. if m, ok := m.ProtoReflect().(interface{ ProtoMessageInfo() *protoimpl.MessageInfo }); ok {
  130. return m.ProtoMessageInfo().Exporter
  131. }
  132. }
  133. return nil
  134. }
  135. // isMessageSet determines whether t is a MessageSet message,
  136. // where t must be a named struct type.
  137. func isMessageSet(t reflect.Type) bool {
  138. if m, ok := reflect.Zero(reflect.PtrTo(t)).Interface().(protoV2.Message); ok {
  139. md := m.ProtoReflect().Descriptor()
  140. xmd, ok := md.(interface{ IsMessageSet() bool })
  141. return ok && xmd.IsMessageSet()
  142. }
  143. return false
  144. }
  145. // A Buffer is a buffer manager for marshaling and unmarshaling
  146. // protocol buffers. It may be reused between invocations to
  147. // reduce memory usage. It is not necessary to use a Buffer;
  148. // the global functions Marshal and Unmarshal create a
  149. // temporary Buffer and are fine for most applications.
  150. type Buffer struct {
  151. buf []byte // encode/decode byte stream
  152. index int // read point
  153. deterministic bool
  154. }
  155. // NewBuffer allocates a new Buffer and initializes its internal data to
  156. // the contents of the argument slice.
  157. func NewBuffer(e []byte) *Buffer {
  158. return &Buffer{buf: e}
  159. }
  160. // Reset resets the Buffer, ready for marshaling a new protocol buffer.
  161. func (p *Buffer) Reset() {
  162. p.buf = p.buf[0:0] // for reading/writing
  163. p.index = 0 // for reading
  164. }
  165. // SetBuf replaces the internal buffer with the slice,
  166. // ready for unmarshaling the contents of the slice.
  167. func (p *Buffer) SetBuf(s []byte) {
  168. p.buf = s
  169. p.index = 0
  170. }
  171. // Bytes returns the contents of the Buffer.
  172. func (p *Buffer) Bytes() []byte { return p.buf }
  173. // SetDeterministic sets whether to use deterministic serialization.
  174. //
  175. // Deterministic serialization guarantees that for a given binary, equal
  176. // messages will always be serialized to the same bytes. This implies:
  177. //
  178. // - Repeated serialization of a message will return the same bytes.
  179. // - Different processes of the same binary (which may be executing on
  180. // different machines) will serialize equal messages to the same bytes.
  181. //
  182. // Note that the deterministic serialization is NOT canonical across
  183. // languages. It is not guaranteed to remain stable over time. It is unstable
  184. // across different builds with schema changes due to unknown fields.
  185. // Users who need canonical serialization (e.g., persistent storage in a
  186. // canonical form, fingerprinting, etc.) should define their own
  187. // canonicalization specification and implement their own serializer rather
  188. // than relying on this API.
  189. //
  190. // If deterministic serialization is requested, map entries will be sorted
  191. // by keys in lexographical order. This is an implementation detail and
  192. // subject to change.
  193. func (p *Buffer) SetDeterministic(deterministic bool) {
  194. p.deterministic = deterministic
  195. }
  196. // DebugPrint dumps the encoded data in b in a debugging format with a header
  197. // including the string s. Used in testing but made available for general debugging.
  198. func (p *Buffer) DebugPrint(s string, b []byte) {
  199. var u uint64
  200. obuf := p.buf
  201. index := p.index
  202. p.buf = b
  203. p.index = 0
  204. depth := 0
  205. fmt.Printf("\n--- %s ---\n", s)
  206. out:
  207. for {
  208. for i := 0; i < depth; i++ {
  209. fmt.Print(" ")
  210. }
  211. index := p.index
  212. if index == len(p.buf) {
  213. break
  214. }
  215. op, err := p.DecodeVarint()
  216. if err != nil {
  217. fmt.Printf("%3d: fetching op err %v\n", index, err)
  218. break out
  219. }
  220. tag := op >> 3
  221. wire := op & 7
  222. switch wire {
  223. default:
  224. fmt.Printf("%3d: t=%3d unknown wire=%d\n",
  225. index, tag, wire)
  226. break out
  227. case WireBytes:
  228. var r []byte
  229. r, err = p.DecodeRawBytes(false)
  230. if err != nil {
  231. break out
  232. }
  233. fmt.Printf("%3d: t=%3d bytes [%d]", index, tag, len(r))
  234. if len(r) <= 6 {
  235. for i := 0; i < len(r); i++ {
  236. fmt.Printf(" %.2x", r[i])
  237. }
  238. } else {
  239. for i := 0; i < 3; i++ {
  240. fmt.Printf(" %.2x", r[i])
  241. }
  242. fmt.Printf(" ..")
  243. for i := len(r) - 3; i < len(r); i++ {
  244. fmt.Printf(" %.2x", r[i])
  245. }
  246. }
  247. fmt.Printf("\n")
  248. case WireFixed32:
  249. u, err = p.DecodeFixed32()
  250. if err != nil {
  251. fmt.Printf("%3d: t=%3d fix32 err %v\n", index, tag, err)
  252. break out
  253. }
  254. fmt.Printf("%3d: t=%3d fix32 %d\n", index, tag, u)
  255. case WireFixed64:
  256. u, err = p.DecodeFixed64()
  257. if err != nil {
  258. fmt.Printf("%3d: t=%3d fix64 err %v\n", index, tag, err)
  259. break out
  260. }
  261. fmt.Printf("%3d: t=%3d fix64 %d\n", index, tag, u)
  262. case WireVarint:
  263. u, err = p.DecodeVarint()
  264. if err != nil {
  265. fmt.Printf("%3d: t=%3d varint err %v\n", index, tag, err)
  266. break out
  267. }
  268. fmt.Printf("%3d: t=%3d varint %d\n", index, tag, u)
  269. case WireStartGroup:
  270. fmt.Printf("%3d: t=%3d start\n", index, tag)
  271. depth++
  272. case WireEndGroup:
  273. depth--
  274. fmt.Printf("%3d: t=%3d end\n", index, tag)
  275. }
  276. }
  277. if depth != 0 {
  278. fmt.Printf("%3d: start-end not balanced %d\n", p.index, depth)
  279. }
  280. fmt.Printf("\n")
  281. p.buf = obuf
  282. p.index = index
  283. }
  284. // SetDefaults sets unset protocol buffer fields to their default values.
  285. // It only modifies fields that are both unset and have defined defaults.
  286. // It recursively sets default values in any non-nil sub-messages.
  287. func SetDefaults(pb Message) {
  288. if setDefaultsAlt != nil {
  289. setDefaultsAlt(pb) // populated by hooks_enabled.go
  290. return
  291. }
  292. setDefaults(reflect.ValueOf(pb), true, false)
  293. }
  294. // v is a pointer to a struct.
  295. func setDefaults(v reflect.Value, recur, zeros bool) {
  296. v = v.Elem()
  297. defaultMu.RLock()
  298. dm, ok := defaults[v.Type()]
  299. defaultMu.RUnlock()
  300. if !ok {
  301. dm = buildDefaultMessage(v.Type())
  302. defaultMu.Lock()
  303. defaults[v.Type()] = dm
  304. defaultMu.Unlock()
  305. }
  306. for _, sf := range dm.scalars {
  307. f := v.Field(sf.index)
  308. if !f.IsNil() {
  309. // field already set
  310. continue
  311. }
  312. dv := sf.value
  313. if dv == nil && !zeros {
  314. // no explicit default, and don't want to set zeros
  315. continue
  316. }
  317. fptr := f.Addr().Interface() // **T
  318. // TODO: Consider batching the allocations we do here.
  319. switch sf.kind {
  320. case reflect.Bool:
  321. b := new(bool)
  322. if dv != nil {
  323. *b = dv.(bool)
  324. }
  325. *(fptr.(**bool)) = b
  326. case reflect.Float32:
  327. f := new(float32)
  328. if dv != nil {
  329. *f = dv.(float32)
  330. }
  331. *(fptr.(**float32)) = f
  332. case reflect.Float64:
  333. f := new(float64)
  334. if dv != nil {
  335. *f = dv.(float64)
  336. }
  337. *(fptr.(**float64)) = f
  338. case reflect.Int32:
  339. // might be an enum
  340. if ft := f.Type(); ft != int32PtrType {
  341. // enum
  342. f.Set(reflect.New(ft.Elem()))
  343. if dv != nil {
  344. f.Elem().SetInt(int64(dv.(int32)))
  345. }
  346. } else {
  347. // int32 field
  348. i := new(int32)
  349. if dv != nil {
  350. *i = dv.(int32)
  351. }
  352. *(fptr.(**int32)) = i
  353. }
  354. case reflect.Int64:
  355. i := new(int64)
  356. if dv != nil {
  357. *i = dv.(int64)
  358. }
  359. *(fptr.(**int64)) = i
  360. case reflect.String:
  361. s := new(string)
  362. if dv != nil {
  363. *s = dv.(string)
  364. }
  365. *(fptr.(**string)) = s
  366. case reflect.Uint8:
  367. // exceptional case: []byte
  368. var b []byte
  369. if dv != nil {
  370. db := dv.([]byte)
  371. b = make([]byte, len(db))
  372. copy(b, db)
  373. } else {
  374. b = []byte{}
  375. }
  376. *(fptr.(*[]byte)) = b
  377. case reflect.Uint32:
  378. u := new(uint32)
  379. if dv != nil {
  380. *u = dv.(uint32)
  381. }
  382. *(fptr.(**uint32)) = u
  383. case reflect.Uint64:
  384. u := new(uint64)
  385. if dv != nil {
  386. *u = dv.(uint64)
  387. }
  388. *(fptr.(**uint64)) = u
  389. default:
  390. log.Printf("proto: can't set default for field %v (sf.kind=%v)", f, sf.kind)
  391. }
  392. }
  393. for _, ni := range dm.nested {
  394. f := v.Field(ni)
  395. // f is *T or []*T or map[T]*T
  396. switch f.Kind() {
  397. case reflect.Ptr:
  398. if f.IsNil() {
  399. continue
  400. }
  401. setDefaults(f, recur, zeros)
  402. case reflect.Slice:
  403. for i := 0; i < f.Len(); i++ {
  404. e := f.Index(i)
  405. if e.IsNil() {
  406. continue
  407. }
  408. setDefaults(e, recur, zeros)
  409. }
  410. case reflect.Map:
  411. for _, k := range f.MapKeys() {
  412. e := f.MapIndex(k)
  413. if e.IsNil() {
  414. continue
  415. }
  416. setDefaults(e, recur, zeros)
  417. }
  418. }
  419. }
  420. }
  421. var (
  422. // defaults maps a protocol buffer struct type to a slice of the fields,
  423. // with its scalar fields set to their proto-declared non-zero default values.
  424. defaultMu sync.RWMutex
  425. defaults = make(map[reflect.Type]defaultMessage)
  426. int32PtrType = reflect.TypeOf((*int32)(nil))
  427. )
  428. // defaultMessage represents information about the default values of a message.
  429. type defaultMessage struct {
  430. scalars []scalarField
  431. nested []int // struct field index of nested messages
  432. }
  433. type scalarField struct {
  434. index int // struct field index
  435. kind reflect.Kind // element type (the T in *T or []T)
  436. value interface{} // the proto-declared default value, or nil
  437. }
  438. // t is a struct type.
  439. func buildDefaultMessage(t reflect.Type) (dm defaultMessage) {
  440. sprop := GetProperties(t)
  441. for fi, prop := range sprop.Prop {
  442. if prop.Tag <= 0 {
  443. // XXX_unrecognized
  444. continue
  445. }
  446. ft := t.Field(fi).Type
  447. sf, nested, err := fieldDefault(ft, prop)
  448. switch {
  449. case err != nil:
  450. log.Print(err)
  451. case nested:
  452. dm.nested = append(dm.nested, fi)
  453. case sf != nil:
  454. sf.index = fi
  455. dm.scalars = append(dm.scalars, *sf)
  456. }
  457. }
  458. return dm
  459. }
  460. // fieldDefault returns the scalarField for field type ft.
  461. // sf will be nil if the field can not have a default.
  462. // nestedMessage will be true if this is a nested message.
  463. // Note that sf.index is not set on return.
  464. func fieldDefault(ft reflect.Type, prop *Properties) (sf *scalarField, nestedMessage bool, err error) {
  465. var canHaveDefault bool
  466. switch ft.Kind() {
  467. case reflect.Ptr:
  468. if ft.Elem().Kind() == reflect.Struct {
  469. nestedMessage = true
  470. } else {
  471. canHaveDefault = true // proto2 scalar field
  472. }
  473. case reflect.Slice:
  474. switch ft.Elem().Kind() {
  475. case reflect.Ptr:
  476. nestedMessage = true // repeated message
  477. case reflect.Uint8:
  478. canHaveDefault = true // bytes field
  479. }
  480. case reflect.Map:
  481. if ft.Elem().Kind() == reflect.Ptr {
  482. nestedMessage = true // map with message values
  483. }
  484. }
  485. if !canHaveDefault {
  486. if nestedMessage {
  487. return nil, true, nil
  488. }
  489. return nil, false, nil
  490. }
  491. // We now know that ft is a pointer or slice.
  492. sf = &scalarField{kind: ft.Elem().Kind()}
  493. // scalar fields without defaults
  494. if !prop.HasDefault {
  495. return sf, false, nil
  496. }
  497. // a scalar field: either *T or []byte
  498. switch ft.Elem().Kind() {
  499. case reflect.Bool:
  500. x, err := strconv.ParseBool(prop.Default)
  501. if err != nil {
  502. return nil, false, fmt.Errorf("proto: bad default bool %q: %v", prop.Default, err)
  503. }
  504. sf.value = x
  505. case reflect.Float32:
  506. x, err := strconv.ParseFloat(prop.Default, 32)
  507. if err != nil {
  508. return nil, false, fmt.Errorf("proto: bad default float32 %q: %v", prop.Default, err)
  509. }
  510. sf.value = float32(x)
  511. case reflect.Float64:
  512. x, err := strconv.ParseFloat(prop.Default, 64)
  513. if err != nil {
  514. return nil, false, fmt.Errorf("proto: bad default float64 %q: %v", prop.Default, err)
  515. }
  516. sf.value = x
  517. case reflect.Int32:
  518. x, err := strconv.ParseInt(prop.Default, 10, 32)
  519. if err != nil {
  520. return nil, false, fmt.Errorf("proto: bad default int32 %q: %v", prop.Default, err)
  521. }
  522. sf.value = int32(x)
  523. case reflect.Int64:
  524. x, err := strconv.ParseInt(prop.Default, 10, 64)
  525. if err != nil {
  526. return nil, false, fmt.Errorf("proto: bad default int64 %q: %v", prop.Default, err)
  527. }
  528. sf.value = x
  529. case reflect.String:
  530. sf.value = prop.Default
  531. case reflect.Uint8:
  532. // []byte (not *uint8)
  533. sf.value = []byte(prop.Default)
  534. case reflect.Uint32:
  535. x, err := strconv.ParseUint(prop.Default, 10, 32)
  536. if err != nil {
  537. return nil, false, fmt.Errorf("proto: bad default uint32 %q: %v", prop.Default, err)
  538. }
  539. sf.value = uint32(x)
  540. case reflect.Uint64:
  541. x, err := strconv.ParseUint(prop.Default, 10, 64)
  542. if err != nil {
  543. return nil, false, fmt.Errorf("proto: bad default uint64 %q: %v", prop.Default, err)
  544. }
  545. sf.value = x
  546. default:
  547. return nil, false, fmt.Errorf("proto: unhandled def kind %v", ft.Elem().Kind())
  548. }
  549. return sf, false, nil
  550. }
  551. // mapKeys returns a sort.Interface to be used for sorting the map keys.
  552. // Map fields may have key types of non-float scalars, strings and enums.
  553. func mapKeys(vs []reflect.Value) sort.Interface {
  554. s := mapKeySorter{vs: vs}
  555. // Type specialization per https://developers.google.com/protocol-buffers/docs/proto#maps.
  556. if len(vs) == 0 {
  557. return s
  558. }
  559. switch vs[0].Kind() {
  560. case reflect.Int32, reflect.Int64:
  561. s.less = func(a, b reflect.Value) bool { return a.Int() < b.Int() }
  562. case reflect.Uint32, reflect.Uint64:
  563. s.less = func(a, b reflect.Value) bool { return a.Uint() < b.Uint() }
  564. case reflect.Bool:
  565. s.less = func(a, b reflect.Value) bool { return !a.Bool() && b.Bool() } // false < true
  566. case reflect.String:
  567. s.less = func(a, b reflect.Value) bool { return a.String() < b.String() }
  568. default:
  569. panic(fmt.Sprintf("unsupported map key type: %v", vs[0].Kind()))
  570. }
  571. return s
  572. }
  573. type mapKeySorter struct {
  574. vs []reflect.Value
  575. less func(a, b reflect.Value) bool
  576. }
  577. func (s mapKeySorter) Len() int { return len(s.vs) }
  578. func (s mapKeySorter) Swap(i, j int) { s.vs[i], s.vs[j] = s.vs[j], s.vs[i] }
  579. func (s mapKeySorter) Less(i, j int) bool {
  580. return s.less(s.vs[i], s.vs[j])
  581. }
  582. // isProto3Zero reports whether v is a zero proto3 value.
  583. func isProto3Zero(v reflect.Value) bool {
  584. switch v.Kind() {
  585. case reflect.Bool:
  586. return !v.Bool()
  587. case reflect.Int32, reflect.Int64:
  588. return v.Int() == 0
  589. case reflect.Uint32, reflect.Uint64:
  590. return v.Uint() == 0
  591. case reflect.Float32, reflect.Float64:
  592. return v.Float() == 0
  593. case reflect.String:
  594. return v.String() == ""
  595. }
  596. return false
  597. }
  598. const (
  599. // ProtoPackageIsVersion3 is referenced from generated protocol buffer files
  600. // to assert that that code is compatible with this version of the proto package.
  601. ProtoPackageIsVersion3 = true
  602. // ProtoPackageIsVersion2 is referenced from generated protocol buffer files
  603. // to assert that that code is compatible with this version of the proto package.
  604. ProtoPackageIsVersion2 = true
  605. // ProtoPackageIsVersion1 is referenced from generated protocol buffer files
  606. // to assert that that code is compatible with this version of the proto package.
  607. ProtoPackageIsVersion1 = true
  608. )
  609. // InternalMessageInfo is a type used internally by generated .pb.go files.
  610. // This type is not intended to be used by non-generated code.
  611. // This type is not subject to any compatibility guarantee.
  612. type InternalMessageInfo struct {
  613. marshal *marshalInfo
  614. unmarshal *unmarshalInfo
  615. merge *mergeInfo
  616. discard *discardInfo
  617. }