...
1
2
3
4
5 package proto
6
7 import (
8 "encoding/json"
9 "errors"
10 "fmt"
11 "strconv"
12
13 protoV2 "google.golang.org/protobuf/proto"
14 )
15
16 var (
17
18 ErrNil = errors.New("proto: Marshal called with nil")
19
20
21 ErrTooLarge = errors.New("proto: message encodes to over 2 GB")
22
23
24 ErrInternalBadWireType = errors.New("proto: internal error: bad wiretype for oneof")
25 )
26
27
28 type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
29
30
31 func GetStats() Stats { return Stats{} }
32
33
34 func MarshalMessageSet(interface{}) ([]byte, error) {
35 return nil, errors.New("proto: not implemented")
36 }
37
38
39 func UnmarshalMessageSet([]byte, interface{}) error {
40 return errors.New("proto: not implemented")
41 }
42
43
44 func MarshalMessageSetJSON(interface{}) ([]byte, error) {
45 return nil, errors.New("proto: not implemented")
46 }
47
48
49 func UnmarshalMessageSetJSON([]byte, interface{}) error {
50 return errors.New("proto: not implemented")
51 }
52
53
54 func RegisterMessageSetType(Message, int32, string) {}
55
56
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
66 func UnmarshalJSONEnum(m map[string]int32, data []byte, enumName string) (int32, error) {
67 if data[0] == '"' {
68
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
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
88 type InternalMessageInfo struct{}
89
90
91 func (*InternalMessageInfo) DiscardUnknown(m Message) {
92 DiscardUnknown(m)
93 }
94
95
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
101 func (*InternalMessageInfo) Merge(dst, src Message) {
102 protoV2.Merge(MessageV2(dst), MessageV2(src))
103 }
104
105
106 func (*InternalMessageInfo) Size(m Message) int {
107 return protoV2.Size(MessageV2(m))
108 }
109
110
111 func (*InternalMessageInfo) Unmarshal(m Message, b []byte) error {
112 return protoV2.UnmarshalOptions{Merge: true}.Unmarshal(b, MessageV2(m))
113 }
114
View as plain text