-
Notifications
You must be signed in to change notification settings - Fork 28
/
vdltool.vdl.go
1600 lines (1503 loc) · 39 KB
/
vdltool.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
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
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// 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: vdltool
// Package vdltool defines types used by the vdl tool itself, including the
// format of vdl.config files. No packages other than the vdltool command
// line tool and v.io/x/ref/lib/vdl/... packages should use it.
//
//nolint:revive
package vdltool
import (
"fmt"
"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 (
vdlTypeEnum1 *vdl.Type = nil
vdlTypeEnum2 *vdl.Type = nil
vdlTypeEnum3 *vdl.Type = nil
vdlTypeStruct4 *vdl.Type = nil
vdlTypeStruct5 *vdl.Type = nil
vdlTypeStruct6 *vdl.Type = nil
vdlTypeList7 *vdl.Type = nil
vdlTypeStruct8 *vdl.Type = nil
vdlTypeStruct9 *vdl.Type = nil
vdlTypeMap10 *vdl.Type = nil
vdlTypeMap11 *vdl.Type = nil
vdlTypeList12 *vdl.Type = nil
vdlTypeStruct13 *vdl.Type = nil
vdlTypeMap14 *vdl.Type = nil
vdlTypeStruct15 *vdl.Type = nil
vdlTypeStruct16 *vdl.Type = nil
vdlTypeStruct17 *vdl.Type = nil
vdlTypeSet18 *vdl.Type = nil
)
// Type definitions
// ================
// GenLanguage enumerates the known code generation languages.
type GenLanguage int
const (
GenLanguageGo GenLanguage = iota
GenLanguageJava
GenLanguageJavascript
GenLanguageSwift
)
// GenLanguageAll holds all labels for GenLanguage.
var GenLanguageAll = [...]GenLanguage{GenLanguageGo, GenLanguageJava, GenLanguageJavascript, GenLanguageSwift}
// GenLanguageFromString creates a GenLanguage from a string label.
//
//nolint:unused
func GenLanguageFromString(label string) (x GenLanguage, err error) {
err = x.Set(label)
return
}
// Set assigns label to x.
func (x *GenLanguage) Set(label string) error {
switch label {
case "Go", "go":
*x = GenLanguageGo
return nil
case "Java", "java":
*x = GenLanguageJava
return nil
case "Javascript", "javascript":
*x = GenLanguageJavascript
return nil
case "Swift", "swift":
*x = GenLanguageSwift
return nil
}
*x = -1
return fmt.Errorf("unknown label %q in vdltool.GenLanguage", label)
}
// String returns the string label of x.
func (x GenLanguage) String() string {
switch x {
case GenLanguageGo:
return "Go"
case GenLanguageJava:
return "Java"
case GenLanguageJavascript:
return "Javascript"
case GenLanguageSwift:
return "Swift"
}
return ""
}
func (GenLanguage) VDLReflect(struct {
Name string `vdl:"vdltool.GenLanguage"`
Enum struct{ Go, Java, Javascript, Swift string }
}) {
}
func (x GenLanguage) VDLIsZero() bool { //nolint:gocyclo
return x == GenLanguageGo
}
func (x GenLanguage) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.WriteValueString(vdlTypeEnum1, x.String()); err != nil {
return err
}
return nil
}
func (x *GenLanguage) VDLRead(dec vdl.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
}
// GoKind describes the kind of Go type.
type GoKind int
const (
GoKindStruct GoKind = iota
GoKindBool
GoKindNumber
GoKindString
GoKindArray
GoKindSlice
GoKindMap
GoKindPointer
GoKindIface
)
// GoKindAll holds all labels for GoKind.
var GoKindAll = [...]GoKind{GoKindStruct, GoKindBool, GoKindNumber, GoKindString, GoKindArray, GoKindSlice, GoKindMap, GoKindPointer, GoKindIface}
// GoKindFromString creates a GoKind from a string label.
//
//nolint:unused
func GoKindFromString(label string) (x GoKind, err error) {
err = x.Set(label)
return
}
// Set assigns label to x.
func (x *GoKind) Set(label string) error {
switch label {
case "Struct", "struct":
*x = GoKindStruct
return nil
case "Bool", "bool":
*x = GoKindBool
return nil
case "Number", "number":
*x = GoKindNumber
return nil
case "String", "string":
*x = GoKindString
return nil
case "Array", "array":
*x = GoKindArray
return nil
case "Slice", "slice":
*x = GoKindSlice
return nil
case "Map", "map":
*x = GoKindMap
return nil
case "Pointer", "pointer":
*x = GoKindPointer
return nil
case "Iface", "iface":
*x = GoKindIface
return nil
}
*x = -1
return fmt.Errorf("unknown label %q in vdltool.GoKind", label)
}
// String returns the string label of x.
func (x GoKind) String() string {
switch x {
case GoKindStruct:
return "Struct"
case GoKindBool:
return "Bool"
case GoKindNumber:
return "Number"
case GoKindString:
return "String"
case GoKindArray:
return "Array"
case GoKindSlice:
return "Slice"
case GoKindMap:
return "Map"
case GoKindPointer:
return "Pointer"
case GoKindIface:
return "Iface"
}
return ""
}
func (GoKind) VDLReflect(struct {
Name string `vdl:"vdltool.GoKind"`
Enum struct{ Struct, Bool, Number, String, Array, Slice, Map, Pointer, Iface string }
}) {
}
func (x GoKind) VDLIsZero() bool { //nolint:gocyclo
return x == GoKindStruct
}
func (x GoKind) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.WriteValueString(vdlTypeEnum2, x.String()); err != nil {
return err
}
return nil
}
func (x *GoKind) VDLRead(dec vdl.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
}
// GoZeroMode describes the relationship between the Go zero value of the native
// type, and the VDL zero value.
type GoZeroMode int
const (
GoZeroModeUnknown GoZeroMode = iota
GoZeroModeCanonical
GoZeroModeUnique
)
// GoZeroModeAll holds all labels for GoZeroMode.
var GoZeroModeAll = [...]GoZeroMode{GoZeroModeUnknown, GoZeroModeCanonical, GoZeroModeUnique}
// GoZeroModeFromString creates a GoZeroMode from a string label.
//
//nolint:unused
func GoZeroModeFromString(label string) (x GoZeroMode, err error) {
err = x.Set(label)
return
}
// Set assigns label to x.
func (x *GoZeroMode) Set(label string) error {
switch label {
case "Unknown", "unknown":
*x = GoZeroModeUnknown
return nil
case "Canonical", "canonical":
*x = GoZeroModeCanonical
return nil
case "Unique", "unique":
*x = GoZeroModeUnique
return nil
}
*x = -1
return fmt.Errorf("unknown label %q in vdltool.GoZeroMode", label)
}
// String returns the string label of x.
func (x GoZeroMode) String() string {
switch x {
case GoZeroModeUnknown:
return "Unknown"
case GoZeroModeCanonical:
return "Canonical"
case GoZeroModeUnique:
return "Unique"
}
return ""
}
func (GoZeroMode) VDLReflect(struct {
Name string `vdl:"vdltool.GoZeroMode"`
Enum struct{ Unknown, Canonical, Unique string }
}) {
}
func (x GoZeroMode) VDLIsZero() bool { //nolint:gocyclo
return x == GoZeroModeUnknown
}
func (x GoZeroMode) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.WriteValueString(vdlTypeEnum3, x.String()); err != nil {
return err
}
return nil
}
func (x *GoZeroMode) VDLRead(dec vdl.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
}
// GoZero describes Go zero value behavior.
//
// REQUIRED: Either Mode == Unique or IsZero is set. We will not perform
// native/wire conversions to check zero values.
type GoZero struct {
Mode GoZeroMode
// IsZero specifies a field, method or function that returns true iff the
// native value represents the VDL zero value.
//
// If IsZero starts with a dot (.), it is assumed to be a field or method.
// The field type or method return type must be bool. Generated code will
// apply the IsZero string verbatim to expressions of the native type.
//
// If IsZero doesn't start with a dot(.), it is assumed to be a function whose
// return type must be bool. Generated code will call the function with a
// single argument that is an expression of the native type.
//
// TODO(toddw): The function form of IsZero isn't implemented.
IsZero string
}
func (GoZero) VDLReflect(struct {
Name string `vdl:"vdltool.GoZero"`
}) {
}
func (x GoZero) VDLIsZero() bool { //nolint:gocyclo
return x == GoZero{}
}
func (x GoZero) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct4); err != nil {
return err
}
if x.Mode != GoZeroModeUnknown {
if err := enc.NextFieldValueString(0, vdlTypeEnum3, x.Mode.String()); err != nil {
return err
}
}
if x.IsZero != "" {
if err := enc.NextFieldValueString(1, vdl.StringType, x.IsZero); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *GoZero) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = GoZero{}
if err := dec.StartValue(vdlTypeStruct4); 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 != vdlTypeStruct4 {
index = vdlTypeStruct4.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:
if err := x.Mode.Set(value); err != nil {
return err
}
}
case 1:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.IsZero = value
}
}
}
}
// GoImport describes Go import information.
type GoImport struct {
// Path is the package path that uniquely identifies the imported package.
Path string
// Name is the name of the package identified by Path. Due to Go conventions,
// it is typically just the basename of Path, but may be set to something
// different if the imported package doesn't follow Go conventions.
Name string
}
func (GoImport) VDLReflect(struct {
Name string `vdl:"vdltool.GoImport"`
}) {
}
func (x GoImport) VDLIsZero() bool { //nolint:gocyclo
return x == GoImport{}
}
func (x GoImport) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct5); err != nil {
return err
}
if x.Path != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.Path); err != nil {
return err
}
}
if x.Name != "" {
if err := enc.NextFieldValueString(1, vdl.StringType, x.Name); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *GoImport) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = GoImport{}
if err := dec.StartValue(vdlTypeStruct5); 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 != vdlTypeStruct5 {
index = vdlTypeStruct5.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.Path = value
}
case 1:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Name = value
}
}
}
}
// GoType describes the Go type information associated with a VDL type.
// See v.io/x/ref/lib/vdl/testdata/native for examples.
type GoType struct {
// Kind is the kind of Type.
Kind GoKind
// Type is the Go type to use in generated code, instead of the VDL type.
Type string
// Zero specifies zero value setting and checking behavior.
Zero GoZero
// ToNative and FromNative overrides the names of the native conversion
// functions. If unspecified, the default functions are of the form:
// WireTypeToNative(wire WireType, native *NativeType) error
// WireTypeFromNative(wire *WireType, native NativeType) error
ToNative string
FromNative string
// Imports are the Go imports referenced by the Type, ToNative and FromNative
// fields. In each field, use the standard local package name, and specify
// the import package here. E.g. to specify the native type time.Time:
// GoType{
// Kind: Struct,
// Type: "time.Time",
// Zero: {Mode: Canonical, IsZero: ".IsZero()"},
// Imports: {{Path: "time", Name: "time"}},
// }
Imports []GoImport
}
func (GoType) VDLReflect(struct {
Name string `vdl:"vdltool.GoType"`
}) {
}
func (x GoType) VDLIsZero() bool { //nolint:gocyclo
if x.Kind != GoKindStruct {
return false
}
if x.Type != "" {
return false
}
if x.Zero != (GoZero{}) {
return false
}
if x.ToNative != "" {
return false
}
if x.FromNative != "" {
return false
}
if len(x.Imports) != 0 {
return false
}
return true
}
func (x GoType) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct6); err != nil {
return err
}
if x.Kind != GoKindStruct {
if err := enc.NextFieldValueString(0, vdlTypeEnum2, x.Kind.String()); err != nil {
return err
}
}
if x.Type != "" {
if err := enc.NextFieldValueString(1, vdl.StringType, x.Type); err != nil {
return err
}
}
if x.Zero != (GoZero{}) {
if err := enc.NextField(2); err != nil {
return err
}
if err := x.Zero.VDLWrite(enc); err != nil {
return err
}
}
if x.ToNative != "" {
if err := enc.NextFieldValueString(3, vdl.StringType, x.ToNative); err != nil {
return err
}
}
if x.FromNative != "" {
if err := enc.NextFieldValueString(4, vdl.StringType, x.FromNative); err != nil {
return err
}
}
if len(x.Imports) != 0 {
if err := enc.NextField(5); err != nil {
return err
}
if err := vdlWriteAnonList1(enc, x.Imports); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonList1(enc vdl.Encoder, x []GoImport) error {
if err := enc.StartValue(vdlTypeList7); 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 err := elem.VDLWrite(enc); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func (x *GoType) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = GoType{}
if err := dec.StartValue(vdlTypeStruct6); 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 != vdlTypeStruct6 {
index = vdlTypeStruct6.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:
if err := x.Kind.Set(value); err != nil {
return err
}
}
case 1:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Type = value
}
case 2:
if err := x.Zero.VDLRead(dec); err != nil {
return err
}
case 3:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.ToNative = value
}
case 4:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.FromNative = value
}
case 5:
if err := vdlReadAnonList1(dec, &x.Imports); err != nil {
return err
}
}
}
}
func vdlReadAnonList1(dec vdl.Decoder, x *[]GoImport) error {
if err := dec.StartValue(vdlTypeList7); err != nil {
return err
}
if len := dec.LenHint(); len > 0 {
*x = make([]GoImport, 0, len)
} else {
*x = nil
}
for {
switch done, err := dec.NextEntry(); {
case err != nil:
return err
case done:
return dec.FinishValue()
default:
var elem GoImport
if err := elem.VDLRead(dec); err != nil {
return err
}
*x = append(*x, elem)
}
}
}
// GoStructTag specifies a single go struct tag and the field to which it
// should be applied.
type GoStructTag struct {
Field string
Tag string
}
func (GoStructTag) VDLReflect(struct {
Name string `vdl:"vdltool.GoStructTag"`
}) {
}
func (x GoStructTag) VDLIsZero() bool { //nolint:gocyclo
return x == GoStructTag{}
}
func (x GoStructTag) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct8); err != nil {
return err
}
if x.Field != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.Field); err != nil {
return err
}
}
if x.Tag != "" {
if err := enc.NextFieldValueString(1, vdl.StringType, x.Tag); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *GoStructTag) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = GoStructTag{}
if err := dec.StartValue(vdlTypeStruct8); 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 != vdlTypeStruct8 {
index = vdlTypeStruct8.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.Field = value
}
case 1:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Tag = value
}
}
}
}
// GoConfig specifies go specific configuration.
type GoConfig struct {
// WireToNativeTypes specifies the mapping from a VDL wire type to its Go
// native type representation. This is rarely used and easy to configure
// incorrectly; usage is currently restricted to packages that are explicitly
// whitelisted.
//
// WireToNativeTypes are meant for scenarios where there is an idiomatic Go
// type used in your code, but you need a standard VDL representation for wire
// compatibility. E.g. the VDL time package defines Duration and Time for
// wire compatibility, but we want the generated code to use the standard Go
// time package.
//
// The key of the map is the name of the VDL type (aka WireType), which must
// be defined in the vdl package associated with the vdl.config file.
//
// The code generator assumes the existence of a pair of conversion functions
// converting between the wire and native types, and will automatically call
// vdl.RegisterNative with these function names.
//
// Assuming the name of the WireType is Foo:
// func fooToNative(x Foo, n *Native) error
// func fooFromNative(x *Foo, n Native) error
WireToNativeTypes map[string]GoType
// StructTags specifies any go struct tags to be include with the generated
// go code. The StructTags map is keyed by the struct type's name.
StructTags map[string][]GoStructTag
}
func (GoConfig) VDLReflect(struct {
Name string `vdl:"vdltool.GoConfig"`
}) {
}
func (x GoConfig) VDLIsZero() bool { //nolint:gocyclo
if len(x.WireToNativeTypes) != 0 {
return false
}
if len(x.StructTags) != 0 {
return false
}
return true
}
func (x GoConfig) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.StartValue(vdlTypeStruct9); err != nil {
return err
}
if len(x.WireToNativeTypes) != 0 {
if err := enc.NextField(0); err != nil {
return err
}
if err := vdlWriteAnonMap2(enc, x.WireToNativeTypes); err != nil {
return err
}
}
if len(x.StructTags) != 0 {
if err := enc.NextField(1); err != nil {
return err
}
if err := vdlWriteAnonMap3(enc, x.StructTags); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonMap2(enc vdl.Encoder, x map[string]GoType) error {
if err := enc.StartValue(vdlTypeMap10); err != nil {
return err
}
if err := enc.SetLenHint(len(x)); err != nil {
return err
}
for key, elem := range x {
if err := enc.NextEntryValueString(vdl.StringType, key); err != nil {
return err
}
if err := elem.VDLWrite(enc); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonMap3(enc vdl.Encoder, x map[string][]GoStructTag) error {
if err := enc.StartValue(vdlTypeMap11); err != nil {
return err
}
if err := enc.SetLenHint(len(x)); err != nil {
return err
}
for key, elem := range x {
if err := enc.NextEntryValueString(vdl.StringType, key); err != nil {
return err
}
if err := vdlWriteAnonList4(enc, elem); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func vdlWriteAnonList4(enc vdl.Encoder, x []GoStructTag) error {
if err := enc.StartValue(vdlTypeList12); 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 err := elem.VDLWrite(enc); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func (x *GoConfig) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
*x = GoConfig{}
if err := dec.StartValue(vdlTypeStruct9); 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 != vdlTypeStruct9 {
index = vdlTypeStruct9.FieldIndexByName(decType.Field(index).Name)
if index == -1 {
if err := dec.SkipValue(); err != nil {
return err
}
continue
}
}
switch index {
case 0:
if err := vdlReadAnonMap2(dec, &x.WireToNativeTypes); err != nil {
return err
}
case 1:
if err := vdlReadAnonMap3(dec, &x.StructTags); err != nil {
return err
}
}
}
}
func vdlReadAnonMap2(dec vdl.Decoder, x *map[string]GoType) error {
if err := dec.StartValue(vdlTypeMap10); err != nil {
return err
}
var tmpMap map[string]GoType
if len := dec.LenHint(); len > 0 {
tmpMap = make(map[string]GoType, len)
}
for {
switch done, key, err := dec.NextEntryValueString(); {
case err != nil:
return err
case done:
*x = tmpMap
return dec.FinishValue()
default:
var elem GoType
if err := elem.VDLRead(dec); err != nil {
return err
}
if tmpMap == nil {
tmpMap = make(map[string]GoType)
}
tmpMap[key] = elem
}
}
}
func vdlReadAnonMap3(dec vdl.Decoder, x *map[string][]GoStructTag) error {
if err := dec.StartValue(vdlTypeMap11); err != nil {
return err
}
var tmpMap map[string][]GoStructTag
if len := dec.LenHint(); len > 0 {
tmpMap = make(map[string][]GoStructTag, len)