| library fidl.test.union; |
| |
| struct Pizza { |
| vector<string:16> toppings; |
| }; |
| |
| struct Pasta { |
| string:16 sauce; |
| }; |
| |
| union PizzaOrPasta { |
| 1: Pizza pizza; |
| 2: Pasta pasta; |
| }; |
| |
| union ExplicitPizzaOrPasta { |
| 3: reserved; |
| 2: reserved; |
| 1: Pizza pizza; |
| 4: Pasta pasta; |
| }; |
| |
| flexible union FlexiblePizzaOrPasta { |
| 1: Pizza pizza; |
| 2: Pasta pasta; |
| }; |
| |
| union StrictPizzaOrPasta { |
| 1: Pizza pizza; |
| 2: Pasta pasta; |
| }; |
| |
| union Union { |
| 1: int32 Primitive; |
| 2: string StringNeedsConstructor; |
| 3: vector<string> VectorStringAlsoNeedsConstructor; |
| }; |
| |
| flexible union FlexibleUnion { |
| 1: int32 Primitive; |
| 2: string StringNeedsConstructor; |
| 3: vector<string> VectorStringAlsoNeedsConstructor; |
| }; |
| |
| union StrictUnion { |
| 1: int32 Primitive; |
| 2: string StringNeedsConstructor; |
| 3: vector<string> VectorStringAlsoNeedsConstructor; |
| }; |
| |
| union FieldCollision { |
| 1: int32 field_collision_tag; |
| }; |
| |
| union ExplicitUnion { |
| 2: reserved; |
| 1: int32 Primitive; |
| 3: string StringNeedsConstructor; |
| }; |
| |
| union ReverseOrdinalUnion { |
| 2: uint32 second; |
| 1: uint32 first; |
| }; |
| |
| struct NullableUnionStruct { |
| Union? the_union; |
| }; |
| |
| flexible union FlexibleFoo { |
| 1: string s; |
| 2: int32 i; |
| }; |
| |
| strict union StrictFoo { |
| 1: string s; |
| 2: int32 i; |
| }; |
| |
| flexible union ExplicitFoo { |
| 2: string s; |
| 1: int32 i; |
| 3: reserved; |
| }; |
| |
| strict union ExplicitStrictFoo { |
| 1: reserved; |
| 3: string s; |
| 2: int32 i; |
| }; |
| |
| flexible union OlderSimpleUnion { |
| 1: int64 i; |
| 2: float32 f; |
| }; |
| |
| flexible union NewerSimpleUnion { |
| // float f; // removed |
| |
| 1: int64 i; // unchanged |
| |
| 2: string s; // added |
| 3: vector<string> v; // added |
| }; |
| |
| // 1. This xunion is currently unused by code, and for tracking changes in the goldens only. |
| // 2. There's no FlexibleSimpleXUnion, since that's covered by OlderSimpleUnion above. |
| strict union StrictSimpleXUnion { |
| 1: int32 i; |
| 2: float32 f; |
| 3: string s; |
| }; |
| |
| struct Empty { |
| }; |
| |
| flexible union XUnionContainingEmptyStruct { |
| // This is a test to prevent regressions for fxbug.dev/8084. Note that we need fxbug.dev/8080 to be resolved |
| // to ensure this actually works, since goldens aren't currently compiled. |
| 1: Empty empty; |
| }; |
| |
| strict union StrictBoundedXUnion { |
| 1: vector<uint8>:10 v; |
| }; |
| |
| protocol TestProtocol { |
| StrictXUnionHenceResponseMayBeStackAllocated() -> (StrictBoundedXUnion xu); |
| FlexibleXUnionHenceResponseMustBeHeapAllocated() -> (OlderSimpleUnion xu); |
| }; |
| |
| struct StructWithNullableXUnion { |
| OlderSimpleUnion? x1; |
| }; |
| |
| flexible union ExplicitXUnion { |
| 3: reserved; |
| 2: reserved; |
| 1: int64 i; |
| 4: float32 f; |
| }; |