/
vdl.vdl.go
323 lines (293 loc) · 7.75 KB
/
vdl.vdl.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
// Copyright 2015 The Vanadium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file was auto-generated by the vanadium vdl tool.
// Package: vdl
//nolint:golint
package vdl
import (
"fmt"
)
var _ = initializeVDL() // Must be first; see initializeVDL comments for details.
// Type definitions
// ================
// WireRetryCode is the suggested retry behavior for the receiver of an error.
// If the receiver doesn't know how to handle the specific error, it should
// attempt the suggested retry behavior.
type WireRetryCode int
const (
WireRetryCodeNoRetry WireRetryCode = iota
WireRetryCodeRetryConnection
WireRetryCodeRetryRefetch
WireRetryCodeRetryBackoff
)
// WireRetryCodeAll holds all labels for WireRetryCode.
var WireRetryCodeAll = [...]WireRetryCode{WireRetryCodeNoRetry, WireRetryCodeRetryConnection, WireRetryCodeRetryRefetch, WireRetryCodeRetryBackoff}
// WireRetryCodeFromString creates a WireRetryCode from a string label.
//nolint:deadcode,unused
func WireRetryCodeFromString(label string) (x WireRetryCode, err error) {
err = x.Set(label)
return
}
// Set assigns label to x.
func (x *WireRetryCode) Set(label string) error {
switch label {
case "NoRetry", "noretry":
*x = WireRetryCodeNoRetry
return nil
case "RetryConnection", "retryconnection":
*x = WireRetryCodeRetryConnection
return nil
case "RetryRefetch", "retryrefetch":
*x = WireRetryCodeRetryRefetch
return nil
case "RetryBackoff", "retrybackoff":
*x = WireRetryCodeRetryBackoff
return nil
}
*x = -1
return fmt.Errorf("unknown label %q in vdl.WireRetryCode", label)
}
// String returns the string label of x.
func (x WireRetryCode) String() string {
switch x {
case WireRetryCodeNoRetry:
return "NoRetry"
case WireRetryCodeRetryConnection:
return "RetryConnection"
case WireRetryCodeRetryRefetch:
return "RetryRefetch"
case WireRetryCodeRetryBackoff:
return "RetryBackoff"
}
return ""
}
func (WireRetryCode) VDLReflect(struct {
Name string `vdl:"v.io/v23/vdl.WireRetryCode"`
Enum struct{ NoRetry, RetryConnection, RetryRefetch, RetryBackoff string }
}) {
}
func (x WireRetryCode) VDLIsZero() bool { //nolint:gocyclo
return x == WireRetryCodeNoRetry
}
func (x WireRetryCode) VDLWrite(enc Encoder) error { //nolint:gocyclo
if err := enc.WriteValueString(vdlTypeEnum1, x.String()); err != nil {
return err
}
return nil
}
func (x *WireRetryCode) VDLRead(dec Decoder) error { //nolint:gocyclo
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
if err := x.Set(value); err != nil {
return err
}
}
return nil
}
// WireError is the wire representation for the built-in error type. Errors and
// exceptions in each programming environment are converted to this type to
// ensure wire compatibility. Generated code for each environment provides
// automatic conversions into idiomatic native representations.
type WireError struct {
Id string // Error Id, used to uniquely identify each error.
RetryCode WireRetryCode // Retry behavior suggested for the receiver.
Msg string // Error message, may be empty.
ParamList []*Value // Variadic parameters contained in the error.
}
func (WireError) VDLReflect(struct {
Name string `vdl:"v.io/v23/vdl.WireError"`
}) {
}
func (x WireError) VDLIsZero() bool { //nolint:gocyclo
if x.Id != "" {
return false
}
if x.RetryCode != WireRetryCodeNoRetry {
return false
}
if x.Msg != "" {
return false
}
if len(x.ParamList) != 0 {
return false
}
return true
}
func (x WireError) VDLWrite(enc Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct2); err != nil {
return err
}
if x.Id != "" {
if err := enc.NextFieldValueString(0, StringType, x.Id); err != nil {
return err
}
}
if x.RetryCode != WireRetryCodeNoRetry {
if err := enc.NextFieldValueString(1, vdlTypeEnum1, x.RetryCode.String()); err != nil {
return err
}
}
if x.Msg != "" {
if err := enc.NextFieldValueString(2, StringType, x.Msg); err != nil {
return err
}
}
if len(x.ParamList) != 0 {
if err := enc.NextField(3); err != nil {
return err
}
if err := vdlWriteAnonList1(enc, x.ParamList); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonList1(enc Encoder, x []*Value) error {
if err := enc.StartValue(vdlTypeList3); err != nil {
return err
}
if err := enc.SetLenHint(len(x)); err != nil {
return err
}
for _, elem := range x {
if err := enc.NextEntry(false); err != nil {
return err
}
if elem == nil {
if err := enc.NilValue(AnyType); err != nil {
return err
}
} else {
if err := elem.VDLWrite(enc); err != nil {
return err
}
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func (x *WireError) VDLRead(dec Decoder) error { //nolint:gocyclo
*x = WireError{}
if err := dec.StartValue(vdlTypeStruct2); err != nil {
return err
}
decType := dec.Type()
for {
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return dec.FinishValue()
}
if decType != vdlTypeStruct2 {
index = vdlTypeStruct2.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Id = value
}
case 1:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
if err := x.RetryCode.Set(value); err != nil {
return err
}
}
case 2:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Msg = value
}
case 3:
if err := vdlReadAnonList1(dec, &x.ParamList); err != nil {
return err
}
}
}
}
func vdlReadAnonList1(dec Decoder, x *[]*Value) error {
if err := dec.StartValue(vdlTypeList3); err != nil {
return err
}
if len := dec.LenHint(); len > 0 {
*x = make([]*Value, 0, len)
} else {
*x = nil
}
for {
switch done, err := dec.NextEntry(); {
case err != nil:
return err
case done:
return dec.FinishValue()
default:
var elem *Value
elem = new(Value)
if err := elem.VDLRead(dec); err != nil {
return err
}
*x = append(*x, elem)
}
}
}
// Type-check native conversion functions.
var ()
// Hold type definitions in package-level variables, for better performance.
//nolint:unused
var (
vdlTypeEnum1 *Type
vdlTypeStruct2 *Type
vdlTypeList3 *Type
)
var initializeVDLCalled bool
// initializeVDL performs vdl initialization. It is safe to call multiple times.
// If you have an init ordering issue, just insert the following line verbatim
// into your source files in this package, right after the "package foo" clause:
//
// var _ = initializeVDL()
//
// The purpose of this function is to ensure that vdl initialization occurs in
// the right order, and very early in the init sequence. In particular, vdl
// registration and package variable initialization needs to occur before
// functions like vdl.TypeOf will work properly.
//
// This function returns a dummy value, so that it can be used to initialize the
// first var in the file, to take advantage of Go's defined init order.
func initializeVDL() struct{} {
if initializeVDLCalled {
return struct{}{}
}
initializeVDLCalled = true
// Register native type conversions first, so that vdl.TypeOf works.
// Register types.
Register((*WireRetryCode)(nil))
Register((*WireError)(nil))
// Initialize type definitions.
vdlTypeEnum1 = TypeOf((*WireRetryCode)(nil))
vdlTypeStruct2 = TypeOf((*WireError)(nil)).Elem()
vdlTypeList3 = TypeOf((*[]*Value)(nil))
return struct{}{}
}