Kit
Interfaces

VariableSizeEncoder

An object that can encode a value of type TFrom into a variable-size ReadonlyUint8Array.

See Encoder to learn more about creating and composing encoders.

Example

const encoder: VariableSizeEncoder<string>;
const bytes = encoder.encode('hello');
const size = encoder.getSizeFromValue('hello');

See

Type Parameters

Type ParameterDescription
TFromThe type of the value to encode.

Properties

PropertyModifierTypeDescription
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.
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