deprecated.go 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  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 proto
  5. import (
  6. "encoding/json"
  7. "errors"
  8. "fmt"
  9. "strconv"
  10. protoV2 "google.golang.org/protobuf/proto"
  11. )
  12. var (
  13. // Deprecated: No longer returned.
  14. ErrNil = errors.New("proto: Marshal called with nil")
  15. // Deprecated: No longer returned.
  16. ErrTooLarge = errors.New("proto: message encodes to over 2 GB")
  17. // Deprecated: No longer returned.
  18. ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
  19. )
  20. // Deprecated: Do not use.
  21. type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
  22. // Deprecated: Do not use.
  23. func GetStats() Stats { return Stats{} }
  24. // Deprecated: Do not use.
  25. func MarshalMessageSet(interface{}) ([]byte, error) {
  26. return nil, errors.New("proto: not implemented")
  27. }
  28. // Deprecated: Do not use.
  29. func UnmarshalMessageSet([]byte, interface{}) error {
  30. return errors.New("proto: not implemented")
  31. }
  32. // Deprecated: Do not use.
  33. func MarshalMessageSetJSON(interface{}) ([]byte, error) {
  34. return nil, errors.New("proto: not implemented")
  35. }
  36. // Deprecated: Do not use.
  37. func UnmarshalMessageSetJSON([]byte, interface{}) error {
  38. return errors.New("proto: not implemented")
  39. }
  40. // Deprecated: Do not use.
  41. func RegisterMessageSetType(Message, int32, string) {}
  42. // Deprecated: Do not use.
  43. func EnumName(m map[int32]string, v int32) string {
  44. s, ok := m[v]
  45. if ok {
  46. return s
  47. }
  48. return strconv.Itoa(int(v))
  49. }
  50. // Deprecated: Do not use.
  51. func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
  52. if data[0] == '"' {
  53. // New style: enums are strings.
  54. var repr string
  55. if err := json.Unmarshal(data, &repr); err != nil {
  56. return -1, err
  57. }
  58. val, ok := m[repr]
  59. if !ok {
  60. return 0, fmt.Errorf("unrecognized enum %s value %q", enumName, repr)
  61. }
  62. return val, nil
  63. }
  64. // Old style: enums are ints.
  65. var val int32
  66. if err := json.Unmarshal(data, &val); err != nil {
  67. return 0, fmt.Errorf("cannot unmarshal %#q into enum %s", data, enumName)
  68. }
  69. return val, nil
  70. }
  71. // Deprecated: Do not use; this type existed for intenal-use only.
  72. type InternalMessageInfo struct{}
  73. // Deprecated: Do not use; this method existed for intenal-use only.
  74. func (*InternalMessageInfo) DiscardUnknown(m Message) {
  75. DiscardUnknown(m)
  76. }
  77. // Deprecated: Do not use; this method existed for intenal-use only.
  78. func (*InternalMessageInfo) Marshal(b []byte, m Message, deterministic bool) ([]byte, error) {
  79. return protoV2.MarshalOptions{Deterministic: deterministic}.MarshalAppend(b, MessageV2(m))
  80. }
  81. // Deprecated: Do not use; this method existed for intenal-use only.
  82. func (*InternalMessageInfo) Merge(dst, src Message) {
  83. protoV2.Merge(MessageV2(dst), MessageV2(src))
  84. }
  85. // Deprecated: Do not use; this method existed for intenal-use only.
  86. func (*InternalMessageInfo) Size(m Message) int {
  87. return protoV2.Size(MessageV2(m))
  88. }
  89. // Deprecated: Do not use; this method existed for intenal-use only.
  90. func (*InternalMessageInfo) Unmarshal(m Message, b []byte) error {
  91. return protoV2.UnmarshalOptions{Merge: true}.Unmarshal(b, MessageV2(m))
  92. }