Kit
Interfaces

FixedSizeCodec

An object that can encode and decode a value to and from a fixed-size byte array.

See Codec to learn more about creating and composing codecs.

Example

const codec: FixedSizeCodec<number | bigint, bigint, 8>;
const bytes = codec.encode(42);
const value = codec.decode(bytes); // 42n
const size = codec.fixedSize; // 8

See

Type Parameters

Type ParameterDefault typeDescription
TFrom-The type of the value to encode.
TTo extends TFromTFromThe type of the decoded value.
TSize extends numbernumberThe fixed size of the encoded value in bytes.

Properties

PropertyModifierTypeDescription
decodereadonly(bytes, offset?) => TToDecodes the provided byte array at the given offset (or zero) and returns the value directly.
encodereadonly(value) => ReadonlyUint8ArrayEncode the provided value and return the encoded bytes directly.
fixedSizereadonlyTSizeThe fixed size of the encoded value in bytes.
readreadonly(bytes, offset) => [TTo, number]Reads the encoded value from the provided byte array at the given offset. Returns the decoded value and the offset of the next byte after the encoded value.
writereadonly(value, bytes, offset) => numberWrites the encoded value into the provided byte array at the given offset. Returns the offset of the next byte after the encoded value.

On this page