/
common.go
673 lines (584 loc) · 18.2 KB
/
common.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
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
// Code generated by thriftrw v1.22.0. DO NOT EDIT.
// @generated
package common
import (
errors "errors"
fmt "fmt"
thriftreflect "go.uber.org/thriftrw/thriftreflect"
wire "go.uber.org/thriftrw/wire"
zapcore "go.uber.org/zap/zapcore"
strings "strings"
)
// ThriftModule represents the IDL file used to generate this package.
var ThriftModule = &thriftreflect.ThriftModule{
Name: "common",
Package: "go.uber.org/yarpc/encoding/thrift/thriftrw-plugin-yarpc/internal/tests/common",
FilePath: "common.thrift",
SHA1: "1bd2b34a2289d2767d66eff00fa74778a14a625f",
Raw: rawIDL,
}
const rawIDL = "service EmptyService {}\n\nservice ExtendEmpty extends EmptyService {\n void hello()\n}\n\nservice BaseService {\n bool healthy()\n}\n\nservice ExtendOnly extends BaseService {\n // A service without any functions except inherited ones\n}\n"
// BaseService_Healthy_Args represents the arguments for the BaseService.healthy function.
//
// The arguments for healthy are sent and received over the wire as this struct.
type BaseService_Healthy_Args struct {
}
// ToWire translates a BaseService_Healthy_Args struct into a Thrift-level intermediate
// representation. This intermediate representation may be serialized
// into bytes using a ThriftRW protocol implementation.
//
// An error is returned if the struct or any of its fields failed to
// validate.
//
// x, err := v.ToWire()
// if err != nil {
// return err
// }
//
// if err := binaryProtocol.Encode(x, writer); err != nil {
// return err
// }
func (v *BaseService_Healthy_Args) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
// FromWire deserializes a BaseService_Healthy_Args struct from its Thrift-level
// representation. The Thrift-level representation may be obtained
// from a ThriftRW protocol implementation.
//
// An error is returned if we were unable to build a BaseService_Healthy_Args struct
// from the provided intermediate representation.
//
// x, err := binaryProtocol.Decode(reader, wire.TStruct)
// if err != nil {
// return nil, err
// }
//
// var v BaseService_Healthy_Args
// if err := v.FromWire(x); err != nil {
// return nil, err
// }
// return &v, nil
func (v *BaseService_Healthy_Args) FromWire(w wire.Value) error {
for _, field := range w.GetStruct().Fields {
switch field.ID {
}
}
return nil
}
// String returns a readable string representation of a BaseService_Healthy_Args
// struct.
func (v *BaseService_Healthy_Args) String() string {
if v == nil {
return "<nil>"
}
var fields [0]string
i := 0
return fmt.Sprintf("BaseService_Healthy_Args{%v}", strings.Join(fields[:i], ", "))
}
// Equals returns true if all the fields of this BaseService_Healthy_Args match the
// provided BaseService_Healthy_Args.
//
// This function performs a deep comparison.
func (v *BaseService_Healthy_Args) Equals(rhs *BaseService_Healthy_Args) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
return true
}
// MarshalLogObject implements zapcore.ObjectMarshaler, enabling
// fast logging of BaseService_Healthy_Args.
func (v *BaseService_Healthy_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
return err
}
// MethodName returns the name of the Thrift function as specified in
// the IDL, for which this struct represent the arguments.
//
// This will always be "healthy" for this struct.
func (v *BaseService_Healthy_Args) MethodName() string {
return "healthy"
}
// EnvelopeType returns the kind of value inside this struct.
//
// This will always be Call for this struct.
func (v *BaseService_Healthy_Args) EnvelopeType() wire.EnvelopeType {
return wire.Call
}
// BaseService_Healthy_Helper provides functions that aid in handling the
// parameters and return values of the BaseService.healthy
// function.
var BaseService_Healthy_Helper = struct {
// Args accepts the parameters of healthy in-order and returns
// the arguments struct for the function.
Args func() *BaseService_Healthy_Args
// IsException returns true if the given error can be thrown
// by healthy.
//
// An error can be thrown by healthy only if the
// corresponding exception type was mentioned in the 'throws'
// section for it in the Thrift file.
IsException func(error) bool
// WrapResponse returns the result struct for healthy
// given its return value and error.
//
// This allows mapping values and errors returned by
// healthy into a serializable result struct.
// WrapResponse returns a non-nil error if the provided
// error cannot be thrown by healthy
//
// value, err := healthy(args)
// result, err := BaseService_Healthy_Helper.WrapResponse(value, err)
// if err != nil {
// return fmt.Errorf("unexpected error from healthy: %v", err)
// }
// serialize(result)
WrapResponse func(bool, error) (*BaseService_Healthy_Result, error)
// UnwrapResponse takes the result struct for healthy
// and returns the value or error returned by it.
//
// The error is non-nil only if healthy threw an
// exception.
//
// result := deserialize(bytes)
// value, err := BaseService_Healthy_Helper.UnwrapResponse(result)
UnwrapResponse func(*BaseService_Healthy_Result) (bool, error)
}{}
func init() {
BaseService_Healthy_Helper.Args = func() *BaseService_Healthy_Args {
return &BaseService_Healthy_Args{}
}
BaseService_Healthy_Helper.IsException = func(err error) bool {
switch err.(type) {
default:
return false
}
}
BaseService_Healthy_Helper.WrapResponse = func(success bool, err error) (*BaseService_Healthy_Result, error) {
if err == nil {
return &BaseService_Healthy_Result{Success: &success}, nil
}
return nil, err
}
BaseService_Healthy_Helper.UnwrapResponse = func(result *BaseService_Healthy_Result) (success bool, err error) {
if result.Success != nil {
success = *result.Success
return
}
err = errors.New("expected a non-void result")
return
}
}
// BaseService_Healthy_Result represents the result of a BaseService.healthy function call.
//
// The result of a healthy execution is sent and received over the wire as this struct.
//
// Success is set only if the function did not throw an exception.
type BaseService_Healthy_Result struct {
// Value returned by healthy after a successful execution.
Success *bool `json:"success,omitempty"`
}
// ToWire translates a BaseService_Healthy_Result struct into a Thrift-level intermediate
// representation. This intermediate representation may be serialized
// into bytes using a ThriftRW protocol implementation.
//
// An error is returned if the struct or any of its fields failed to
// validate.
//
// x, err := v.ToWire()
// if err != nil {
// return err
// }
//
// if err := binaryProtocol.Encode(x, writer); err != nil {
// return err
// }
func (v *BaseService_Healthy_Result) ToWire() (wire.Value, error) {
var (
fields [1]wire.Field
i int = 0
w wire.Value
err error
)
if v.Success != nil {
w, err = wire.NewValueBool(*(v.Success)), error(nil)
if err != nil {
return w, err
}
fields[i] = wire.Field{ID: 0, Value: w}
i++
}
if i != 1 {
return wire.Value{}, fmt.Errorf("BaseService_Healthy_Result should have exactly one field: got %v fields", i)
}
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
// FromWire deserializes a BaseService_Healthy_Result struct from its Thrift-level
// representation. The Thrift-level representation may be obtained
// from a ThriftRW protocol implementation.
//
// An error is returned if we were unable to build a BaseService_Healthy_Result struct
// from the provided intermediate representation.
//
// x, err := binaryProtocol.Decode(reader, wire.TStruct)
// if err != nil {
// return nil, err
// }
//
// var v BaseService_Healthy_Result
// if err := v.FromWire(x); err != nil {
// return nil, err
// }
// return &v, nil
func (v *BaseService_Healthy_Result) FromWire(w wire.Value) error {
var err error
for _, field := range w.GetStruct().Fields {
switch field.ID {
case 0:
if field.Value.Type() == wire.TBool {
var x bool
x, err = field.Value.GetBool(), error(nil)
v.Success = &x
if err != nil {
return err
}
}
}
}
count := 0
if v.Success != nil {
count++
}
if count != 1 {
return fmt.Errorf("BaseService_Healthy_Result should have exactly one field: got %v fields", count)
}
return nil
}
// String returns a readable string representation of a BaseService_Healthy_Result
// struct.
func (v *BaseService_Healthy_Result) String() string {
if v == nil {
return "<nil>"
}
var fields [1]string
i := 0
if v.Success != nil {
fields[i] = fmt.Sprintf("Success: %v", *(v.Success))
i++
}
return fmt.Sprintf("BaseService_Healthy_Result{%v}", strings.Join(fields[:i], ", "))
}
func _Bool_EqualsPtr(lhs, rhs *bool) bool {
if lhs != nil && rhs != nil {
x := *lhs
y := *rhs
return (x == y)
}
return lhs == nil && rhs == nil
}
// Equals returns true if all the fields of this BaseService_Healthy_Result match the
// provided BaseService_Healthy_Result.
//
// This function performs a deep comparison.
func (v *BaseService_Healthy_Result) Equals(rhs *BaseService_Healthy_Result) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
if !_Bool_EqualsPtr(v.Success, rhs.Success) {
return false
}
return true
}
// MarshalLogObject implements zapcore.ObjectMarshaler, enabling
// fast logging of BaseService_Healthy_Result.
func (v *BaseService_Healthy_Result) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
if v.Success != nil {
enc.AddBool("success", *v.Success)
}
return err
}
// GetSuccess returns the value of Success if it is set or its
// zero value if it is unset.
func (v *BaseService_Healthy_Result) GetSuccess() (o bool) {
if v != nil && v.Success != nil {
return *v.Success
}
return
}
// IsSetSuccess returns true if Success is not nil.
func (v *BaseService_Healthy_Result) IsSetSuccess() bool {
return v != nil && v.Success != nil
}
// MethodName returns the name of the Thrift function as specified in
// the IDL, for which this struct represent the result.
//
// This will always be "healthy" for this struct.
func (v *BaseService_Healthy_Result) MethodName() string {
return "healthy"
}
// EnvelopeType returns the kind of value inside this struct.
//
// This will always be Reply for this struct.
func (v *BaseService_Healthy_Result) EnvelopeType() wire.EnvelopeType {
return wire.Reply
}
// ExtendEmpty_Hello_Args represents the arguments for the ExtendEmpty.hello function.
//
// The arguments for hello are sent and received over the wire as this struct.
type ExtendEmpty_Hello_Args struct {
}
// ToWire translates a ExtendEmpty_Hello_Args struct into a Thrift-level intermediate
// representation. This intermediate representation may be serialized
// into bytes using a ThriftRW protocol implementation.
//
// An error is returned if the struct or any of its fields failed to
// validate.
//
// x, err := v.ToWire()
// if err != nil {
// return err
// }
//
// if err := binaryProtocol.Encode(x, writer); err != nil {
// return err
// }
func (v *ExtendEmpty_Hello_Args) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
// FromWire deserializes a ExtendEmpty_Hello_Args struct from its Thrift-level
// representation. The Thrift-level representation may be obtained
// from a ThriftRW protocol implementation.
//
// An error is returned if we were unable to build a ExtendEmpty_Hello_Args struct
// from the provided intermediate representation.
//
// x, err := binaryProtocol.Decode(reader, wire.TStruct)
// if err != nil {
// return nil, err
// }
//
// var v ExtendEmpty_Hello_Args
// if err := v.FromWire(x); err != nil {
// return nil, err
// }
// return &v, nil
func (v *ExtendEmpty_Hello_Args) FromWire(w wire.Value) error {
for _, field := range w.GetStruct().Fields {
switch field.ID {
}
}
return nil
}
// String returns a readable string representation of a ExtendEmpty_Hello_Args
// struct.
func (v *ExtendEmpty_Hello_Args) String() string {
if v == nil {
return "<nil>"
}
var fields [0]string
i := 0
return fmt.Sprintf("ExtendEmpty_Hello_Args{%v}", strings.Join(fields[:i], ", "))
}
// Equals returns true if all the fields of this ExtendEmpty_Hello_Args match the
// provided ExtendEmpty_Hello_Args.
//
// This function performs a deep comparison.
func (v *ExtendEmpty_Hello_Args) Equals(rhs *ExtendEmpty_Hello_Args) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
return true
}
// MarshalLogObject implements zapcore.ObjectMarshaler, enabling
// fast logging of ExtendEmpty_Hello_Args.
func (v *ExtendEmpty_Hello_Args) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
return err
}
// MethodName returns the name of the Thrift function as specified in
// the IDL, for which this struct represent the arguments.
//
// This will always be "hello" for this struct.
func (v *ExtendEmpty_Hello_Args) MethodName() string {
return "hello"
}
// EnvelopeType returns the kind of value inside this struct.
//
// This will always be Call for this struct.
func (v *ExtendEmpty_Hello_Args) EnvelopeType() wire.EnvelopeType {
return wire.Call
}
// ExtendEmpty_Hello_Helper provides functions that aid in handling the
// parameters and return values of the ExtendEmpty.hello
// function.
var ExtendEmpty_Hello_Helper = struct {
// Args accepts the parameters of hello in-order and returns
// the arguments struct for the function.
Args func() *ExtendEmpty_Hello_Args
// IsException returns true if the given error can be thrown
// by hello.
//
// An error can be thrown by hello only if the
// corresponding exception type was mentioned in the 'throws'
// section for it in the Thrift file.
IsException func(error) bool
// WrapResponse returns the result struct for hello
// given the error returned by it. The provided error may
// be nil if hello did not fail.
//
// This allows mapping errors returned by hello into a
// serializable result struct. WrapResponse returns a
// non-nil error if the provided error cannot be thrown by
// hello
//
// err := hello(args)
// result, err := ExtendEmpty_Hello_Helper.WrapResponse(err)
// if err != nil {
// return fmt.Errorf("unexpected error from hello: %v", err)
// }
// serialize(result)
WrapResponse func(error) (*ExtendEmpty_Hello_Result, error)
// UnwrapResponse takes the result struct for hello
// and returns the erorr returned by it (if any).
//
// The error is non-nil only if hello threw an
// exception.
//
// result := deserialize(bytes)
// err := ExtendEmpty_Hello_Helper.UnwrapResponse(result)
UnwrapResponse func(*ExtendEmpty_Hello_Result) error
}{}
func init() {
ExtendEmpty_Hello_Helper.Args = func() *ExtendEmpty_Hello_Args {
return &ExtendEmpty_Hello_Args{}
}
ExtendEmpty_Hello_Helper.IsException = func(err error) bool {
switch err.(type) {
default:
return false
}
}
ExtendEmpty_Hello_Helper.WrapResponse = func(err error) (*ExtendEmpty_Hello_Result, error) {
if err == nil {
return &ExtendEmpty_Hello_Result{}, nil
}
return nil, err
}
ExtendEmpty_Hello_Helper.UnwrapResponse = func(result *ExtendEmpty_Hello_Result) (err error) {
return
}
}
// ExtendEmpty_Hello_Result represents the result of a ExtendEmpty.hello function call.
//
// The result of a hello execution is sent and received over the wire as this struct.
type ExtendEmpty_Hello_Result struct {
}
// ToWire translates a ExtendEmpty_Hello_Result struct into a Thrift-level intermediate
// representation. This intermediate representation may be serialized
// into bytes using a ThriftRW protocol implementation.
//
// An error is returned if the struct or any of its fields failed to
// validate.
//
// x, err := v.ToWire()
// if err != nil {
// return err
// }
//
// if err := binaryProtocol.Encode(x, writer); err != nil {
// return err
// }
func (v *ExtendEmpty_Hello_Result) ToWire() (wire.Value, error) {
var (
fields [0]wire.Field
i int = 0
)
return wire.NewValueStruct(wire.Struct{Fields: fields[:i]}), nil
}
// FromWire deserializes a ExtendEmpty_Hello_Result struct from its Thrift-level
// representation. The Thrift-level representation may be obtained
// from a ThriftRW protocol implementation.
//
// An error is returned if we were unable to build a ExtendEmpty_Hello_Result struct
// from the provided intermediate representation.
//
// x, err := binaryProtocol.Decode(reader, wire.TStruct)
// if err != nil {
// return nil, err
// }
//
// var v ExtendEmpty_Hello_Result
// if err := v.FromWire(x); err != nil {
// return nil, err
// }
// return &v, nil
func (v *ExtendEmpty_Hello_Result) FromWire(w wire.Value) error {
for _, field := range w.GetStruct().Fields {
switch field.ID {
}
}
return nil
}
// String returns a readable string representation of a ExtendEmpty_Hello_Result
// struct.
func (v *ExtendEmpty_Hello_Result) String() string {
if v == nil {
return "<nil>"
}
var fields [0]string
i := 0
return fmt.Sprintf("ExtendEmpty_Hello_Result{%v}", strings.Join(fields[:i], ", "))
}
// Equals returns true if all the fields of this ExtendEmpty_Hello_Result match the
// provided ExtendEmpty_Hello_Result.
//
// This function performs a deep comparison.
func (v *ExtendEmpty_Hello_Result) Equals(rhs *ExtendEmpty_Hello_Result) bool {
if v == nil {
return rhs == nil
} else if rhs == nil {
return false
}
return true
}
// MarshalLogObject implements zapcore.ObjectMarshaler, enabling
// fast logging of ExtendEmpty_Hello_Result.
func (v *ExtendEmpty_Hello_Result) MarshalLogObject(enc zapcore.ObjectEncoder) (err error) {
if v == nil {
return nil
}
return err
}
// MethodName returns the name of the Thrift function as specified in
// the IDL, for which this struct represent the result.
//
// This will always be "hello" for this struct.
func (v *ExtendEmpty_Hello_Result) MethodName() string {
return "hello"
}
// EnvelopeType returns the kind of value inside this struct.
//
// This will always be Reply for this struct.
func (v *ExtendEmpty_Hello_Result) EnvelopeType() wire.EnvelopeType {
return wire.Reply
}