blob: e8db57e097a1a92dd5998e0724ee4ea40910c168 [file] [log] [blame]
amit.ghosh258d14c2020-10-02 15:13:38 +02001// 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 Scandoloa6a3aee2019-11-26 13:30:14 -07004
5package proto
6
amit.ghosh258d14c2020-10-02 15:13:38 +02007import (
8 "encoding/json"
9 "errors"
10 "fmt"
11 "strconv"
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070012
amit.ghosh258d14c2020-10-02 15:13:38 +020013 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.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070028type Stats struct{ Emalloc, Dmalloc, Encode, Decode, Chit, Cmiss, Size uint64 }
29
amit.ghosh258d14c2020-10-02 15:13:38 +020030// Deprecated: Do not use.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070031func GetStats() Stats { return Stats{} }
32
amit.ghosh258d14c2020-10-02 15:13:38 +020033// Deprecated: Do not use.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070034func MarshalMessageSet(interface{}) ([]byte, error) {
35 return nil, errors.New("proto: not implemented")
36}
37
amit.ghosh258d14c2020-10-02 15:13:38 +020038// Deprecated: Do not use.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070039func UnmarshalMessageSet([]byte, interface{}) error {
40 return errors.New("proto: not implemented")
41}
42
amit.ghosh258d14c2020-10-02 15:13:38 +020043// Deprecated: Do not use.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070044func MarshalMessageSetJSON(interface{}) ([]byte, error) {
45 return nil, errors.New("proto: not implemented")
46}
47
amit.ghosh258d14c2020-10-02 15:13:38 +020048// Deprecated: Do not use.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070049func UnmarshalMessageSetJSON([]byte, interface{}) error {
50 return errors.New("proto: not implemented")
51}
52
amit.ghosh258d14c2020-10-02 15:13:38 +020053// Deprecated: Do not use.
Matteo Scandoloa6a3aee2019-11-26 13:30:14 -070054func RegisterMessageSetType(Message, int32, string) {}
amit.ghosh258d14c2020-10-02 15:13:38 +020055
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}