Skip to main content
Version: v0.0.4

Function: deframeMllp()

deframeMllp(bytes): Promise<{ payloads: Buffer<ArrayBufferLike>[]; warningCount: number; }>

De-frame an MLLP byte stream into its enclosed HL7 payloads via @cosyte/mllp's FrameReader. MLLP is a transport container, not a document format: each frame's payload is an HL7 v2 message the CLI then parses/inspects with the hl7 adapter. Multi-frame streams are the CLI's multi-message surface.

Parameters

bytes

Uint8Array

The MLLP-framed input.

Returns

Promise<{ payloads: Buffer<ArrayBufferLike>[]; warningCount: number; }>

The de-framed HL7 payloads (in stream order) + a value-free framing-warning count. Truncation is a data error, never a silent drop. The FrameReader is a streaming decoder: an unterminated trailing frame (a VT opened with no closing FS/CR) is left buffered and delivered by no callback, so feeding a whole file and reading only onFrame would silently lose the partial message with a green exit. We therefore detect an open trailing frame at the byte level (the last VT sits after the last FS: MLLP payloads are HL7 v2 text and never carry the 0x0B/0x1C framing bytes) and reject the whole stream as a value-free CLI_PARSE_FAILED data error.

Throws

CLI_PARSER_UNAVAILABLE if @cosyte/mllp is absent; CLI_PARSE_FAILED (exit 65) on a truncated stream; a hard framing error propagates for the caller's value-free boundary.

Example

import { deframeMllp } from "@cosyte/cli";

// a VT-framed "MSH|..." message → one payload
(await deframeMllp(new Uint8Array([0x0b, 0x4d, 0x53, 0x48, 0x1c, 0x0d]))).payloads.length; // => 1