blob: e8db57e097a1a92dd5998e0724ee4ea40910c168 [file] [log] [blame]
khenaidood948f772021-08-11 17:49:24 -04001// 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.
William Kurkiandaa6bb22019-03-07 12:26:28 -05004
5package proto
6
khenaidood948f772021-08-11 17:49:24 -04007import (
8 "encoding/json"
9 "errors"
10 "fmt"
11 "strconv"
William Kurkiandaa6bb22019-03-07 12:26:28 -050012
khenaidood948f772021-08-11 17:49:24 -040013 protoV2 "google.golang.org/protobuf/proto"
14)
15
16var (
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.
William Kurkiandaa6bb22019-03-07 12:26:28 -050028type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
29
khenaidood948f772021-08-11 17:49:24 -040030// Deprecated: Do not use.
William Kurkiandaa6bb22019-03-07 12:26:28 -050031func GetStats() Stats { return Stats{} }
32
khenaidood948f772021-08-11 17:49:24 -040033// Deprecated: Do not use.
William Kurkiandaa6bb22019-03-07 12:26:28 -050034func MarshalMessageSet(interface{}) ([]byte, error) {
35 return nil, errors.New("proto: not implemented")
36}
37
khenaidood948f772021-08-11 17:49:24 -040038// Deprecated: Do not use.
William Kurkiandaa6bb22019-03-07 12:26:28 -050039func UnmarshalMessageSet([]byte, interface{}) error {
40 return errors.New("proto: not implemented")
41}
42
khenaidood948f772021-08-11 17:49:24 -040043// Deprecated: Do not use.
William Kurkiandaa6bb22019-03-07 12:26:28 -050044func MarshalMessageSetJSON(interface{}) ([]byte, error) {
45 return nil, errors.New("proto: not implemented")
46}
47
khenaidood948f772021-08-11 17:49:24 -040048// Deprecated: Do not use.
William Kurkiandaa6bb22019-03-07 12:26:28 -050049func UnmarshalMessageSetJSON([]byte, interface{}) error {
50 return errors.New("proto: not implemented")
51}
52
khenaidood948f772021-08-11 17:49:24 -040053// Deprecated: Do not use.
William Kurkiandaa6bb22019-03-07 12:26:28 -050054func RegisterMessageSetType(Message, int32, string) {}
khenaidood948f772021-08-11 17:49:24 -040055
56// Deprecated: Do not use.
57func 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.
66func 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.
88type InternalMessageInfo struct{}
89
90// Deprecated: Do not use; this method existed for intenal-use only.
91func (*InternalMessageInfo) DiscardUnknown(m Message) {
92 DiscardUnknown(m)
93}
94
95// Deprecated: Do not use; this method existed for intenal-use only.
96func (*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.
101func (*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.
106func (*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.
111func (*InternalMessageInfo) Unmarshal(m Message, b []byte) error {
112 return protoV2.UnmarshalOptions{Merge: true}.Unmarshal(b, MessageV2(m))
113}