/
internal.vdl.go
244 lines (204 loc) · 6.81 KB
/
internal.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
// 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: internal
// Package internal provides a VDL specification for a service used in the
// unittest of the access package.
//nolint:golint
package internal
import (
v23 "v.io/v23"
"v.io/v23/context"
"v.io/v23/rpc"
"v.io/v23/vdl"
)
var _ = initializeVDL() // Must be first; see initializeVDL comments for details.
// Type definitions
// ================
// Any package can define tags (of arbitrary types) to be attached to methods.
// This type can be used to index into a Permissions.
type MyTag string
func (MyTag) VDLReflect(struct {
Name string `vdl:"v.io/v23/security/access/internal.MyTag"`
}) {
}
func (x MyTag) VDLIsZero() bool { //nolint:gocyclo
return x == ""
}
func (x MyTag) VDLWrite(enc vdl.Encoder) error { //nolint:gocyclo
if err := enc.WriteValueString(vdlTypeString1, string(x)); err != nil {
return err
}
return nil
}
func (x *MyTag) VDLRead(dec vdl.Decoder) error { //nolint:gocyclo
switch value, err := dec.ReadValueString(); {
case err != nil:
return err
default:
*x = MyTag(value)
}
return nil
}
// Const definitions
// =================
// For this example/unittest, there are three possible values of MyTag, each
// represented by a single-character string.
const Read = MyTag("R")
const Write = MyTag("W")
const Execute = MyTag("X")
// Interface definitions
// =====================
// MyObjectClientMethods is the client interface
// containing MyObject methods.
//
// MyObject demonstrates how tags are attached to methods.
type MyObjectClientMethods interface {
Get(*context.T, ...rpc.CallOpt) error
Put(*context.T, ...rpc.CallOpt) error
Resolve(*context.T, ...rpc.CallOpt) error
NoTags(*context.T, ...rpc.CallOpt) error // No tags attached to this.
}
// MyObjectClientStub embeds MyObjectClientMethods and is a
// placeholder for additional management operations.
type MyObjectClientStub interface {
MyObjectClientMethods
}
// MyObjectClient returns a client stub for MyObject.
func MyObjectClient(name string) MyObjectClientStub {
return implMyObjectClientStub{name}
}
type implMyObjectClientStub struct {
name string
}
func (c implMyObjectClientStub) Get(ctx *context.T, opts ...rpc.CallOpt) (err error) {
err = v23.GetClient(ctx).Call(ctx, c.name, "Get", nil, nil, opts...)
return
}
func (c implMyObjectClientStub) Put(ctx *context.T, opts ...rpc.CallOpt) (err error) {
err = v23.GetClient(ctx).Call(ctx, c.name, "Put", nil, nil, opts...)
return
}
func (c implMyObjectClientStub) Resolve(ctx *context.T, opts ...rpc.CallOpt) (err error) {
err = v23.GetClient(ctx).Call(ctx, c.name, "Resolve", nil, nil, opts...)
return
}
func (c implMyObjectClientStub) NoTags(ctx *context.T, opts ...rpc.CallOpt) (err error) {
err = v23.GetClient(ctx).Call(ctx, c.name, "NoTags", nil, nil, opts...)
return
}
// MyObjectServerMethods is the interface a server writer
// implements for MyObject.
//
// MyObject demonstrates how tags are attached to methods.
type MyObjectServerMethods interface {
Get(*context.T, rpc.ServerCall) error
Put(*context.T, rpc.ServerCall) error
Resolve(*context.T, rpc.ServerCall) error
NoTags(*context.T, rpc.ServerCall) error // No tags attached to this.
}
// MyObjectServerStubMethods is the server interface containing
// MyObject methods, as expected by rpc.Server.
// There is no difference between this interface and MyObjectServerMethods
// since there are no streaming methods.
type MyObjectServerStubMethods MyObjectServerMethods
// MyObjectServerStub adds universal methods to MyObjectServerStubMethods.
type MyObjectServerStub interface {
MyObjectServerStubMethods
// DescribeInterfaces the MyObject interfaces.
Describe__() []rpc.InterfaceDesc
}
// MyObjectServer returns a server stub for MyObject.
// It converts an implementation of MyObjectServerMethods into
// an object that may be used by rpc.Server.
func MyObjectServer(impl MyObjectServerMethods) MyObjectServerStub {
stub := implMyObjectServerStub{
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 implMyObjectServerStub struct {
impl MyObjectServerMethods
gs *rpc.GlobState
}
func (s implMyObjectServerStub) Get(ctx *context.T, call rpc.ServerCall) error {
return s.impl.Get(ctx, call)
}
func (s implMyObjectServerStub) Put(ctx *context.T, call rpc.ServerCall) error {
return s.impl.Put(ctx, call)
}
func (s implMyObjectServerStub) Resolve(ctx *context.T, call rpc.ServerCall) error {
return s.impl.Resolve(ctx, call)
}
func (s implMyObjectServerStub) NoTags(ctx *context.T, call rpc.ServerCall) error {
return s.impl.NoTags(ctx, call)
}
func (s implMyObjectServerStub) Globber() *rpc.GlobState {
return s.gs
}
func (s implMyObjectServerStub) Describe__() []rpc.InterfaceDesc {
return []rpc.InterfaceDesc{MyObjectDesc}
}
// MyObjectDesc describes the MyObject interface.
var MyObjectDesc rpc.InterfaceDesc = descMyObject
// descMyObject hides the desc to keep godoc clean.
var descMyObject = rpc.InterfaceDesc{
Name: "MyObject",
PkgPath: "v.io/v23/security/access/internal",
Doc: "// MyObject demonstrates how tags are attached to methods.",
Methods: []rpc.MethodDesc{
{
Name: "Get",
Tags: []*vdl.Value{vdl.ValueOf(MyTag("R"))},
},
{
Name: "Put",
Tags: []*vdl.Value{vdl.ValueOf(MyTag("W"))},
},
{
Name: "Resolve",
Tags: []*vdl.Value{vdl.ValueOf(MyTag("X"))},
},
{
Name: "NoTags",
},
},
}
// Hold type definitions in package-level variables, for better performance.
//nolint:unused
var (
vdlTypeString1 *vdl.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 types.
vdl.Register((*MyTag)(nil))
// Initialize type definitions.
vdlTypeString1 = vdl.TypeOf((*MyTag)(nil))
return struct{}{}
}