Kit
Functions

assertByteArrayOffsetIsNotOutOfRange

assertByteArrayOffsetIsNotOutOfRange(codecDescription, offset, bytesLength): void

Asserts that a given offset is within the byte array bounds. This range is between 0 and the byte array length and is inclusive. An offset equals to the byte array length is considered a valid offset as it allows the post-offset of codecs to signal the end of the byte array.

Parameters

ParameterTypeDescription
codecDescriptionstringA description of the codec used by the assertion error.
offsetnumberThe offset to check.
bytesLengthnumberThe length of the byte array from which the offset should be within bounds.

Returns

void

Example

const bytes = new Uint8Array([0x01, 0x02, 0x03]);
assertByteArrayOffsetIsNotOutOfRange('myCodec', 0, bytes.length); // OK
assertByteArrayOffsetIsNotOutOfRange('myCodec', 3, bytes.length); // OK
assertByteArrayOffsetIsNotOutOfRange('myCodec', 4, bytes.length); // Throws

On this page