proto.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. // Copyright 2019 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.md file.
  4. // Package protolegacy is a stub version of the v1 proto package
  5. // to satisfy internal/testprotos/legacy dependencies.
  6. package protolegacy
  7. import (
  8. "bytes"
  9. "compress/gzip"
  10. "errors"
  11. "fmt"
  12. "io/ioutil"
  13. "google.golang.org/protobuf/reflect/protoreflect"
  14. "google.golang.org/protobuf/reflect/protoregistry"
  15. "google.golang.org/protobuf/runtime/protoiface"
  16. "google.golang.org/protobuf/runtime/protoimpl"
  17. )
  18. const (
  19. ProtoPackageIsVersion1 = true
  20. ProtoPackageIsVersion2 = true
  21. ProtoPackageIsVersion3 = true
  22. )
  23. const (
  24. WireVarint = 0
  25. WireFixed32 = 5
  26. WireFixed64 = 1
  27. WireBytes = 2
  28. WireStartGroup = 3
  29. WireEndGroup = 4
  30. )
  31. type (
  32. Message = protoiface.MessageV1
  33. ExtensionRange = protoiface.ExtensionRangeV1
  34. ExtensionDesc = protoimpl.ExtensionInfo
  35. Extension = protoimpl.ExtensionFieldV1
  36. XXX_InternalExtensions = protoimpl.ExtensionFields
  37. )
  38. func RegisterFile(s string, d []byte) {
  39. // Decompress the descriptor.
  40. zr, err := gzip.NewReader(bytes.NewReader(d))
  41. if err != nil {
  42. panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err))
  43. }
  44. b, err := ioutil.ReadAll(zr)
  45. if err != nil {
  46. panic(fmt.Sprintf("proto: invalid compressed file descriptor: %v", err))
  47. }
  48. // Construct a protoreflect.FileDescriptor from the raw descriptor.
  49. // Note that DescBuilder.Build automatically registers the constructed
  50. // file descriptor with the v2 registry.
  51. protoimpl.DescBuilder{RawDescriptor: b}.Build()
  52. }
  53. func RegisterType(m Message, s string) {
  54. mt := protoimpl.X.LegacyMessageTypeOf(m, protoreflect.FullName(s))
  55. if err := protoregistry.GlobalTypes.Register(mt); err != nil {
  56. panic(err)
  57. }
  58. }
  59. func RegisterMapType(interface{}, string) {
  60. // Do nothing.
  61. }
  62. func RegisterEnum(string, map[int32]string, map[string]int32) {
  63. // Do nothing.
  64. }
  65. func RegisterExtension(d *ExtensionDesc) {
  66. if err := protoregistry.GlobalTypes.Register(d); err != nil {
  67. panic(err)
  68. }
  69. }
  70. var ErrInternalBadWireType = errors.New("not implemented")
  71. func Size(Message) int { panic("not implemented") }
  72. func Marshal(Message) ([]byte, error) { panic("not implemented") }
  73. func Unmarshal([]byte, Message) error { panic("not implemented") }
  74. func SizeVarint(uint64) int { panic("not implemented") }
  75. func EncodeVarint(uint64) []byte { panic("not implemented") }
  76. func DecodeVarint([]byte) (uint64, int) { panic("not implemented") }
  77. func CompactTextString(Message) string { panic("not implemented") }
  78. func EnumName(map[int32]string, int32) string { panic("not implemented") }
  79. func UnmarshalJSONEnum(map[string]int32, []byte, string) (int32, error) { panic("not implemented") }
  80. type Buffer struct{}
  81. func (*Buffer) DecodeFixed32() (uint64, error) { panic("not implemented") }
  82. func (*Buffer) DecodeFixed64() (uint64, error) { panic("not implemented") }
  83. func (*Buffer) DecodeGroup(Message) error { panic("not implemented") }
  84. func (*Buffer) DecodeMessage(Message) error { panic("not implemented") }
  85. func (*Buffer) DecodeRawBytes(bool) ([]byte, error) { panic("not implemented") }
  86. func (*Buffer) DecodeStringBytes() (string, error) { panic("not implemented") }
  87. func (*Buffer) DecodeVarint() (uint64, error) { panic("not implemented") }
  88. func (*Buffer) DecodeZigzag32() (uint64, error) { panic("not implemented") }
  89. func (*Buffer) DecodeZigzag64() (uint64, error) { panic("not implemented") }
  90. func (*Buffer) EncodeFixed32(uint64) error { panic("not implemented") }
  91. func (*Buffer) EncodeFixed64(uint64) error { panic("not implemented") }
  92. func (*Buffer) EncodeMessage(Message) error { panic("not implemented") }
  93. func (*Buffer) EncodeRawBytes([]byte) error { panic("not implemented") }
  94. func (*Buffer) EncodeStringBytes(string) error { panic("not implemented") }
  95. func (*Buffer) EncodeVarint(uint64) error { panic("not implemented") }
  96. func (*Buffer) EncodeZigzag32(uint64) error { panic("not implemented") }
  97. func (*Buffer) EncodeZigzag64(uint64) error { panic("not implemented") }
  98. func (*Buffer) Marshal(Message) error { panic("not implemented") }
  99. func (*Buffer) Unmarshal(Message) error { panic("not implemented") }
  100. type InternalMessageInfo struct{}
  101. func (*InternalMessageInfo) DiscardUnknown(Message) { panic("not implemented") }
  102. func (*InternalMessageInfo) Marshal([]byte, Message, bool) ([]byte, error) { panic("not implemented") }
  103. func (*InternalMessageInfo) Merge(Message, Message) { panic("not implemented") }
  104. func (*InternalMessageInfo) Size(Message) int { panic("not implemented") }
  105. func (*InternalMessageInfo) Unmarshal(Message, []byte) error { panic("not implemented") }