Functions
getUnionDecoder
getUnionDecoder<
TVariants
>(variants
,getIndexFromBytes
):Decoder
<GetDecoderTypeFromVariants
<TVariants
>>
Returns a decoder for union types.
This decoder deserializes values by selecting the correct variant decoder
based on the getIndexFromBytes
function.
Unlike other codecs, this decoder does not assume a stored discriminator. It is the user's responsibility to manage discriminators separately.
For more details, see getUnionCodec.
Type Parameters
Type Parameter | Description |
---|---|
TVariants extends readonly Decoder <any >[] | An array of decoders, each corresponding to a union variant. |
Parameters
Parameter | Type | Description |
---|---|---|
variants | TVariants | The decoders for each variant of the union. |
getIndexFromBytes | (bytes , offset ) => number | A function that determines the variant index from the byte array. |
Returns
Decoder
<GetDecoderTypeFromVariants
<TVariants
>>
A Decoder
for decoding union values.
Example
Decoding a union of numbers and booleans.