blob: aa037327b50d11dc3f990aa8e32b7ead374649b8 [file] [log] [blame]
// Copyright 2018 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
library bindingstest;
using zx;
type TestSimple = struct {
x int64;
};
type TestSimpleBool = struct {
x bool;
};
type TestAlignment1 = struct {
x int8;
y int8;
z uint32;
};
type TestAlignment2 = struct {
a uint32;
b uint32;
c int8;
d int8;
e int8;
f uint8;
g uint32;
h uint16;
i uint16;
};
type TestFloat1 = struct {
a float32;
};
type TestFloat2 = struct {
a float64;
};
type TestFloat3 = struct {
a float32;
b float64;
c uint64;
d float32;
};
type TestArray1 = struct {
a array<int8, 5>;
};
type TestArray2 = struct {
a float64;
b array<float32, 1>;
};
type TestArray3 = struct {
a int32;
b array<uint16, 3>;
c uint64;
};
type TestArray4 = struct {
a array<bool, 9>;
};
type TestString1 = struct {
a string;
b string:optional;
};
type TestString2 = struct {
a array<string, 2>;
};
type TestString3 = struct {
a array<string:4, 2>;
b array<string:<4, optional>, 2>;
};
type TestStringWithBound = struct {
a string:8;
};
type TestOptStringWithBound = struct {
a string:<8, optional>;
};
type TestVector1 = struct {
a vector<int8>;
b vector<int16>:optional;
c vector<int32>:2;
d vector<int64>:<2, optional>;
};
type TestVector2 = struct {
a array<vector<int8>, 2>;
b vector<vector<int8>>:2;
c vector<vector<string:5>:<2, optional>>:2;
};
type TestStruct1 = struct {
a TestSimple;
b box<TestSimple>;
};
type TestStruct2 = struct {
a TestArray1;
b TestFloat1;
c TestVector1;
d box<TestString1>;
};
type EmptyStruct = struct {};
type TestRecursiveStruct = struct {
s box<TestRecursiveStruct>;
};
type TestRecursiveVectorStruct = struct {
v vector<box<TestRecursiveVectorStruct>>;
};
type TestRecursiveVectorUnion = flexible union {
1: a float32;
2: b vector<TestRecursiveVectorUnion:optional>;
};
type TestRecursiveUnionStruct = struct {
u TestRecursiveVectorUnion:optional;
};
type Union1 = strict union {
1: a array<int8, 3>;
2: b TestSimple;
3: d float32;
};
type TestUnion1 = struct {
a Union1;
b Union1:optional;
};
type TestUnion2 = struct {
a vector<Union1>;
b vector<Union1:optional>;
};
type XUnion1 = flexible union {
1: a array<int8, 3>;
2: b TestSimple;
3: d float32;
};
type XUnion1Struct = struct {
xu XUnion1;
};
type XUnion1AsUnion = strict union {
1: a array<int8, 3>;
2: b TestSimple;
3: d float32;
};
type XUnion1AsUnionStruct = struct {
xuau XUnion1AsUnion;
};
type UnionInsideUnion = strict union {
1: a float32;
2: b XUnion1AsUnion;
};
type UnionInsideUnionStruct = struct {
u UnionInsideUnion;
};
type XUnionInsideXUnion = flexible union {
1: a float32;
2: b XUnion1;
};
type XUnionInsideXUnionStruct = struct {
u XUnionInsideXUnion;
};
type TestXUnion1 = struct {
a XUnion1;
b XUnion1:optional;
};
type TestXUnion2 = struct {
a vector<XUnion1>;
b vector<XUnion1:optional>;
};
type StrictXUnion1 = strict union {
1: a array<int8, 3>;
2: b TestSimple;
3: d float32;
};
type StrictXUnion1Struct = struct {
xu StrictXUnion1;
};
type TestStrictXUnion1 = struct {
a StrictXUnion1;
b StrictXUnion1:optional;
};
type TestStrictXUnion2 = struct {
a vector<StrictXUnion1>;
b vector<StrictXUnion1:optional>;
};
type TestHandle1 = resource struct {
a zx.handle;
b zx.handle:optional;
c zx.handle:VMO;
d zx.handle:<VMO, optional>;
};
type TestHandle2 = resource struct {
a vector<zx.handle>:1;
b vector<zx.handle:<VMO, optional>>:1;
};
protocol Test1 {
Echo(struct {
in string:optional;
}) -> (struct {
out string:optional;
});
NoResponse();
EmptyResponse() -> ();
-> Surprise(struct {
foo string;
});
EchoHandleRights(resource struct {
h zx.handle:<PORT, zx.rights.READ | zx.rights.TRANSFER | zx.rights.DUPLICATE>;
}) -> (struct {
rights uint32;
});
};
protocol ExampleProtocol {};
type HasClientEnd = resource struct {
client_end client_end:ExampleProtocol;
};
type HasServerEnd = resource struct {
server_end server_end:ExampleProtocol;
};
type TestInterface1 = resource struct {
a client_end:Test1;
b client_end:<Test1, optional>;
c server_end:Test1;
d server_end:<Test1, optional>;
};
type SimpleTable = table {
1: x int64;
2: reserved;
3: reserved;
4: reserved;
5: y int64;
};
type TestSimpleTable = struct {
table SimpleTable;
};
// A variant of SimpleTable that has just the first few fields.
// Think of this as an older variant of that type!
type OlderSimpleTable = table {
1: x int64;
2: reserved;
};
type TestOlderSimpleTable = struct {
table OlderSimpleTable;
};
// A variant of SimpleTable that has some additional new fields.
// Think of this as an newer variant of that type!
type NewerSimpleTable = table {
1: x int64;
2: reserved;
3: reserved;
4: reserved;
5: y int64;
6: z int64;
7: reserved;
};
type TestNewerSimpleTable = struct {
table NewerSimpleTable;
};
type TestWithTableAndInt = struct {
table SimpleTable;
foo uint64;
};
type SimpleUnion = strict union {
1: i32 int32;
2: i64 int64;
3: s Int64Struct;
4: str string;
};
type Int64Struct = struct {
x int64;
};
// examples from fuchsia world.
const kMaxBuf uint64 = 8192;
type TestFuchsiaIoReadAtResponse = struct {
s zx.status;
data vector<uint8>:kMaxBuf;
};
type TestFuchsiaIoWriteAtRequest = struct {
data vector<uint8>:kMaxBuf;
offset uint64;
};
type TestFuchsiaPosixSocketSendMsgRequest = struct {
sockaddr bytes:128;
data vector<bytes>:MAX;
control bytes;
flags int16;
};
protocol EthernetDevice {};
type InterfaceConfig = struct {
name string;
ip_address_config IpAddressConfig;
};
type IpAddressConfig = strict union {
1: padding_size_24_align_4 array<uint32, 6>;
2: dhcp bool;
};
type TestAddEthernetDeviceRequest = resource struct {
topological_path string;
config InterfaceConfig;
device client_end:EthernetDevice;
};
type TestPackageResolverResolveRequest = resource struct {
package_url string;
selectors vector<string>;
update_policy UpdatePolicy;
dir server_end:EthernetDevice;
};
type UpdatePolicy = struct {
fetch_if_absent bool;
allow_old_versions bool;
};
type TestUcharEnum = strict enum : uint8 {
UcharEnum1 = 1;
UcharEnum2 = 2;
};
// TODO(pascallouis): Move to GIDL
type TestUcharEnumVec = struct {
values vector<TestUcharEnum>:10;
};
type HandleRightsSubtypeTestStruct = resource struct {
h vector<zx.handle:<VMO, zx.rights.DUPLICATE | zx.rights.TRANSFER>>;
};
type PlainHandleTestStruct = resource struct {
h zx.handle;
};
type StrictBits = strict bits {
ONE = 0b01;
TWO = 0b10;
};
type FlexibleBits = flexible bits {
ONE = 0b01;
TWO = 0b10;
};