Kit
Functions

reverseDecoder

reverseDecoder<TTo, TSize>(decoder): FixedSizeDecoder<TTo, TSize>

Reverses the bytes of a fixed-size decoder.

Given a FixedSizeDecoder, this function returns a new FixedSizeDecoder that reverses the bytes within the fixed-size byte array before decoding.

This can be useful to modify endianness or for other byte-order transformations.

For more details, see reverseCodec.

Type Parameters

Type ParameterDescription
TToThe type of the decoded value.
TSize extends numberThe fixed size of the decoded value in bytes.

Parameters

ParameterTypeDescription
decoderFixedSizeDecoder<TTo, TSize>The fixed-size decoder to reverse.

Returns

FixedSizeDecoder<TTo, TSize>

A new decoder that reads bytes in reverse order.

Example

Decoding a reversed u16 value.

const decoder = reverseDecoder(getU16Decoder({ endian: Endian.Big }));
const value = decoder.decode(new Uint8Array([0x34, 0x12])); // 0x1234 (bytes are flipped back)

See

On this page