blob: 77d593bee855fb4d341e8b26e3176f7f64c8e604 [file] [log] [blame]
// 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.
// Package base is a simple single-file test of vdl functionality.
package base
type (
NamedBool bool
NamedByte byte
NamedUint16 uint16
NamedUint32 uint32
NamedUint64 uint64
NamedInt8 int8
NamedInt16 int16
NamedInt32 int32
NamedInt64 int64
NamedFloat32 float32
NamedFloat64 float64
NamedString string
NamedEnum enum{A;B;C}
NamedArray [2]bool
NamedList []uint32
NamedSet set[string]
NamedMap map[string]float32
NamedStruct struct{A bool;B string;C int32}
NamedUnion union{A bool;B string;C int32}
)
type Scalars struct {
A0 bool
A1 byte
A2 uint16
A3 uint32
A4 uint64
A5 int8
A6 int16
A7 int32
A8 int64
A9 float32
A10 float64
A11 string
A12 error
A13 any
A14 typeobject
B0 NamedBool
B1 NamedByte
B2 NamedUint16
B3 NamedUint32
B4 NamedUint64
B5 NamedInt8
B6 NamedInt16
B7 NamedInt32
B8 NamedInt64
B9 NamedFloat32
B10 NamedFloat64
B11 NamedString
B12 NamedEnum
B13 NamedUnion
}
// These are all scalars that may be used as map or set keys.
type KeyScalars struct {
A0 bool
A1 byte
A2 uint16
A3 uint32
A4 uint64
A5 int8
A6 int16
A7 int32
A8 int64
A9 float32
A10 float64
A11 string
B0 NamedBool
B1 NamedByte
B2 NamedUint16
B3 NamedUint32
B4 NamedUint64
B5 NamedInt8
B6 NamedInt16
B7 NamedInt32
B8 NamedInt64
B9 NamedFloat32
B10 NamedFloat64
B13 NamedString
}
type ScalarsArray [2]Scalars
type Composites struct {
A0 Scalars
A1 ScalarsArray
A2 []Scalars
A3 set[KeyScalars]
A4 map[string]Scalars
}
type CompositesArray [2]Composites
type CompComp struct {
A0 Composites
A1 CompositesArray
A2 []Composites
A3 map[string]Composites
A4 map[KeyScalars][]map[string]Composites
}
// NestedArgs is defined before Args; that's allowed in regular Go, and also
// allowed in our vdl files. The compiler will re-order dependent types to ease
// code generation in other languages.
type NestedArgs struct {
Args Args
}
// Args will be reordered to show up before NestedArgs in the generated output.
type Args struct {
A int32
B int32
}
const (
Cbool = true
Cbyte = byte(1)
Cint32 = int32(2)
Cint64 = int64(3)
Cuint32 = uint32(4)
Cuint64 = uint64(5)
Cfloat32 = float32(6)
Cfloat64 = float64(7)
CNamedBool = NamedBool(true)
CNamedStruct = NamedStruct{A:true, B: "test",}
Cstring = "foo"
Cenum = NamedEnum.A
Cunion = NamedUnion{A: true}
Carray = NamedArray{true, false}
Clist = []int32{1, 2, 3}
Cset = set[int32]{1, 2, 3}
cmap = map[int32]string{1: "A", 2: "B", 3: "C"}
Cargs = Args{1, 2}
CScalars = Scalars{
A0: true,
A1: 1,
A2: 2,
A3: 3,
A4: 4,
A5: 5,
A6: 6,
A7: 7,
A8: 8,
A9: 9,
A10: 10,
A11: "abc",
A13: false,
A14: typeobject(bool),
B0: true,
B1: 1,
B2: 2,
B3: 3,
B4: 4,
B5: 5,
B6: 6,
B7: 7,
B8: 8,
B9: 9,
B10: 10,
B11: "abc",
B12: NamedEnum.B,
B13: NamedUnion{C: 123},
}
True = true
Foo = "foo"
Five = int32(5)
SixSquared = Six*Six
FiveSquared = Five*Five
Six = uint64(6)
CTypeObject_bool = typeobject(bool)
CTypeObject_string = typeobject(string)
CTypeObject_bytes = typeobject([]byte)
CTypeObject_byte = typeobject(byte)
CTypeObject_uint16 = typeobject(uint16)
CTypeObject_int8 = typeobject(int8)
CTypeObject_int16 = typeobject(int16)
CTypeObject_float32 = typeobject(float32)
CTypeObject_enum = typeobject(NamedEnum)
CTypeObject_Array = typeobject(NamedArray)
CTypeObject_List = typeobject([]string)
CTypeObject_Set = typeobject(set[string])
CTypeObject_Map = typeobject(map[string]int64)
CTypeObject_Struct = typeobject(Scalars)
CTypeObject_Union = typeobject(NamedUnion)
CTypeObject_TypeObject = typeobject(typeobject)
CTypeObject_Any = typeobject(any)
)
type ServiceA interface {
MethodA1() error
MethodA2(a int32, b string) (s string | error)
MethodA3(a int32) stream<_, Scalars> (s string | error) {"tag", Six}
MethodA4(a int32) stream<int32, string> error
//TODO(bprosnitz) Adding MethodA5 breaks the java test - fix this.
//MethodA5(a error) (b error | error)
}
type ServiceB interface {
ServiceA
MethodB1(a Scalars, b Composites) (c CompComp | error)
}
// Error definitions, which allow stable error-checking across different address
// spaces.
error (
NoParams1() {"en":"en msg"}
NoParams2() {RetryRefetch, "en":"en msg", "fr":"fr msg"}
WithParams1(x string, y int32) {"en":"en x={x} y={y}"}
WithParams2(x string, y int32) {
RetryRefetch,
"en":"en x={x} y={y}",
"fr":"fr y={y} x={x}",
}
//TODO(bprosnitz) Adding WithParams3 breaks the java test - fix this.
//WithParams3(x error) {
// "en":"en x={x}",
//}
notExported(x string, y int32) {"en":"en x={x} y={y}"}
)