blob: 5eac633a57ca25585465e38d68167c07e9822738 [file] [log] [blame]
// Copyright 2019 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// NOTE: Refer to README.md to regenerate the coding tables whenever these
// definitions change.
library example;
union UnionSize8Aligned4 {
1: uint8 unused1; // makes `variant` tagged 2
2: uint8 unused2; // since it is the third
3: uint32 variant; // xunion_ordinal = 0x7fc2f0db
};
union UnionSize12Aligned4 {
1: uint8 unused1; // avoid tag 0
2: uint8 unused2; // avoid tag 1
3: uint8 unused3; // avoid tag 2
4: array<uint8>:6 variant;
};
struct StructSize16Alignment8 {
uint64 f1;
uint64 f2;
};
union UnionSize24Alignment8 {
1: uint8 unused1; // avoid tag 0
2: uint8 unused2; // avoid tag 1
3: uint8 unused3; // avoid tag 2
4: StructSize16Alignment8 variant; // 0x3404559b
};
struct Sandwich1 {
uint32 before;
UnionSize8Aligned4 the_union;
uint32 after;
};
struct Sandwich1WithOptUnion {
uint32 before;
UnionSize8Aligned4? opt_union;
uint32 after;
};
struct Sandwich2 {
uint32 before;
UnionSize12Aligned4 the_union;
uint32 after;
};
struct Sandwich3 {
uint32 before;
UnionSize24Alignment8 the_union;
uint32 after;
};
union UnionSize36Alignment4 {
1: uint8 unused1; // avoid tag 0
2: uint8 unused2; // avoid tag 1
3: uint8 unused3; // avoid tag 2
4: array<uint8>:32 variant; // 0x5e411019
};
union UnionSize8Alignment4 {
1: uint8 unused1; // avoid tag 0
2: uint8 unused2; // avoid tag 1
3: uint8 unused3; // avoid tag 2
4: array<uint8>:4 variant; // TODO: figure out tag
};
struct Sandwich4 {
uint32 before;
UnionSize36Alignment4 the_union;
uint32 after;
};
struct Sandwich4Align8 {
Sandwich4 sandwich4;
uint64 alignment8_enforcement;
};
struct Size8Align8 {
uint64 data;
};
struct Size64Align8 {
array<uint8>:8 data;
};
struct Sandwich4Align8WithPointer {
Sandwich4 sandwich4;
Size8Align8? alignment8_enforcement;
};
struct NoCodingTablesStresssor {
uint64 f1;
uint64 f2;
UnionSize36Alignment4 u1;
uint64 f3;
uint64 f4;
UnionSize36Alignment4 u2;
uint64 f5;
uint64 f6;
UnionSize36Alignment4 u3;
uint64 f7;
Size8Align8? p1;
uint64 f8;
Size8Align8? p2;
uint64 f9;
};
union UnionOfUnion {
1: uint8 unused; // avoid tag 0
2: UnionSize8Aligned4 size8aligned4; // 0x20AADD60
3: UnionSize12Aligned4 size16aligned4; // 0x2D7665CD
4: UnionSize24Alignment8 size24aligned8; // 0x06722D1F
};
struct Sandwich5 {
uint32 before;
UnionOfUnion union_of_union;
uint32 after;
};
struct StructSize3Alignment1 {
array<uint8>:3 three_bytes;
};
struct StructSize3Alignment2 {
uint16 f1;
uint8 f2;
};
// We name Sandwich6 cases by the tag number, i.e. Sandwich6 case 2 is
// testing the `string` variant.
union UnionWithVector {
1: uint8 unused; // 0: unused
2: vector<uint8> vector_of_uint8; // 1: 0x79C3CCAD
3: string string; // 2: 0x3B314338
4: vector<StructSize3Alignment1> vector_s3_a1; // 3: 0x4BC13CDC
5: vector<StructSize3Alignment2> vector_s3_a2; // 4: 0x1D08AA3C
6: vector<handle> handles; // 5: 0x471EAA76
7: array<StructSize3Alignment1>:2 array_s3_a1; // 6: 0x5EA0A810
8: array<StructSize3Alignment2>:2 array_s3_a2; // 7: 0x5CF8B70D
9: vector<UnionSize8Aligned4> vector_union; // 8: 0x2B768C31
};
struct Sandwich6 {
uint32 before;
UnionWithVector the_union;
uint32 after;
};
struct Sandwich7 {
uint32 before;
Sandwich1? opt_sandwich1;
uint32 after;
};
// Same as Sandwich5, except "before" is uint64 instead of uint32, so there's no padding before the
// union.
struct Sandwich8 {
uint64 before;
UnionOfUnion union_of_union;
uint32 after;
};
// This is designed to test out-of-line handling.
union UnionWithVectorOfVectors {
1: vector<vector<StructSize3Alignment1?>> v;
};
struct Sandwich9 {
uint16 before;
UnionWithVectorOfVectors the_union;
uint16 after;
};
struct OutOfLineSandwich1 {
string before;
vector<Sandwich1>:1 v;
string after;
};
struct OutOfLineSandwich1WithOptUnion {
string before;
vector<Sandwich1WithOptUnion>:1 v;
string after;
};
struct Regression1 {
uint8 f1;
uint32 f2;
uint8 f3;
uint16 f4;
uint64 f5;
uint8 f6;
};
struct Regression2 {
Regression1 head;
uint8 f7;
};
struct Regression3 {
Regression2? opt_value;
};
// Regression1, but has at least one non primitive field
struct Regression4 {
uint8 f1;
uint32 f2;
StructSize3Alignment1 s1;
uint8 f3;
uint16 f4;
uint64 f5;
uint8 f6;
};
enum EnumUint32 {
MEMBER = 0x3231302F;
};
enum EnumUint8 : uint8 {
MEMBER = 0x08;
};
// Regression1, but with enums.
struct Regression5 {
uint8 f1;
EnumUint32 f2;
EnumUint8 f3;
uint16 f4;
uint64 f5;
uint8 f6;
};
bits BitsUint32 {
MEMBER_LOW_1 = 0x00000001;
MEMBER_LOW_2 = 0x00000002;
MEMBER_HIG_1 = 0x10000000;
MEMBER_HIG_2 = 0x20000000;
};
bits BitsUint8 : uint8 {
MEMBER = 0x08;
};
// Regression1, but with bits.
struct Regression6 {
uint8 f1;
BitsUint32 f2;
BitsUint8 f3;
uint16 f4;
uint64 f5;
uint8 f6;
};
table Table_NoFields {
};
table Table_TwoReservedFields {
1: reserved;
2: reserved;
};
table Table_StructWithReservedSandwich {
1: reserved;
2: StructSize3Alignment1 s1;
3: StructSize3Alignment1 s2;
4: reserved;
};
table Table_StructWithUint32Sandwich {
1: uint32 i;
2: StructSize3Alignment1 s1;
3: StructSize3Alignment1 s2;
4: uint32 i2;
};
table Table_UnionWithVector_ReservedSandwich {
1: reserved;
2: UnionWithVector uv;
3: reserved;
};
table Table_UnionWithVector_StructSandwich {
1: StructSize3Alignment1 s1;
2: UnionWithVector uv;
3: StructSize3Alignment1 s2;
};
table SimpleTable {
1: uint32 value;
};
struct SimpleTableArrayStruct {
array<SimpleTable>:2 the_array;
};
xunion XUnionWithStruct {
StructSize3Alignment1 s;
};
xunion XUnionWithXUnion {
XUnionWithStruct xu;
};
xunion XUnionWithUnions {
UnionSize8Aligned4 u1;
UnionSize12Aligned4 u2;
};
struct Size5Alignment1 {
array<uint8>:5 data;
};
struct Size5Alignment4 {
uint32 four;
uint8 one;
};
struct Size5Alignment1Vector {
vector<Size5Alignment1> v;
};
struct Size5Alignment4Vector {
vector<Size5Alignment4> v;
};
struct Size5Alignment1Array {
array<Size5Alignment1>:3 a;
};
struct Size5Alignment4Array {
array<Size5Alignment4>:3 a;
};
// compatibility_test turned up problems with these StringUnion-associated definitions.
union StringUnion {
1: string s;
2: bool b;
};
struct ArrayStruct {
array<StringUnion>:3 unions;
array<StringUnion?>:3 optional_unions;
};
struct StringUnionVector {
vector<StringUnion?>:3 the_vector;
};
struct StringUnionStruct {
StringUnion u;
StringUnion? nullable_u;
};
struct StringUnionStructWrapper {
StringUnionStruct sus;
};
protocol StringUnionStructWrapperProtocol {
TheMethod(StringUnionStructWrapper value) -> (StringUnionStructWrapper value);
};
// Empty struct testing.
struct EmptyStruct {
};
union EmptyStructUnion {
1: uint8 unused; // force the union tag to be non-zero
2: EmptyStruct es;
};
struct EmptyStructUnionStruct {
EmptyStructUnion u;
};
// TODO(apang): Union containing a table (to test out-of-line sizing)
struct LauncherInfo {
string:200 url;
vector<string>? arguments;
EmptyStruct? out;
EmptyStruct? err;
handle<channel>? directory_request;
EmptyStruct? flat_namespace;
EmptyStruct? additional_services;
};
union this_is_a_union {
1: string s;
2: bool b;
};
table this_is_a_table {
1: string s;
};
xunion this_is_a_xunion {
string s; // 0x3BC5BEBD
bool b;
};
table AllTypesTable {
1: this_is_a_union union_member;
2: array<uint32>:3 array_member;
3: this_is_a_table table_member;
4: this_is_a_xunion xunion_member;
};
struct CompatTable {
AllTypesTable value;
string empty;
};
table TableWithXUnion {
1: this_is_a_xunion member;
};
struct StructOfTableWithXUnion {
TableWithXUnion value;
};
union UnionAtTheBottom {
1: uint8 unused1;
2: uint8 unused2;
3: uint8 tiny;
};
xunion XUnionOfUnion {
UnionAtTheBottom variant; // 0x5F67105B
};
table TableOfXUnionThenUnion {
1: reserved;
2: XUnionOfUnion member;
};
xunion XUnionOfTableThenXUnionThenUnion {
TableOfXUnionThenUnion variant; //0x5B15934E
};
union UnionOfXUnionThenTableThenXUnionThenUnion {
1: uint8 unused1; // avoid tag 0
2: reserved; // no tag correspondance
3: XUnionOfTableThenXUnionThenUnion variant; // tag = 1
};
table TableOfUnionThenXUnionThenTableThenXUnionThenUnion {
1: reserved;
2: reserved;
3: UnionOfXUnionThenTableThenXUnionThenUnion member;
};
struct Regression7TableUnionXUnion {
TableOfUnionThenXUnionThenTableThenXUnionThenUnion value;
};
struct Regression8OptUnionSize12Aligned4 {
UnionSize12Aligned4? opt_union1;
UnionSize12Aligned4? opt_union2;
UnionSize12Aligned4? opt_union3;
};
struct Regression8VectorOfOptUnionSize12Aligned4 {
vector<UnionSize12Aligned4?> value;
};
table TableWithUnionSize12Aligned4 {
1: uint8 before;
2: reserved;
3: UnionSize12Aligned4 member;
4: reserved;
5: uint8 after;
};
struct Regression8TableWithUnionSize12Aligned4 {
TableWithUnionSize12Aligned4 value;
};
struct Regression9Value {
StringUnion u;
StringUnion? nullable_u;
};
// At first, only one member.
table Regression10TableV1 {
1: uint64 member1;
};
// Then, we add a second member in 5th position.
table Regression10TableV2 {
1: uint64 member1;
2: reserved;
3: reserved;
4: reserved;
5: uint64 member2;
};
// Third, we add a third member in 6th position, and reserve the 7th.
table Regression10TableV3 {
1: int64 x;
2: reserved;
3: reserved;
4: reserved;
5: int64 y;
6: int64 z;
7: reserved;
};
struct Regression10V1 {
Regression10TableV1 table;
};
struct Regression10V2 {
Regression10TableV2 table;
};
struct Regression10V3 {
Regression10TableV3 table;
};
union UnionWithRegression10Table {
1: uint8 unused; // avoid tag 0
2: reserved;
3: Regression10TableV2 at_v2; // but consider the evolution v1, v2, v3, ...
};
struct Regression11 {
UnionWithRegression10Table table_of_table;
};
protocol FakeProtocol {
// TODO(apang): Make this consistent.
WrapSandwich4(Sandwich4 sandwich);
SendSandwich1(uint32 before, UnionSize8Aligned4 the_union, uint32 after);
SendSandwich5(uint32 before, UnionOfUnion union_of_union, uint32 after);
SendSandwich7(uint32 before, Sandwich1? opt_sandwich1, uint32 after);
// this method tests having omitted fields in various positions within the struct
SendMixedFields(
uint32 before,
UnionSize8Aligned4 first_union,
uint16 middle_start,
uint64 middle_end,
UnionSize8Aligned4 second_union,
uint32 after);
SendFakeLauncherCreateComponentRequest(LauncherInfo info, handle h);
// This method tests a simplified version of the result returned in the
// EchoStructWithErrorSuccessCase test in the compatibility tests
Regression9() -> (Regression9Value value) error uint32;
};