A record mapping variant names to codecs.
// Dynamic union without custom numeric IDs
union({ cafe: Uint8, bee: Uint16 })
// Dynamic union with custom numeric IDs
union({ cafe: Uint8, bee: Uint16 }, { cafe: 0xcafe, bee: 0xbee })
// Fixed-size union without custom numeric IDs
const PaddedUint8 = struct({ data : u8, padding : u8 })
union({ cafe: PaddedUint8, bee: Uint16 });
// Fixed-size union with custom numeric IDs
union({ cafe: PaddedUint8, bee: Uint16 }, { cafe: 0xcafe, bee: 0xbee })
Constructs a union codec that can serialize and deserialize values tagged with a type identifier.
If all variants have the same fixed size, the resulting union codec is fixed-size (header + payload). Otherwise, it falls back to a dynamic-size codec.
Serialization format: