MLLP (Minimal Lower Layer Protocol) framing for HL7v2 messages.
MLLP wraps each HL7v2 message in a simple frame:
<SB>message<EB><CR>Where:
- SB (Start Block) =
0x0B - EB (End Block) =
0x1C - CR (Carriage Return) =
0x0D
See HL7 Implementation Technology Specification — Minimal Lower Layer Protocol.
Summary
Functions
Extracts complete MLLP messages from a buffer.
Wraps a message binary in an MLLP frame.
Extracts the message from an MLLP frame.
Functions
Extracts complete MLLP messages from a buffer.
Returns {messages, remaining_buffer} where messages is a list of
extracted message binaries (without MLLP framing) and remaining_buffer
contains any incomplete data that needs more bytes.
Examples
iex> HL7v2.MLLP.extract_messages(<<0x0B, "MSG1", 0x1C, 0x0D, 0x0B, "MSG2", 0x1C, 0x0D>>)
{["MSG1", "MSG2"], <<>>}
iex> HL7v2.MLLP.extract_messages(<<0x0B, "MSG1", 0x1C, 0x0D, 0x0B, "partial">>)
{["MSG1"], <<0x0B, "partial">>}
Wraps a message binary in an MLLP frame.
Examples
iex> HL7v2.MLLP.frame("MSH|...")
<<0x0B, "MSH|...", 0x1C, 0x0D>>
Extracts the message from an MLLP frame.
Returns {:ok, message} when the binary starts with SB and ends with EB+CR.
Returns {:error, :invalid_frame} otherwise.
Examples
iex> HL7v2.MLLP.unframe(<<0x0B, "MSH|...", 0x1C, 0x0D>>)
{:ok, "MSH|..."}
iex> HL7v2.MLLP.unframe("bad")
{:error, :invalid_frame}