function array
array<TDecoded>(
elementType: Coder<TDecoded>,
): Coder<TDecoded[]>

Creates a Coder for arrays that automatically chooses between length-prefixed and fixed-length based on the arguments provided.

  • If a lengthType coder is provided as the second argument, it creates a length-prefixed array
  • If a length number/reference is provided as the second argument, it creates a fixed-length array

Type Parameters

TDecoded

Parameters

elementType: Coder<TDecoded>

The coder for individual array elements

A condition function for while-loop arrays

Return Type

Coder<TDecoded[]>

A Coder that can encode/decode arrays of the element type

array<TDecoded>(
elementType: Coder<TDecoded>,
lengthCoderOrLengthType: Coder<number> | LengthOrRef
): Coder<TDecoded[]>

Creates a Coder for arrays that automatically chooses between length-prefixed and fixed-length based on the arguments provided.

  • If a lengthType coder is provided as the second argument, it creates a length-prefixed array
  • If a length number/reference is provided as the second argument, it creates a fixed-length array

Type Parameters

TDecoded

Parameters

elementType: Coder<TDecoded>

The coder for individual array elements

lengthCoderOrLengthType: Coder<number> | LengthOrRef

Either a length coder (for length-prefixed) or length value/reference (for fixed-length)

Return Type

Coder<TDecoded[]>

A Coder that can encode/decode arrays of the element type