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