Expand description
Byte stream framing: turn arbitrary read chunks into complete frames.
The parsers follow the semantics of the Node.js @serialport/parser-*
packages (their test suites are ported in this module’s tests), with these
deliberate differences:
- Time is passed in (
now: Instant) instead of using timers, so a polling read loop drives timeouts withFramer::poll/Framer::deadline. - Frames are bytes. Node’s
encodingoption (readline, regex) only changes how Node renders a frame as a string; decoding is left to the caller. - Buffers are bounded (
maxBufferSize, default 64 KiB; SLIP uses the default, byteLength and ccTalk are bounded by their frame size, ready keeps only a marker-sized tail): a stream that never completes a frame cannot grow memory forever. Delimiter, readline, regex, inter-byte timeout, packetLength and SLIP emit the full buffer as a frame; start/end drops the overlong open frame (keeping a later start marker). - Work per pushed byte is bounded: no parser rescans its whole buffer on every
push, so a stream without delimiters fed byte by byte stays linear.
regexlooks backREGEX_LOOKBACKbytes for a match that started in earlier data, and rescans the whole buffer only each time it has doubled: a longer match that arrives in pieces is still found, at the latest when the buffered text has doubled (or with the next match). - Unknown option names are rejected (a typo would otherwise silently fall back to a default); the Node names and the aliases listed on each field are accepted.
readyfinds its marker after a false start: Node resets its match on a mismatching byte without re-checking that byte, so"RREADY"never matches"READY".packetLengthscans for a multi-byte delimiter with a sliding window: Node drops the newest byte on a mismatch, so it only finds a multi-byte delimiter at stream start or right after a packet (00 ab ab bamisses0xababba). At end of stream only a started packet is flushed (Node also flushes the partial delimiter window, byte-reversed). A packet ends once it is at leastlen + packetOverheadlong, so a config where the header outgrows that cannot buffer forever.regexkeeps an incomplete UTF-8 sequence for the next chunk (Node decodes each chunk alone and turns a split character into U+FFFD). The pattern isregex_litesyntax, and capture groups are not spliced into the output the way JavaScriptString.splitdoes.- Empty frames are never emitted (Node streams drop empty pushes too).
Structs§
- Config
Error - Invalid parser options.
- Slip
Decoder - SLIP decoder with Node
SlipDecodersemantics. - Slip
Options - SLIP framing bytes (RFC 1055 defaults;
start/esc_startoptional).
Enums§
- ByteSeq
- Bytes given as a UTF-8 string or as an array of byte values.
- Framer
Config - Parser selection, as sent from JavaScript (
{ type: "readline", … }). - OneOr
Many - A number or a list of numbers (Node accepts both for
delimiter).
Constants§
- DEFAULT_
MAX_ BUFFER - Default cap on buffered, not yet framed bytes.
- REGEX_
LOOKBACK - How far back (in bytes) the
regexframer re-scans old text on every push for a match that may end in newly pushed data.
Traits§
- Framer
- A stateful framer fed with read chunks.
Functions§
- slip_
encode - SLIP-encode one packet.
bluetooth_quirkadds a leading END and skips empty packets.