Kit
Functions

assertIsVariableSize

Call Signature

assertIsVariableSize<TFrom>(encoder): asserts encoder is VariableSizeEncoder<TFrom>

Asserts that the given codec, encoder, or decoder is variable-size.

If the object is not variable-size (i.e., it has a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH.

Type Parameters

Type ParameterDescription
TFromThe type of the value to encode.

Parameters

ParameterType
encoderEncoder<TFrom>

Returns

asserts encoder is VariableSizeEncoder<TFrom>

Throws

If the object is not variable-size.

Examples

Asserting a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsVariableSize(encoder); // Passes

Attempting to assert a fixed-size encoder.

const encoder = getU32Encoder();
assertIsVariableSize(encoder); // Throws SolanaError

Remarks

This function is the assertion-based counterpart of isVariableSize. If you only need to check whether an object is variable-size without throwing an error, use isVariableSize instead.

Also note that this function is the inverse of assertIsFixedSize.

See

Call Signature

assertIsVariableSize<TTo>(decoder): asserts decoder is VariableSizeDecoder<TTo>

Asserts that the given codec, encoder, or decoder is variable-size.

If the object is not variable-size (i.e., it has a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH.

Type Parameters

Type ParameterDescription
TToThe type of the decoded value.

Parameters

ParameterType
decoderDecoder<TTo>

Returns

asserts decoder is VariableSizeDecoder<TTo>

Throws

If the object is not variable-size.

Examples

Asserting a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsVariableSize(encoder); // Passes

Attempting to assert a fixed-size encoder.

const encoder = getU32Encoder();
assertIsVariableSize(encoder); // Throws SolanaError

Remarks

This function is the assertion-based counterpart of isVariableSize. If you only need to check whether an object is variable-size without throwing an error, use isVariableSize instead.

Also note that this function is the inverse of assertIsFixedSize.

See

Call Signature

assertIsVariableSize<TFrom, TTo>(codec): asserts codec is VariableSizeCodec<TFrom, TTo>

Asserts that the given codec, encoder, or decoder is variable-size.

If the object is not variable-size (i.e., it has a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH.

Type Parameters

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

Parameters

ParameterType
codecCodec<TFrom, TTo>

Returns

asserts codec is VariableSizeCodec<TFrom, TTo>

Throws

If the object is not variable-size.

Examples

Asserting a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsVariableSize(encoder); // Passes

Attempting to assert a fixed-size encoder.

const encoder = getU32Encoder();
assertIsVariableSize(encoder); // Throws SolanaError

Remarks

This function is the assertion-based counterpart of isVariableSize. If you only need to check whether an object is variable-size without throwing an error, use isVariableSize instead.

Also note that this function is the inverse of assertIsFixedSize.

See

Call Signature

assertIsVariableSize(codec): asserts codec is { maxSize?: number }

Asserts that the given codec, encoder, or decoder is variable-size.

If the object is not variable-size (i.e., it has a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_VARIABLE_LENGTH.

Parameters

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

Returns

asserts codec is { maxSize?: number }

Throws

If the object is not variable-size.

Examples

Asserting a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsVariableSize(encoder); // Passes

Attempting to assert a fixed-size encoder.

const encoder = getU32Encoder();
assertIsVariableSize(encoder); // Throws SolanaError

Remarks

This function is the assertion-based counterpart of isVariableSize. If you only need to check whether an object is variable-size without throwing an error, use isVariableSize instead.

Also note that this function is the inverse of assertIsFixedSize.

See

On this page