| // Copyright 2018 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. |
| // A set of structs and interface methods designed to exercise fidl_encode, |
| // fidl_decode, and fidl_validate. |
| |
| library fidl.test.coding.fuchsia; |
| |
| using zx; |
| |
| protocol Handles { |
| // Starting easy: just a handle. |
| NonnullableHandle(resource struct { |
| h0 zx.handle; |
| }); |
| |
| // Multiple handles! |
| MultipleNonnullableHandles(resource struct { |
| data0 uint32; |
| h0 zx.handle; |
| data1 uint64; |
| h1 zx.handle; |
| h2 zx.handle; |
| data2 uint64; |
| }); |
| MultipleNullableHandles(resource struct { |
| data0 uint32; |
| h0 zx.handle:optional; |
| data1 uint64; |
| h1 zx.handle:optional; |
| h2 zx.handle:optional; |
| data2 uint64; |
| }); |
| }; |
| |
| type NonnullableHandleArray = resource struct { |
| handles array<zx.handle, 4>; |
| }; |
| |
| protocol Arrays { |
| ArrayOfNonnullableHandles(resource struct { |
| handles array<zx.handle, 4>; |
| }); |
| ArrayOfNullableHandles(resource struct { |
| handles array<zx.handle:optional, 4>; |
| }); |
| ArrayOfArrayOfNonnullableHandles(resource struct { |
| handles array<array<zx.handle, 3>, 4>; |
| }); |
| OutOfLineArrayOfNonnullableHandles(resource struct { |
| handles box<NonnullableHandleArray>; |
| }); |
| }; |
| |
| protocol Strings { |
| UnboundedNonnullableString(struct { |
| s0 string; |
| }); |
| UnboundedNullableString(struct { |
| s0 string:optional; |
| }); |
| Bounded32NonnullableString(struct { |
| s0 string:32; |
| }); |
| Bounded32NullableString(struct { |
| s0 string:<32, optional>; |
| }); |
| MultipleNonnullableStrings(struct { |
| s0 string; |
| s1 string; |
| }); |
| MultipleNullableStrings(struct { |
| s0 string:optional; |
| s1 string:optional; |
| }); |
| }; |
| |
| protocol Vectors { |
| UnboundedNonnullableVectorOfHandles(resource struct { |
| vh0 vector<zx.handle>; |
| }); |
| UnboundedNullableVectorOfHandles(resource struct { |
| vh0 vector<zx.handle>:optional; |
| }); |
| Bounded32NonnullableVectorOfHandles(resource struct { |
| vh0 vector<zx.handle>:32; |
| }); |
| Bounded32NullableVectorOfHandles(resource struct { |
| vh0 vector<zx.handle>:<32, optional>; |
| }); |
| MultipleNonnullableVectorsOfHandles(resource struct { |
| vh0 vector<zx.handle>; |
| vh1 vector<zx.handle>; |
| }); |
| MultipleNullableVectorsOfHandles(resource struct { |
| vh0 vector<zx.handle>:optional; |
| vh1 vector<zx.handle>:optional; |
| }); |
| UnboundedNonnullableVectorOfUint32s(struct { |
| vu0 vector<uint32>; |
| }); |
| UnboundedNullableVectorOfUint32s(struct { |
| vu0 vector<uint32>:optional; |
| }); |
| Bounded32NonnullableVectorOfUint32s(struct { |
| vu0 vector<uint32>:32; |
| }); |
| Bounded32NullableVectorOfUint32s(struct { |
| vu0 vector<uint32>:<32, optional>; |
| }); |
| MultipleNonnullableVectorsOfUint32s(struct { |
| vu0 vector<uint32>; |
| vu1 vector<uint32>; |
| }); |
| MultipleNullableVectorsOfUint32s(struct { |
| vu0 vector<uint32>:optional; |
| vu1 vector<uint32>:optional; |
| }); |
| }; |
| |
| type SingleHandleUnion = strict resource union { |
| 1: h0 zx.handle; |
| }; |
| |
| type MultipleHandlesUnion = strict resource union { |
| 1: h zx.handle; |
| 2: hs array<zx.handle, 2>; |
| 3: hss array<array<zx.handle, 2>, 2>; |
| }; |
| |
| type MaybeRecurse = strict resource union { |
| 1: h zx.handle; |
| 2: more MaybeRecurseHelper; |
| }; |
| |
| // Unions cannot have nullable fields, so wrap it in a struct. |
| type MaybeRecurseHelper = resource struct { |
| more MaybeRecurse:optional; |
| }; |
| |
| protocol Unions { |
| SingleHandleUnion(resource struct { |
| u SingleHandleUnion; |
| }); |
| SingleHandleUnionPointer(resource struct { |
| u SingleHandleUnion; |
| }); |
| MultipleHandlesUnion(resource struct { |
| u MultipleHandlesUnion; |
| }); |
| MultipleHandlesUnionPointer(resource struct { |
| u MultipleHandlesUnion:optional; |
| }); |
| Recursion(resource struct { |
| u MaybeRecurse; |
| }); |
| }; |
| |
| type Inline3 = resource struct { |
| padding uint32; |
| h zx.handle; |
| }; |
| |
| type Inline2 = resource struct { |
| padding uint64; |
| l3 Inline3; |
| h zx.handle; |
| }; |
| |
| type Inline1 = resource struct { |
| h zx.handle; |
| l2 Inline2; |
| padding uint64; |
| }; |
| |
| type Inline0 = resource struct { |
| padding uint64; |
| L1 Inline1; |
| h zx.handle; |
| }; |
| |
| type OutOfLine3 = resource struct { |
| padding uint32; |
| h zx.handle; |
| }; |
| |
| type OutOfLine2 = resource struct { |
| padding uint64; |
| l3_present box<OutOfLine3>; |
| l3_absent box<OutOfLine3>; |
| l3_inline OutOfLine3; |
| }; |
| |
| type OutOfLine1 = resource struct { |
| h zx.handle; |
| l2_present box<OutOfLine2>; |
| l2_inline OutOfLine2; |
| l2_absent box<OutOfLine2>; |
| padding uint64; |
| }; |
| |
| type OutOfLine0 = resource struct { |
| padding uint64; |
| l1_absent box<OutOfLine1>; |
| l1_inline OutOfLine1; |
| h zx.handle; |
| l1_present box<OutOfLine1>; |
| }; |
| |
| protocol Structs { |
| Inline(resource struct { |
| l0 Inline0; |
| }); |
| OutOfLine(resource struct { |
| l0 OutOfLine0; |
| }); |
| }; |