Kit
Functions

getArrayEncoder

Call Signature

getArrayEncoder<TFrom>(item, config): FixedSizeEncoder<TFrom[], 0>

Returns an encoder for arrays of values.

This encoder serializes arrays by encoding each element using the provided item encoder. By default, a u32 size prefix is included 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
TFromThe type of the elements in the array.

Parameters

ParameterTypeDescription
itemEncoder<TFrom>The encoder for each item in the array.
configArrayCodecConfig<NumberEncoder> & objectOptional configuration for the size encoding strategy.

Returns

FixedSizeEncoder<TFrom[], 0>

A VariableSizeEncoder<TFrom[]> for encoding arrays.

Example

Encoding an array of u8 numbers.

const encoder = getArrayEncoder(getU8Encoder());
const bytes = encoder.encode([1, 2, 3]);
// 0x03000000010203
//   |       └-- 3 items of 1 byte each.
//   └-- 4-byte prefix telling us to read 3 items.

See

getArrayCodec

Call Signature

getArrayEncoder<TFrom>(item, config): FixedSizeEncoder<TFrom[]>

Returns an encoder for arrays of values.

This encoder serializes arrays by encoding each element using the provided item encoder. By default, a u32 size prefix is included 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
TFromThe type of the elements in the array.

Parameters

ParameterTypeDescription
itemFixedSizeEncoder<TFrom>The encoder for each item in the array.
configArrayCodecConfig<NumberEncoder> & objectOptional configuration for the size encoding strategy.

Returns

FixedSizeEncoder<TFrom[]>

A VariableSizeEncoder<TFrom[]> for encoding arrays.

Example

Encoding an array of u8 numbers.

const encoder = getArrayEncoder(getU8Encoder());
const bytes = encoder.encode([1, 2, 3]);
// 0x03000000010203
//   |       └-- 3 items of 1 byte each.
//   └-- 4-byte prefix telling us to read 3 items.

See

getArrayCodec

Call Signature

getArrayEncoder<TFrom>(item, config?): VariableSizeEncoder<TFrom[]>

Returns an encoder for arrays of values.

This encoder serializes arrays by encoding each element using the provided item encoder. By default, a u32 size prefix is included 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
TFromThe type of the elements in the array.

Parameters

ParameterTypeDescription
itemEncoder<TFrom>The encoder for each item in the array.
config?ArrayCodecConfig<NumberEncoder>Optional configuration for the size encoding strategy.

Returns

VariableSizeEncoder<TFrom[]>

A VariableSizeEncoder<TFrom[]> for encoding arrays.

Example

Encoding an array of u8 numbers.

const encoder = getArrayEncoder(getU8Encoder());
const bytes = encoder.encode([1, 2, 3]);
// 0x03000000010203
//   |       └-- 3 items of 1 byte each.
//   └-- 4-byte prefix telling us to read 3 items.

See

getArrayCodec

On this page