Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

114 строки
3.1 KiB

  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. }