| // 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; |
| |
| closed protocol Handles { |
| // Starting easy: just a handle. |
| strict NonnullableHandle(resource struct { |
| h0 zx.Handle; |
| }); |
| |
| // Multiple handles! |
| strict MultipleNonnullableHandles(resource struct { |
| data0 uint32; |
| h0 zx.Handle; |
| data1 uint64; |
| h1 zx.Handle; |
| h2 zx.Handle; |
| data2 uint64; |
| }); |
| strict 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>; |
| }; |
| |
| closed protocol Arrays { |
| strict ArrayOfNonnullableHandles(resource struct { |
| handles array<zx.Handle, 4>; |
| }); |
| strict ArrayOfNullableHandles(resource struct { |
| handles array<zx.Handle:optional, 4>; |
| }); |
| strict ArrayOfArrayOfNonnullableHandles(resource struct { |
| handles array<array<zx.Handle, 3>, 4>; |
| }); |
| strict OutOfLineArrayOfNonnullableHandles(resource struct { |
| handles box<NonnullableHandleArray>; |
| }); |
| }; |
| |
| closed protocol Strings { |
| strict UnboundedNonnullableString(struct { |
| s0 string; |
| }); |
| strict UnboundedNullableString(struct { |
| s0 string:optional; |
| }); |
| strict Bounded32NonnullableString(struct { |
| s0 string:32; |
| }); |
| strict Bounded32NullableString(struct { |
| s0 string:<32, optional>; |
| }); |
| strict MultipleNonnullableStrings(struct { |
| s0 string; |
| s1 string; |
| }); |
| strict MultipleNullableStrings(struct { |
| s0 string:optional; |
| s1 string:optional; |
| }); |
| }; |
| |
| closed protocol Vectors { |
| strict UnboundedNonnullableVectorOfHandles(resource struct { |
| vh0 vector<zx.Handle>; |
| }); |
| strict UnboundedNullableVectorOfHandles(resource struct { |
| vh0 vector<zx.Handle>:optional; |
| }); |
| strict Bounded32NonnullableVectorOfHandles(resource struct { |
| vh0 vector<zx.Handle>:32; |
| }); |
| strict Bounded32NullableVectorOfHandles(resource struct { |
| vh0 vector<zx.Handle>:<32, optional>; |
| }); |
| strict MultipleNonnullableVectorsOfHandles(resource struct { |
| vh0 vector<zx.Handle>; |
| vh1 vector<zx.Handle>; |
| }); |
| strict MultipleNullableVectorsOfHandles(resource struct { |
| vh0 vector<zx.Handle>:optional; |
| vh1 vector<zx.Handle>:optional; |
| }); |
| strict UnboundedNonnullableVectorOfUint32s(struct { |
| vu0 vector<uint32>; |
| }); |
| strict UnboundedNullableVectorOfUint32s(struct { |
| vu0 vector<uint32>:optional; |
| }); |
| strict Bounded32NonnullableVectorOfUint32s(struct { |
| vu0 vector<uint32>:32; |
| }); |
| strict Bounded32NullableVectorOfUint32s(struct { |
| vu0 vector<uint32>:<32, optional>; |
| }); |
| strict MultipleNonnullableVectorsOfUint32s(struct { |
| vu0 vector<uint32>; |
| vu1 vector<uint32>; |
| }); |
| strict 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; |
| }; |
| |
| closed protocol Unions { |
| strict SingleHandleUnion(resource struct { |
| u SingleHandleUnion; |
| }); |
| strict SingleHandleUnionPointer(resource struct { |
| u SingleHandleUnion; |
| }); |
| strict MultipleHandlesUnion(resource struct { |
| u MultipleHandlesUnion; |
| }); |
| strict MultipleHandlesUnionPointer(resource struct { |
| u MultipleHandlesUnion:optional; |
| }); |
| strict 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>; |
| }; |
| |
| closed protocol Structs { |
| strict Inline(resource struct { |
| l0 Inline0; |
| }); |
| strict OutOfLine(resource struct { |
| l0 OutOfLine0; |
| }); |
| }; |