Kit
Functions

getTupleDecoder

Call Signature

getTupleDecoder<TItems>(items): FixedSizeDecoder<DrainOuterGeneric<{ [I in string | number | symbol]: TItems[I<I>] extends Decoder<TTo> ? TTo : never }>>

Returns a decoder for tuples.

This decoder deserializes a fixed-size array (tuple) by decoding its items sequentially using the provided item decoders.

For more details, see getTupleCodec.

Type Parameters

Type ParameterDescription
TItems extends readonly FixedSizeDecoder<any>[]An array of decoders, each corresponding to a tuple element.

Parameters

ParameterTypeDescription
itemsTItemsThe decoders for each item in the tuple.

Returns

FixedSizeDecoder<DrainOuterGeneric<{ [I in string | number | symbol]: TItems[I<I>] extends Decoder<TTo> ? TTo : never }>>

A FixedSizeDecoder or VariableSizeDecoder for decoding tuples.

Example

Decoding a tuple with 2 items.

const decoder = getTupleDecoder([fixCodecSize(getUtf8Decoder(), 5), getU8Decoder()]);
 
const tuple = decoder.decode(new Uint8Array([
  0x41,0x6c,0x69,0x63,0x65,0x2a
]));
// ['Alice', 42]

See

getTupleCodec

Call Signature

getTupleDecoder<TItems>(items): VariableSizeDecoder<DrainOuterGeneric<{ [I in string | number | symbol]: TItems[I<I>] extends Decoder<TTo> ? TTo : never }>>

Returns a decoder for tuples.

This decoder deserializes a fixed-size array (tuple) by decoding its items sequentially using the provided item decoders.

For more details, see getTupleCodec.

Type Parameters

Type ParameterDescription
TItems extends readonly Decoder<any>[]An array of decoders, each corresponding to a tuple element.

Parameters

ParameterTypeDescription
itemsTItemsThe decoders for each item in the tuple.

Returns

VariableSizeDecoder<DrainOuterGeneric<{ [I in string | number | symbol]: TItems[I<I>] extends Decoder<TTo> ? TTo : never }>>

A FixedSizeDecoder or VariableSizeDecoder for decoding tuples.

Example

Decoding a tuple with 2 items.

const decoder = getTupleDecoder([fixCodecSize(getUtf8Decoder(), 5), getU8Decoder()]);
 
const tuple = decoder.decode(new Uint8Array([
  0x41,0x6c,0x69,0x63,0x65,0x2a
]));
// ['Alice', 42]

See

getTupleCodec

On this page