Skip to content

DecodeDriver

Defined in: packages/format-core/src/decode-driver.ts:45

Drives a Decoder over a DecodeBuffer, dispatching every outcome to a DecodeSink.

This is the one engine shared by every consumption shape: decodeAll (one-shot, idle: {kind: "exhausted"}), DecodeStream (Web Streams, idle: {kind: "exhausted"} at flush time), and net/core’s FrameLink (live, idle: {kind: "timer", schedule} backed by a real clock). Before this existed, the same accumulate-and-dispatch loop was hand-written three times — Framer.drain/Framer.handleSilenceTimeout, CborSequenceDecoder, and NdjsonParseStream — each slightly differently.

Message-mode datagrams (one transport delivery = one complete value, no state carried between deliveries) are deliberately out of scope: call the decoder directly for that case, as FrameLink does. A buffer that never accumulates across calls gains nothing from this class.

T

The decoded value type.

View = Uint8Array

What the decoder reads. Matches the buffer’s view type.

Chunk = View

What write accepts. Matches the buffer’s chunk type.

W = never

The decoder’s warning type.

new DecodeDriver<T, View, Chunk, W>(options): DecodeDriver<T, View, Chunk, W>

Defined in: packages/format-core/src/decode-driver.ts:59

DecodeDriverOptions<T, View, Chunk, W>

DecodeDriver<T, View, Chunk, W>

get buffered(): number

Defined in: packages/format-core/src/decode-driver.ts:67

Unconsumed input currently held.

number

clear(): void

Defined in: packages/format-core/src/decode-driver.ts:96

Discard buffered input and decoder state, ahead of a mode switch.

void


close(): void

Defined in: packages/format-core/src/decode-driver.ts:85

No more input will ever arrive. Triggers a final decode attempt and, if the decoder is still inconclusive, reports DecodeSink.onTruncated.

void


discardBuffer(): void

Defined in: packages/format-core/src/decode-driver.ts:124

Discard buffered input without touching decoder state.

void


resync(): void

Defined in: packages/format-core/src/decode-driver.ts:108

Cancel any pending idle timer and reset the incomplete-hint, without discarding buffered input. Used ahead of an operation that changes decode semantics mid-stream (a codec or transport swap) but must keep unconsumed input for whatever reads it next.

void


swapDecoder(decoder): void

Defined in: packages/format-core/src/decode-driver.ts:118

Replace the decoder, keeping buffered input for the new one to interpret (an RTMP handshake completing, an SMTP session negotiating a new mode).

Decoder<T, View, W>

void


takeResidue(): Chunk

Defined in: packages/format-core/src/decode-driver.ts:130

Remove and return the buffered input without discarding decoder state.

Chunk


write(chunk): void

Defined in: packages/format-core/src/decode-driver.ts:72

New input arrived: append it and decode as much as possible.

Chunk

void