Kit
Functions

getArrayDecoder

Call Signature

getArrayDecoder<TTo>(item, config): FixedSizeDecoder<TTo[], 0>

Returns a decoder for arrays of values.

This decoder deserializes arrays by decoding each element using the provided item decoder. By default, a u32 size prefix is expected to indicate the number of items in the array. The size option can be used to modify this behaviour.

For more details, see getArrayCodec.

Type Parameters

Type ParameterDescription
TToThe type of the decoded elements in the array.

Parameters

ParameterTypeDescription
itemDecoder<TTo>The decoder for each item in the array.
configArrayCodecConfig<NumberDecoder> & objectOptional configuration for the size decoding strategy.

Returns

FixedSizeDecoder<TTo[], 0>

A VariableSizeDecoder<TTo[]> for decoding arrays.

Example

Decoding an array of u8 numbers.

const decoder = getArrayDecoder(getU8Decoder());
const array = decoder.decode(new Uint8Array([0x03, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03]));
// [1, 2, 3]
// 0x03000000010203
//   |       └-- 3 items of 1 byte each.
//   └-- 4-byte prefix telling us to read 3 items.

See

getArrayCodec

Call Signature

getArrayDecoder<TTo>(item, config): FixedSizeDecoder<TTo[]>

Returns a decoder for arrays of values.

This decoder deserializes arrays by decoding each element using the provided item decoder. By default, a u32 size prefix is expected to indicate the number of items in the array. The size option can be used to modify this behaviour.

For more details, see getArrayCodec.

Type Parameters

Type ParameterDescription
TToThe type of the decoded elements in the array.

Parameters

ParameterTypeDescription
itemFixedSizeDecoder<TTo>The decoder for each item in the array.
configArrayCodecConfig<NumberDecoder> & objectOptional configuration for the size decoding strategy.

Returns

FixedSizeDecoder<TTo[]>

A VariableSizeDecoder<TTo[]> for decoding arrays.

Example

Decoding an array of u8 numbers.

const decoder = getArrayDecoder(getU8Decoder());
const array = decoder.decode(new Uint8Array([0x03, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03]));
// [1, 2, 3]
// 0x03000000010203
//   |       └-- 3 items of 1 byte each.
//   └-- 4-byte prefix telling us to read 3 items.

See

getArrayCodec

Call Signature

getArrayDecoder<TTo>(item, config?): VariableSizeDecoder<TTo[]>

Returns a decoder for arrays of values.

This decoder deserializes arrays by decoding each element using the provided item decoder. By default, a u32 size prefix is expected to indicate the number of items in the array. The size option can be used to modify this behaviour.

For more details, see getArrayCodec.

Type Parameters

Type ParameterDescription
TToThe type of the decoded elements in the array.

Parameters

ParameterTypeDescription
itemDecoder<TTo>The decoder for each item in the array.
config?ArrayCodecConfig<NumberDecoder>Optional configuration for the size decoding strategy.

Returns

VariableSizeDecoder<TTo[]>

A VariableSizeDecoder<TTo[]> for decoding arrays.

Example

Decoding an array of u8 numbers.

const decoder = getArrayDecoder(getU8Decoder());
const array = decoder.decode(new Uint8Array([0x03, 0x00, 0x00, 0x00, 0x01, 0x02, 0x03]));
// [1, 2, 3]
// 0x03000000010203
//   |       └-- 3 items of 1 byte each.
//   └-- 4-byte prefix telling us to read 3 items.

See

getArrayCodec

On this page