Kit
Functions

isVariableSize

Call Signature

isVariableSize<TFrom>(encoder): encoder is VariableSizeEncoder<TFrom>

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

A variable-size object is identified by the absence of a fixedSize property. If this property is missing, the object is considered a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Type Parameters

Type ParameterDescription
TFromThe type of the value to encode.

Parameters

ParameterType
encoderEncoder<TFrom>

Returns

encoder is VariableSizeEncoder<TFrom>

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

Examples

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isVariableSize(encoder); // true

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isVariableSize(encoder); // false

Remarks

This function is the inverse of isFixedSize.

See

Call Signature

isVariableSize<TTo>(decoder): decoder is VariableSizeDecoder<TTo>

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

A variable-size object is identified by the absence of a fixedSize property. If this property is missing, the object is considered a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Type Parameters

Type ParameterDescription
TToThe type of the decoded value.

Parameters

ParameterType
decoderDecoder<TTo>

Returns

decoder is VariableSizeDecoder<TTo>

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

Examples

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isVariableSize(encoder); // true

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isVariableSize(encoder); // false

Remarks

This function is the inverse of isFixedSize.

See

Call Signature

isVariableSize<TFrom, TTo>(codec): codec is VariableSizeCodec<TFrom, TTo>

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

A variable-size object is identified by the absence of a fixedSize property. If this property is missing, the object is considered a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Type Parameters

Type ParameterDescription
TFromThe type of the value to encode.
TToThe type of the decoded value.

Parameters

ParameterType
codecCodec<TFrom, TTo>

Returns

codec is VariableSizeCodec<TFrom, TTo>

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

Examples

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isVariableSize(encoder); // true

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isVariableSize(encoder); // false

Remarks

This function is the inverse of isFixedSize.

See

Call Signature

isVariableSize(codec): codec is { maxSize?: number }

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

A variable-size object is identified by the absence of a fixedSize property. If this property is missing, the object is considered a VariableSizeCodec, VariableSizeEncoder, or VariableSizeDecoder.

Parameters

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

Returns

codec is { maxSize?: number }

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

Examples

Checking a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
isVariableSize(encoder); // true

Checking a fixed-size encoder.

const encoder = getU32Encoder();
isVariableSize(encoder); // false

Remarks

This function is the inverse of isFixedSize.

See

On this page