Kit
Functions

assertByteArrayHasEnoughBytesForCodec

assertByteArrayHasEnoughBytesForCodec(codecDescription, expected, bytes, offset?): void

Asserts that a given byte array has enough bytes to decode (after the optional provided offset).

Returns void if the byte array has at least the expected number of bytes but throws a SolanaError otherwise.

Parameters

ParameterTypeDescription
codecDescriptionstringA description of the codec used by the assertion error.
expectednumberThe minimum number of bytes expected in the byte array.
bytesUint8Array<ArrayBufferLike> | ReadonlyUint8ArrayThe byte array to check.
offset?numberThe offset from which to start checking the byte array.

Returns

void

Example

const bytes = new Uint8Array([0x01, 0x02, 0x03]);
assertByteArrayHasEnoughBytesForCodec('myCodec', 3, bytes); // OK
assertByteArrayHasEnoughBytesForCodec('myCodec', 4, bytes); // Throws
assertByteArrayHasEnoughBytesForCodec('myCodec', 2, bytes, 1); // OK
assertByteArrayHasEnoughBytesForCodec('myCodec', 3, bytes, 1); // Throws

On this page