Kit
Functions

isFixedSize

Call Signature

isFixedSize<TFrom, TSize>(encoder): encoder is FixedSizeEncoder<TFrom, TSize>

Determines whether the given codec, encoder, or decoder is fixed-size.

A fixed-size object is identified by the presence of a fixedSize property. If this property exists, the object is considered a FixedSizeCodec, FixedSizeEncoder, or FixedSizeDecoder. Otherwise, it is assumed to be a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Type Parameters

Type ParameterDescription
TFromThe type of the value to encode.
TSize extends numberThe fixed size of the encoded value in bytes.

Parameters

ParameterType
encoderFixedSizeEncoder<TFrom, TSize> | VariableSizeEncoder<TFrom>

Returns

encoder is FixedSizeEncoder<TFrom, TSize>

true if the object is fixed-size, false otherwise.

Examples

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isFixedSize(encoder); // true

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isFixedSize(encoder); // false

Remarks

This function is commonly used to distinguish between fixed-size and variable-size objects at runtime. If you need to enforce this distinction with type assertions, consider using assertIsFixedSize.

See

assertIsFixedSize

Call Signature

isFixedSize<TTo, TSize>(decoder): decoder is FixedSizeDecoder<TTo, TSize>

Determines whether the given codec, encoder, or decoder is fixed-size.

A fixed-size object is identified by the presence of a fixedSize property. If this property exists, the object is considered a FixedSizeCodec, FixedSizeEncoder, or FixedSizeDecoder. Otherwise, it is assumed to be a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Type Parameters

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

Parameters

ParameterType
decoderFixedSizeDecoder<TTo, TSize> | VariableSizeDecoder<TTo>

Returns

decoder is FixedSizeDecoder<TTo, TSize>

true if the object is fixed-size, false otherwise.

Examples

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isFixedSize(encoder); // true

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isFixedSize(encoder); // false

Remarks

This function is commonly used to distinguish between fixed-size and variable-size objects at runtime. If you need to enforce this distinction with type assertions, consider using assertIsFixedSize.

See

assertIsFixedSize

Call Signature

isFixedSize<TFrom, TTo, TSize>(codec): codec is FixedSizeCodec<TFrom, TTo, TSize>

Determines whether the given codec, encoder, or decoder is fixed-size.

A fixed-size object is identified by the presence of a fixedSize property. If this property exists, the object is considered a FixedSizeCodec, FixedSizeEncoder, or FixedSizeDecoder. Otherwise, it is assumed to be a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Type Parameters

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

Parameters

ParameterType
codecFixedSizeCodec<TFrom, TTo, TSize> | VariableSizeCodec<TFrom, TTo>

Returns

codec is FixedSizeCodec<TFrom, TTo, TSize>

true if the object is fixed-size, false otherwise.

Examples

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isFixedSize(encoder); // true

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isFixedSize(encoder); // false

Remarks

This function is commonly used to distinguish between fixed-size and variable-size objects at runtime. If you need to enforce this distinction with type assertions, consider using assertIsFixedSize.

See

assertIsFixedSize

Call Signature

isFixedSize<TSize>(codec): codec is { fixedSize: TSize }

Determines whether the given codec, encoder, or decoder is fixed-size.

A fixed-size object is identified by the presence of a fixedSize property. If this property exists, the object is considered a FixedSizeCodec, FixedSizeEncoder, or FixedSizeDecoder. Otherwise, it is assumed to be a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Type Parameters

Type ParameterDescription
TSize extends numberThe fixed size of the encoded value in bytes.

Parameters

ParameterType
codec{ fixedSize: TSize; } | { maxSize?: number; }

Returns

codec is { fixedSize: TSize }

true if the object is fixed-size, false otherwise.

Examples

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isFixedSize(encoder); // true

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isFixedSize(encoder); // false

Remarks

This function is commonly used to distinguish between fixed-size and variable-size objects at runtime. If you need to enforce this distinction with type assertions, consider using assertIsFixedSize.

See

assertIsFixedSize

On this page