-
Notifications
You must be signed in to change notification settings - Fork 28
/
http.vdl.go
711 lines (670 loc) · 16 KB
/
http.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
// Copyright 2016 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: http
// Package HTTP defines an interface to send a http.Request from a client to a
// Vanadium server. This code is Go-specific since it is only used internally
// by Vanadium.
package http
import (
"v.io/v23"
"v.io/v23/context"
"v.io/v23/rpc"
"v.io/v23/security/access"
"v.io/v23/vdl"
)
var _ = __VDLInit() // Must be first; see __VDLInit comments for details.
//////////////////////////////////////////////////
// Type definitions
// Url represents a url.URL struct.
// The User field is skipped since it is a struct with only unexported fields.
type Url struct {
Scheme string
Opaque string
Host string
Path string
RawPath string
RawQuery string
Fragment string
}
func (Url) VDLReflect(struct {
Name string `vdl:"v.io/v23/services/http.Url"`
}) {
}
func (x Url) VDLIsZero() bool {
return x == Url{}
}
func (x Url) VDLWrite(enc vdl.Encoder) error {
if err := enc.StartValue(__VDLType_struct_1); err != nil {
return err
}
if x.Scheme != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.Scheme); err != nil {
return err
}
}
if x.Opaque != "" {
if err := enc.NextFieldValueString(1, vdl.StringType, x.Opaque); err != nil {
return err
}
}
if x.Host != "" {
if err := enc.NextFieldValueString(2, vdl.StringType, x.Host); err != nil {
return err
}
}
if x.Path != "" {
if err := enc.NextFieldValueString(3, vdl.StringType, x.Path); err != nil {
return err
}
}
if x.RawPath != "" {
if err := enc.NextFieldValueString(4, vdl.StringType, x.RawPath); err != nil {
return err
}
}
if x.RawQuery != "" {
if err := enc.NextFieldValueString(5, vdl.StringType, x.RawQuery); err != nil {
return err
}
}
if x.Fragment != "" {
if err := enc.NextFieldValueString(6, vdl.StringType, x.Fragment); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func (x *Url) VDLRead(dec vdl.Decoder) error {
*x = Url{}
if err := dec.StartValue(__VDLType_struct_1); 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 != __VDLType_struct_1 {
index = __VDLType_struct_1.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.Scheme = value
}
case 1:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Opaque = value
}
case 2:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Host = value
}
case 3:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Path = value
}
case 4:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.RawPath = value
}
case 5:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.RawQuery = value
}
case 6:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Fragment = value
}
}
}
}
// Request represents the http.Request struct. The MultipartForm field is
// skipped since the docs indicate that it is ignored by clients in favor of
// the Body field.
type Request struct {
Method string
Url Url
Proto string
ProtoMajor int16
ProtoMinor int16
Header map[string][]string
Body []byte
ContentLength int64
TransferEncoding []string
Close bool
Host string
Form map[string][]string
PostForm map[string][]string
Trailer map[string][]string
RemoteAddr string
RequestUri string
}
func (Request) VDLReflect(struct {
Name string `vdl:"v.io/v23/services/http.Request"`
}) {
}
func (x Request) VDLIsZero() bool {
if x.Method != "" {
return false
}
if x.Url != (Url{}) {
return false
}
if x.Proto != "" {
return false
}
if x.ProtoMajor != 0 {
return false
}
if x.ProtoMinor != 0 {
return false
}
if len(x.Header) != 0 {
return false
}
if len(x.Body) != 0 {
return false
}
if x.ContentLength != 0 {
return false
}
if len(x.TransferEncoding) != 0 {
return false
}
if x.Close {
return false
}
if x.Host != "" {
return false
}
if len(x.Form) != 0 {
return false
}
if len(x.PostForm) != 0 {
return false
}
if len(x.Trailer) != 0 {
return false
}
if x.RemoteAddr != "" {
return false
}
if x.RequestUri != "" {
return false
}
return true
}
func (x Request) VDLWrite(enc vdl.Encoder) error {
if err := enc.StartValue(__VDLType_struct_2); err != nil {
return err
}
if x.Method != "" {
if err := enc.NextFieldValueString(0, vdl.StringType, x.Method); err != nil {
return err
}
}
if x.Url != (Url{}) {
if err := enc.NextField(1); err != nil {
return err
}
if err := x.Url.VDLWrite(enc); err != nil {
return err
}
}
if x.Proto != "" {
if err := enc.NextFieldValueString(2, vdl.StringType, x.Proto); err != nil {
return err
}
}
if x.ProtoMajor != 0 {
if err := enc.NextFieldValueInt(3, vdl.Int16Type, int64(x.ProtoMajor)); err != nil {
return err
}
}
if x.ProtoMinor != 0 {
if err := enc.NextFieldValueInt(4, vdl.Int16Type, int64(x.ProtoMinor)); err != nil {
return err
}
}
if len(x.Header) != 0 {
if err := enc.NextField(5); err != nil {
return err
}
if err := __VDLWriteAnon_map_1(enc, x.Header); err != nil {
return err
}
}
if len(x.Body) != 0 {
if err := enc.NextFieldValueBytes(6, __VDLType_list_4, x.Body); err != nil {
return err
}
}
if x.ContentLength != 0 {
if err := enc.NextFieldValueInt(7, vdl.Int64Type, x.ContentLength); err != nil {
return err
}
}
if len(x.TransferEncoding) != 0 {
if err := enc.NextField(8); err != nil {
return err
}
if err := __VDLWriteAnon_list_2(enc, x.TransferEncoding); err != nil {
return err
}
}
if x.Close {
if err := enc.NextFieldValueBool(9, vdl.BoolType, x.Close); err != nil {
return err
}
}
if x.Host != "" {
if err := enc.NextFieldValueString(10, vdl.StringType, x.Host); err != nil {
return err
}
}
if len(x.Form) != 0 {
if err := enc.NextField(11); err != nil {
return err
}
if err := __VDLWriteAnon_map_1(enc, x.Form); err != nil {
return err
}
}
if len(x.PostForm) != 0 {
if err := enc.NextField(12); err != nil {
return err
}
if err := __VDLWriteAnon_map_1(enc, x.PostForm); err != nil {
return err
}
}
if len(x.Trailer) != 0 {
if err := enc.NextField(13); err != nil {
return err
}
if err := __VDLWriteAnon_map_1(enc, x.Trailer); err != nil {
return err
}
}
if x.RemoteAddr != "" {
if err := enc.NextFieldValueString(14, vdl.StringType, x.RemoteAddr); err != nil {
return err
}
}
if x.RequestUri != "" {
if err := enc.NextFieldValueString(15, vdl.StringType, x.RequestUri); err != nil {
return err
}
}
if err := enc.NextField(-1); err != nil {
return err
}
return enc.FinishValue()
}
func __VDLWriteAnon_map_1(enc vdl.Encoder, x map[string][]string) error {
if err := enc.StartValue(__VDLType_map_3); 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 := __VDLWriteAnon_list_2(enc, elem); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func __VDLWriteAnon_list_2(enc vdl.Encoder, x []string) error {
if err := enc.StartValue(__VDLType_list_5); err != nil {
return err
}
if err := enc.SetLenHint(len(x)); err != nil {
return err
}
for _, elem := range x {
if err := enc.NextEntryValueString(vdl.StringType, elem); err != nil {
return err
}
}
if err := enc.NextEntry(true); err != nil {
return err
}
return enc.FinishValue()
}
func (x *Request) VDLRead(dec vdl.Decoder) error {
*x = Request{}
if err := dec.StartValue(__VDLType_struct_2); 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 != __VDLType_struct_2 {
index = __VDLType_struct_2.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.Method = value
}
case 1:
if err := x.Url.VDLRead(dec); err != nil {
return err
}
case 2:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Proto = value
}
case 3:
switch value, err := dec.ReadValueInt(16); {
case err != nil:
return err
default:
x.ProtoMajor = int16(value)
}
case 4:
switch value, err := dec.ReadValueInt(16); {
case err != nil:
return err
default:
x.ProtoMinor = int16(value)
}
case 5:
if err := __VDLReadAnon_map_1(dec, &x.Header); err != nil {
return err
}
case 6:
if err := dec.ReadValueBytes(-1, &x.Body); err != nil {
return err
}
case 7:
switch value, err := dec.ReadValueInt(64); {
case err != nil:
return err
default:
x.ContentLength = value
}
case 8:
if err := __VDLReadAnon_list_2(dec, &x.TransferEncoding); err != nil {
return err
}
case 9:
switch value, err := dec.ReadValueBool(); {
case err != nil:
return err
default:
x.Close = value
}
case 10:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.Host = value
}
case 11:
if err := __VDLReadAnon_map_1(dec, &x.Form); err != nil {
return err
}
case 12:
if err := __VDLReadAnon_map_1(dec, &x.PostForm); err != nil {
return err
}
case 13:
if err := __VDLReadAnon_map_1(dec, &x.Trailer); err != nil {
return err
}
case 14:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.RemoteAddr = value
}
case 15:
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
x.RequestUri = value
}
}
}
}
func __VDLReadAnon_map_1(dec vdl.Decoder, x *map[string][]string) error {
if err := dec.StartValue(__VDLType_map_3); err != nil {
return err
}
var tmpMap map[string][]string
if len := dec.LenHint(); len > 0 {
tmpMap = make(map[string][]string, len)
}
for {
switch done, key, err := dec.NextEntryValueString(); {
case err != nil:
return err
case done:
*x = tmpMap
return dec.FinishValue()
default:
var elem []string
if err := __VDLReadAnon_list_2(dec, &elem); err != nil {
return err
}
if tmpMap == nil {
tmpMap = make(map[string][]string)
}
tmpMap[key] = elem
}
}
}
func __VDLReadAnon_list_2(dec vdl.Decoder, x *[]string) error {
if err := dec.StartValue(__VDLType_list_5); err != nil {
return err
}
if len := dec.LenHint(); len > 0 {
*x = make([]string, 0, len)
} else {
*x = nil
}
for {
switch done, elem, err := dec.NextEntryValueString(); {
case err != nil:
return err
case done:
return dec.FinishValue()
default:
*x = append(*x, elem)
}
}
}
//////////////////////////////////////////////////
// Interface definitions
// HttpClientMethods is the client interface
// containing Http methods.
type HttpClientMethods interface {
// RawDo returns the server's response to req.
RawDo(_ *context.T, req Request, _ ...rpc.CallOpt) (data []byte, _ error)
}
// HttpClientStub adds universal methods to HttpClientMethods.
type HttpClientStub interface {
HttpClientMethods
rpc.UniversalServiceMethods
}
// HttpClient returns a client stub for Http.
func HttpClient(name string) HttpClientStub {
return implHttpClientStub{name}
}
type implHttpClientStub struct {
name string
}
func (c implHttpClientStub) RawDo(ctx *context.T, i0 Request, opts ...rpc.CallOpt) (o0 []byte, err error) {
err = v23.GetClient(ctx).Call(ctx, c.name, "RawDo", []interface{}{i0}, []interface{}{&o0}, opts...)
return
}
// HttpServerMethods is the interface a server writer
// implements for Http.
type HttpServerMethods interface {
// RawDo returns the server's response to req.
RawDo(_ *context.T, _ rpc.ServerCall, req Request) (data []byte, _ error)
}
// HttpServerStubMethods is the server interface containing
// Http methods, as expected by rpc.Server.
// There is no difference between this interface and HttpServerMethods
// since there are no streaming methods.
type HttpServerStubMethods HttpServerMethods
// HttpServerStub adds universal methods to HttpServerStubMethods.
type HttpServerStub interface {
HttpServerStubMethods
// Describe the Http interfaces.
Describe__() []rpc.InterfaceDesc
}
// HttpServer returns a server stub for Http.
// It converts an implementation of HttpServerMethods into
// an object that may be used by rpc.Server.
func HttpServer(impl HttpServerMethods) HttpServerStub {
stub := implHttpServerStub{
impl: impl,
}
// Initialize GlobState; always check the stub itself first, to handle the
// case where the user has the Glob method defined in their VDL source.
if gs := rpc.NewGlobState(stub); gs != nil {
stub.gs = gs
} else if gs := rpc.NewGlobState(impl); gs != nil {
stub.gs = gs
}
return stub
}
type implHttpServerStub struct {
impl HttpServerMethods
gs *rpc.GlobState
}
func (s implHttpServerStub) RawDo(ctx *context.T, call rpc.ServerCall, i0 Request) ([]byte, error) {
return s.impl.RawDo(ctx, call, i0)
}
func (s implHttpServerStub) Globber() *rpc.GlobState {
return s.gs
}
func (s implHttpServerStub) Describe__() []rpc.InterfaceDesc {
return []rpc.InterfaceDesc{HttpDesc}
}
// HttpDesc describes the Http interface.
var HttpDesc rpc.InterfaceDesc = descHttp
// descHttp hides the desc to keep godoc clean.
var descHttp = rpc.InterfaceDesc{
Name: "Http",
PkgPath: "v.io/v23/services/http",
Methods: []rpc.MethodDesc{
{
Name: "RawDo",
Doc: "// RawDo returns the server's response to req.",
InArgs: []rpc.ArgDesc{
{"req", ``}, // Request
},
OutArgs: []rpc.ArgDesc{
{"data", ``}, // []byte
},
Tags: []*vdl.Value{vdl.ValueOf(access.Tag("Debug"))},
},
},
}
// Hold type definitions in package-level variables, for better performance.
var (
__VDLType_struct_1 *vdl.Type
__VDLType_struct_2 *vdl.Type
__VDLType_map_3 *vdl.Type
__VDLType_list_4 *vdl.Type
__VDLType_list_5 *vdl.Type
)
var __VDLInitCalled bool
// __VDLInit 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 _ = __VDLInit()
//
// 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 __VDLInit() struct{} {
if __VDLInitCalled {
return struct{}{}
}
__VDLInitCalled = true
// Register types.
vdl.Register((*Url)(nil))
vdl.Register((*Request)(nil))
// Initialize type definitions.
__VDLType_struct_1 = vdl.TypeOf((*Url)(nil)).Elem()
__VDLType_struct_2 = vdl.TypeOf((*Request)(nil)).Elem()
__VDLType_map_3 = vdl.TypeOf((*map[string][]string)(nil))
__VDLType_list_4 = vdl.TypeOf((*[]byte)(nil))
__VDLType_list_5 = vdl.TypeOf((*[]string)(nil))
return struct{}{}
}