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