-
Notifications
You must be signed in to change notification settings - Fork 28
/
serialization.vdl.go
277 lines (249 loc) · 7.36 KB
/
serialization.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
// 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: serialization
//
//nolint:revive
package serialization
import (
"fmt"
"v.io/v23/security"
"v.io/v23/vdl"
)
var initializeVDLCalled = false
var _ = initializeVDL() // Must be first; see initializeVDL comments for details.
// Hold type definitions in package-level variables, for better performance.
// Declare and initialize with default values here so that the initializeVDL
// method will be considered ready to initialize before any of the type
// definitions that appear below.
//
//nolint:unused
var (
vdlTypeStruct1 *vdl.Type = nil
vdlTypeArray2 *vdl.Type = nil
vdlTypeStruct3 *vdl.Type = nil
vdlTypeUnion4 *vdl.Type = nil
)
// Type definitions
// ================
type SignedHeader struct {
ChunkSizeBytes int64
}
func (SignedHeader) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/lib/security/serialization.SignedHeader"`
}) {
}
func (x SignedHeader) VDLIsZero() bool { //nolint:gocyclo
return x == SignedHeader{}
}
func (x SignedHeader) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct1); err != nil {
return err
}
if x.ChunkSizeBytes != 0 {
if err := enc.NextFieldValueInt(0, vdl.Int64Type, x.ChunkSizeBytes); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *SignedHeader) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = SignedHeader{}
if err := dec.StartValue(vdlTypeStruct1); 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 != vdlTypeStruct1 {
index = vdlTypeStruct1.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
if index == 0 {
switch value, err := dec.ReadValueInt(64); {
case err != nil:
return err
default:
x.ChunkSizeBytes = value
}
}
}
}
type HashCode [32]byte
func (HashCode) VDLReflect(struct {
Name string `vdl:"v.io/x/ref/lib/security/serialization.HashCode"`
}) {
}
func (x HashCode) VDLIsZero() bool { //nolint:gocyclo
return x == HashCode{}
}
func (x HashCode) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.WriteValueBytes(vdlTypeArray2, x[:]); err != nil {
return err
}
return nil
}
func (x *HashCode) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
bytes := x[:]
if err := dec.ReadValueBytes(32, &bytes); err != nil {
return err
}
return nil
}
type (
// SignedData represents any single field of the SignedData union type.
//
// SignedData describes the information sent by a SigningWriter and read by VerifiyingReader.
SignedData interface {
// Index returns the field index.
Index() int
// Interface returns the field value as an interface.
Interface() interface{}
// Name returns the field name.
Name() string
// VDLReflect describes the SignedData union type.
VDLReflect(vdlSignedDataReflect)
VDLIsZero() bool
VDLWrite(vdl.Encoder) error
}
// SignedDataSignature represents field Signature of the SignedData union type.
SignedDataSignature struct{ Value security.Signature }
// SignedDataHash represents field Hash of the SignedData union type.
SignedDataHash struct{ Value HashCode }
// vdlSignedDataReflect describes the SignedData union type.
vdlSignedDataReflect struct {
Name string `vdl:"v.io/x/ref/lib/security/serialization.SignedData"`
Type SignedData
Union struct {
Signature SignedDataSignature
Hash SignedDataHash
}
}
)
func (x SignedDataSignature) Index() int { return 0 }
func (x SignedDataSignature) Interface() interface{} { return x.Value }
func (x SignedDataSignature) Name() string { return "Signature" }
func (x SignedDataSignature) VDLReflect(vdlSignedDataReflect) {}
func (x SignedDataHash) Index() int { return 1 }
func (x SignedDataHash) Interface() interface{} { return x.Value }
func (x SignedDataHash) Name() string { return "Hash" }
func (x SignedDataHash) VDLReflect(vdlSignedDataReflect) {}
func (x SignedDataSignature) VDLIsZero() bool { //nolint:gocyclo
return x.Value.VDLIsZero()
}
func (x SignedDataHash) VDLIsZero() bool {
return false
}
func (x SignedDataSignature) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeUnion4); err != nil {
return err
}
if err := enc.NextField(0); err != nil {
return err
}
if err := x.Value.VDLWrite(enc); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x SignedDataHash) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeUnion4); err != nil {
return err
}
if err := enc.NextFieldValueBytes(1, vdlTypeArray2, x.Value[:]); err != nil {
return err
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func VDLReadSignedData(dec vdl.Decoder, x *SignedData) error { //nolint:gocyclo
if err := dec.StartValue(vdlTypeUnion4); err != nil {
return err
}
decType := dec.Type()
index, err := dec.NextField()
switch {
case err != nil:
return err
case index == -1:
return fmt.Errorf("missing field in union %T, from %v", x, decType)
}
if decType != vdlTypeUnion4 {
name := decType.Field(index).Name
index = vdlTypeUnion4.FieldIndexByName(name)
if index == -1 {
return fmt.Errorf("field %q not in union %T, from %v", name, x, decType)
}
}
switch index {
case 0:
var field SignedDataSignature
if err := field.Value.VDLRead(dec); err != nil {
return err
}
*x = field
case 1:
var field SignedDataHash
bytes := field.Value[:]
if err := dec.ReadValueBytes(32, &bytes); err != nil {
return err
}
*x = field
}
switch index, err := dec.NextField(); {
case err != nil:
return err
case index != -1:
return fmt.Errorf("extra field %d in union %T, from %v", index, x, dec.Type())
}
return dec.FinishValue()
}
// 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 types.
vdl.Register((*SignedHeader)(nil))
vdl.Register((*HashCode)(nil))
vdl.Register((*SignedData)(nil))
// Initialize type definitions.
vdlTypeStruct1 = vdl.TypeOf((*SignedHeader)(nil)).Elem()
vdlTypeArray2 = vdl.TypeOf((*HashCode)(nil))
vdlTypeStruct3 = vdl.TypeOf((*security.Signature)(nil)).Elem()
vdlTypeUnion4 = vdl.TypeOf((*SignedData)(nil))
return struct{}{}
}