Class: FrameReader
Stateful MLLP frame decoder. Feed raw TCP byte chunks via push(chunk).
Complete frames fire synchronously via onFrame callback during push().
The decoder operates as a 3-state FSM:
SCANNING_FOR_VT, waiting for the 0x0B frame-start byteREADING_PAYLOAD, accumulating payload bytes until FS (0x1C)EXPECTING_CR, received FS, waiting for CR (0x0D) to complete the frame
Example
const reader = new FrameReader({
onFrame: (payload, byteOffset, warnings) => process(payload, byteOffset, warnings),
onWarning: (w) => logger.warn(w),
});
socket.on('data', (chunk) => reader.push(chunk));
Constructors
Constructor
new FrameReader(
opts):FrameReader
Construct a chunked MLLP frame reader.
Parameters
opts
Reader options (onFrame/onWarning callbacks, tolerance, maxFrameSizeBytes).
Returns
FrameReader
Methods
push()
push(
chunk):void
Feed a chunk of raw TCP bytes into the FSM. Frames fire synchronously via onFrame
during this call. May throw MllpFramingError for unrecoverable framing violations
when the matching tolerance is not enabled.
Parameters
chunk
Buffer
Returns
void
Example
socket.on('data', (chunk) => reader.push(chunk));
reset()
reset():
void
Clear internal accumulator state and reset byte offset to 0.
Call on reconnect / connection reuse to start fresh without allocating a new reader. Pending partial frame state is discarded silently.
Returns
void
Example
socket.on('close', () => reader.reset());