Skip to content

ByteCursor

Defined in: packages/format-core/src/byte-cursor.ts:19

Sequential reader over a possibly non-contiguous byte sequence.

All methods are relative to an internal cursor, reset to position 0 before each decode attempt by whatever DecodeDriver owns the backing ChunkListBuffer — a decoder still reports consumed, so the single DecodeResult contract holds whether the backing is contiguous or not. peek* inspects without advancing; read* advances. Absolute positions are never exposed, so a decoder written against this interface is agnostic to the backing layout.

Named ByteCursor, not ByteReader — @ac-kit/core already exports a concrete ByteReader over a single contiguous Uint8Array (used by the ASN.1 codecs); this is an unrelated type for an unrelated problem (decoding over a chunk list without a single contiguous copy).

readonly remaining: number

Defined in: packages/format-core/src/byte-cursor.ts:21

Unread bytes remaining.

contiguous(length): Uint8Array<ArrayBufferLike> | null

Defined in: packages/format-core/src/byte-cursor.ts:50

Contiguous window over the next length bytes when the backing allows it, otherwise null. Lets a hot decoder take a zero-copy fast path and fall back to readBytes only when a value straddles a chunk boundary.

number

Uint8Array<ArrayBufferLike> | null


indexOf(needle, from?): number

Defined in: packages/format-core/src/byte-cursor.ts:27

Index of needle relative to the cursor, or -1.

number | Uint8Array<ArrayBufferLike>

number

number


peekByte(offset): number | undefined

Defined in: packages/format-core/src/byte-cursor.ts:24

Byte at offset from the cursor, or undefined past the end.

number

number | undefined


peekBytes(length): Uint8Array

Defined in: packages/format-core/src/byte-cursor.ts:30

Copy length bytes from the cursor without advancing.

number

Uint8Array


readBytes(length): Uint8Array

Defined in: packages/format-core/src/byte-cursor.ts:33

Copy length bytes and advance the cursor.

number

Uint8Array


readString(length, encoding?): string

Defined in: packages/format-core/src/byte-cursor.ts:40

Decode length bytes as text and advance the cursor.

number

TextEncodingName

Defaults to "utf-8".

string


skip(length): void

Defined in: packages/format-core/src/byte-cursor.ts:43

Advance the cursor without copying.

number

void