-
Notifications
You must be signed in to change notification settings - Fork 0
/
wrappers.go
352 lines (296 loc) · 8.89 KB
/
wrappers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
package wrapperspb
import (
"encoding/base64"
"math"
"strconv"
"github.com/aperturerobotics/protobuf-go-lite/json"
)
// MarshalJSON marshals the DoubleValue to JSON.
func (x *DoubleValue) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the DoubleValue from JSON.
func (x *DoubleValue) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a DoubleValue from JSON.
func (x *DoubleValue) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = DoubleValue{Value: s.ReadFloat64()}
}
// MarshalProtoJSON marshals a DoubleValue to JSON.
func (x *DoubleValue) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteFloat64(x.Value)
}
// String formats the DoubleValue to a string.
func (x *DoubleValue) String() string {
return strconv.FormatFloat(x.Value, 'g', -1, 64)
}
// MarshalProtoText formats the DoubleValue to a proto text string.
func (x *DoubleValue) MarshalProtoText() string {
return x.String()
}
// MarshalJSON marshals the FloatValue to JSON.
func (x *FloatValue) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the FloatValue from JSON.
func (x *FloatValue) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a FloatValue from JSON.
func (x *FloatValue) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = FloatValue{Value: float32(s.ReadFloat64())}
}
// MarshalProtoJSON marshals a FloatValue to JSON.
func (x *FloatValue) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteFloat64(float64(x.Value))
}
// String formats the FloatValue to a string.
func (x *FloatValue) String() string {
return strconv.FormatFloat(float64(x.Value), 'g', -1, 32)
}
// MarshalProtoText formats the FloatValue to a proto text string.
func (x *FloatValue) MarshalProtoText() string {
return x.String()
}
// MarshalJSON marshals the Int64Value to JSON.
func (x *Int64Value) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the Int64Value from JSON.
func (x *Int64Value) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a Int64Value from JSON.
func (x *Int64Value) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = Int64Value{Value: s.ReadInt64()}
}
// MarshalProtoJSON marshals a Int64Value to JSON.
func (x *Int64Value) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteInt64(x.Value)
}
// String formats the Int64Value to a string.
func (x *Int64Value) String() string {
return strconv.FormatInt(x.Value, 10)
}
// MarshalProtoText formats the Int64Value to a proto text string.
func (x *Int64Value) MarshalProtoText() string {
return x.String()
}
// MarshalJSON marshals the UInt64Value to JSON.
func (x *UInt64Value) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the UInt64Value from JSON.
func (x *UInt64Value) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a UInt64Value from JSON.
func (x *UInt64Value) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = UInt64Value{Value: s.ReadUint64()}
}
// MarshalProtoJSON marshals a UInt64Value to JSON.
func (x *UInt64Value) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteUint64(x.Value)
}
// String formats the UInt64Value to a string.
func (x *UInt64Value) String() string {
return strconv.FormatUint(x.Value, 10)
}
// MarshalProtoText formats the UInt64Value to a proto text string.
func (x *UInt64Value) MarshalProtoText() string {
return x.String()
}
// MarshalJSON marshals the Int32Value to JSON.
func (x *Int32Value) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the Int32Value from JSON.
func (x *Int32Value) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a Int32Value from JSON.
func (x *Int32Value) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
v := s.ReadInt64()
if v < math.MinInt32 || v > math.MaxInt32 {
s.SetErrorf("value out of range for int32: %v", v)
return
}
*x = Int32Value{Value: int32(v)}
}
// MarshalProtoJSON marshals a Int32Value to JSON.
func (x *Int32Value) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteInt64(int64(x.Value))
}
// String formats the Int32Value to a string.
func (x *Int32Value) String() string {
return strconv.Itoa(int(x.Value))
}
// MarshalProtoText formats the Int32Value to a proto text string.
func (x *Int32Value) MarshalProtoText() string {
return x.String()
}
// MarshalJSON marshals the UInt32Value to JSON.
func (x *UInt32Value) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the UInt32Value from JSON.
func (x *UInt32Value) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a UInt32Value from JSON.
func (x *UInt32Value) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
v := s.ReadUint64()
if v > math.MaxUint32 {
s.SetErrorf("value out of range for uint32: %v", v)
return
}
*x = UInt32Value{Value: uint32(v)}
}
// MarshalProtoJSON marshals a UInt32Value to JSON.
func (x *UInt32Value) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteUint64(uint64(x.Value))
}
// String formats the UInt32Value to a string.
func (x *UInt32Value) String() string {
return strconv.FormatUint(uint64(x.Value), 10)
}
// MarshalProtoText formats the UInt32Value to a proto text string.
func (x *UInt32Value) MarshalProtoText() string {
return x.String()
}
// MarshalJSON marshals the BoolValue to JSON.
func (x *BoolValue) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the BoolValue from JSON.
func (x *BoolValue) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a BoolValue from JSON.
func (x *BoolValue) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = BoolValue{Value: s.ReadBool()}
}
// MarshalProtoJSON marshals a BoolValue to JSON.
func (x *BoolValue) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteBool(x.Value)
}
// String formats the BoolValue to a string.
func (x *BoolValue) String() string {
return strconv.FormatBool(x.Value)
}
// MarshalProtoText formats the BoolValue to a proto text string.
func (x *BoolValue) MarshalProtoText() string {
return x.String()
}
// MarshalJSON marshals the StringValue to JSON.
func (x *StringValue) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the StringValue from JSON.
func (x *StringValue) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a StringValue from JSON.
func (x *StringValue) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = StringValue{Value: s.ReadString()}
}
// MarshalProtoJSON marshals a StringValue to JSON.
func (x *StringValue) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteString(x.Value)
}
// String formats the StringValue to a string.
func (x *StringValue) String() string {
return x.Value
}
// MarshalProtoText formats the StringValue to a proto text string.
func (x *StringValue) MarshalProtoText() string {
return strconv.Quote(x.String())
}
// MarshalJSON marshals the BytesValue to JSON.
func (x *BytesValue) MarshalJSON() ([]byte, error) {
return json.DefaultMarshalerConfig.Marshal(x)
}
// UnmarshalJSON unmarshals the BytesValue from JSON.
func (x *BytesValue) UnmarshalJSON(b []byte) error {
return json.DefaultUnmarshalerConfig.Unmarshal(b, x)
}
// UnmarshalProtoJSON unmarshals a BytesValue from JSON.
func (x *BytesValue) UnmarshalProtoJSON(s *json.UnmarshalState) {
if s.ReadNil() {
return
}
*x = BytesValue{Value: s.ReadBytes()}
}
// MarshalProtoJSON marshals a BytesValue to JSON.
func (x *BytesValue) MarshalProtoJSON(s *json.MarshalState) {
if x == nil {
s.WriteNil()
return
}
s.WriteBytes(x.Value)
}
// String formats the BytesValue to a string.
func (x *BytesValue) String() string {
return base64.StdEncoding.EncodeToString(x.GetValue())
}
// MarshalProtoText formats the BytesValue to a proto text string.
func (x *BytesValue) MarshalProtoText() string {
return strconv.Quote(x.String())
}