blob: e8db57e097a1a92dd5998e0724ee4ea40910c168 [file] [log] [blame]
mpagenkoaf801632020-07-03 10:00:42 +00001// 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.
Holger Hildebrandtfa074992020-03-27 15:42:06 +00004
5package proto
6
mpagenkoaf801632020-07-03 10:00:42 +00007import (
8 "encoding/json"
9 "errors"
10 "fmt"
11 "strconv"
Holger Hildebrandtfa074992020-03-27 15:42:06 +000012
mpagenkoaf801632020-07-03 10:00:42 +000013 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.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000028type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
29
mpagenkoaf801632020-07-03 10:00:42 +000030// Deprecated: Do not use.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000031func GetStats() Stats { return Stats{} }
32
mpagenkoaf801632020-07-03 10:00:42 +000033// Deprecated: Do not use.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000034func MarshalMessageSet(interface{}) ([]byte, error) {
35 return nil, errors.New("proto: not implemented")
36}
37
mpagenkoaf801632020-07-03 10:00:42 +000038// Deprecated: Do not use.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000039func UnmarshalMessageSet([]byte, interface{}) error {
40 return errors.New("proto: not implemented")
41}
42
mpagenkoaf801632020-07-03 10:00:42 +000043// Deprecated: Do not use.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000044func MarshalMessageSetJSON(interface{}) ([]byte, error) {
45 return nil, errors.New("proto: not implemented")
46}
47
mpagenkoaf801632020-07-03 10:00:42 +000048// Deprecated: Do not use.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000049func UnmarshalMessageSetJSON([]byte, interface{}) error {
50 return errors.New("proto: not implemented")
51}
52
mpagenkoaf801632020-07-03 10:00:42 +000053// Deprecated: Do not use.
Holger Hildebrandtfa074992020-03-27 15:42:06 +000054func RegisterMessageSetType(Message, int32, string) {}
mpagenkoaf801632020-07-03 10:00:42 +000055
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}