Kit
Interfaces

VariableSizeCodec

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

See Codec to learn more about creating and composing codecs.

Example

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

See

Type Parameters

Type ParameterDefault typeDescription
TFrom-The type of the value to encode.
TTo extends TFromTFromThe type of the decoded value.

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.
getSizeFromValuereadonly(value) => numberReturns the size of the encoded value in bytes for a given input.
maxSize?readonlynumberThe maximum possible size of an encoded value in bytes, if applicable.
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