Kit
Functions

assertIsFixedSize

Call Signature

assertIsFixedSize<TFrom, TSize>(encoder): asserts encoder is FixedSizeEncoder<TFrom, TSize>

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

If the object is not fixed-size (i.e., it lacks a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH.

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

asserts encoder is FixedSizeEncoder<TFrom, TSize>

Throws

If the object is not fixed-size.

Examples

Asserting a fixed-size encoder.

const encoder = getU32Encoder();
assertIsFixedSize(encoder); // Passes

Attempting to assert a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsFixedSize(encoder); // Throws SolanaError

Remarks

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

See

isFixedSize

Call Signature

assertIsFixedSize<TTo, TSize>(decoder): asserts decoder is FixedSizeDecoder<TTo, TSize>

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

If the object is not fixed-size (i.e., it lacks a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH.

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

asserts decoder is FixedSizeDecoder<TTo, TSize>

Throws

If the object is not fixed-size.

Examples

Asserting a fixed-size encoder.

const encoder = getU32Encoder();
assertIsFixedSize(encoder); // Passes

Attempting to assert a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsFixedSize(encoder); // Throws SolanaError

Remarks

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

See

isFixedSize

Call Signature

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

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

If the object is not fixed-size (i.e., it lacks a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH.

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

asserts codec is FixedSizeCodec<TFrom, TTo, TSize>

Throws

If the object is not fixed-size.

Examples

Asserting a fixed-size encoder.

const encoder = getU32Encoder();
assertIsFixedSize(encoder); // Passes

Attempting to assert a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsFixedSize(encoder); // Throws SolanaError

Remarks

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

See

isFixedSize

Call Signature

assertIsFixedSize<TSize>(codec): asserts codec is { fixedSize: TSize }

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

If the object is not fixed-size (i.e., it lacks a fixedSize property), this function throws a SolanaError with the code SOLANA_ERROR__CODECS__EXPECTED_FIXED_LENGTH.

Type Parameters

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

Parameters

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

Returns

asserts codec is { fixedSize: TSize }

Throws

If the object is not fixed-size.

Examples

Asserting a fixed-size encoder.

const encoder = getU32Encoder();
assertIsFixedSize(encoder); // Passes

Attempting to assert a variable-size encoder.

const encoder = addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder());
assertIsFixedSize(encoder); // Throws SolanaError

Remarks

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

See

isFixedSize

On this page