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