| // 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. |
| |
| library fidl.test.example.codingtables; |
| |
| using fidl.test.example.codingtablesdeps as deplib; |
| |
| struct SomeStruct { |
| bool foo; |
| int32 bar; |
| }; |
| |
| // Tested in StructWithSomeFieldsRemoved. |
| // All fields in this struct don't have actions in coding tables. |
| struct StructWithAllFieldsRemovedFromCodingTables { |
| int8 a; |
| int8 b; |
| int16 c; |
| }; |
| |
| // Tested in StructWithSomeFieldsRemoved. |
| struct StructWithPadding { |
| int8 a; |
| int64 c; |
| }; |
| |
| struct PaddingAtEndStruct { |
| uint16 a; |
| uint8 b; |
| }; |
| |
| // Some fields in this struct should be removed from coding tables because |
| // they have no action and the walker can skip over them. |
| struct StructWithSomeFieldsRemovedFromCodingTables { |
| StructWithPadding padding_struct; // not removed |
| // PaddingAtEndStruct contains 3 bytes with 1 final byte of padding |
| // When the struct is flattened, this becomes 5 bytes of padding. |
| PaddingAtEndStruct padding_at_end_struct; |
| uint64 reset_alignment; |
| int8 foo; // removed |
| // 3 bytes padding. |
| array<StructWithAllFieldsRemovedFromCodingTables>:1 arr; // removed |
| array<bool>:1 bool_array; // not removed |
| // 1 byte padding. |
| uint16 bar; // removed |
| }; |
| |
| flexible union MyXUnion { |
| 1: bool foo; |
| 2: int32 bar; |
| }; |
| |
| union MyStrictXUnion { |
| 1: bool foo; |
| 2: int32 bar; |
| }; |
| |
| table MyTable { |
| 1: bool foo; |
| 2: int32 bar; |
| 3: reserved; |
| 4: array<uint64>:42 baz; |
| 5: vector<uint64>:42 qux; |
| }; |
| |
| bits MyBits : uint8 { |
| HELLO = 0x1; |
| WORLD = 0x10; |
| }; |
| |
| enum MyEnum : uint32 { |
| FOO = 1; |
| BAR = 42; |
| }; |
| |
| // Types defined to detect collisions in the mangled coding table output. |
| struct A { |
| }; |
| |
| struct A1 { |
| }; |
| |
| struct NumberCollision { |
| array<A>:11 a; |
| array<A1>:1 b; |
| vector<A>:11 c; |
| vector<A1>:1 d; |
| string:11 e; |
| string:1 f; |
| }; |
| |
| // fidlc will only expose coding tables for message types. |
| // However, we can obtain the coding tables for SomeStruct/MyXUnion etc. via the coding table |
| // for request message types, by defining dummy methods which take a single desired argument. |
| protocol Coding { |
| SomeStruct(SomeStruct s); |
| StructWithSomeFieldsRemovedFromCodingTables(StructWithSomeFieldsRemovedFromCodingTables s); |
| |
| // Various trickery to avoid directly refering a xunion/table inline, |
| // which is not supported in the C bindings. |
| MyXUnion(MyXUnion? x); |
| MyStrictXUnion(MyStrictXUnion? x); |
| |
| // Ensuring support for multiple uses of the same nullable type. |
| MyXUnion2(MyXUnion? x); |
| MyStrictXUnion2(MyStrictXUnion? x); |
| |
| VectorOfMyTable(vector<MyTable> t); |
| VectorOfMyXUnion(vector<MyXUnion> x); |
| VectorOfMyStrictXUnion(vector<MyStrictXUnion> x); |
| |
| MyBits(MyBits b); |
| MyEnum(MyEnum e); |
| |
| NumberCollision(NumberCollision x); |
| |
| ForeignXUnions(deplib.MyXUnionA tx) -> (deplib.MyXUnionA? rx); |
| }; |