@serialpilot/parser-cobs
v0.1.0
Published
Transform-stream parser that emits one decoded payload per COBS frame (0x00 delimiter). Wraps @serialpilot/cobs.
Downloads
87
Maintainers
Readme
@serialpilot/parser-cobs
Transform-stream wrapper around @serialpilot/cobs. Buffers incoming bytes until the next 0x00 delimiter, decodes the frame, and pushes the decoded payload as a single chunk.
Install
npm install @serialpilot/parser-cobsUse
import { SerialPilot } from 'serialpilot'
import { CobsParser } from '@serialpilot/parser-cobs'
const port = new SerialPilot({ path: '/dev/ttyUSB0', baudRate: 115200 })
const frames = port.pipe(new CobsParser())
frames.on('data', (frame: Buffer) => {
// one decoded COBS payload
})Options
new CobsParser({ strict: true }) // emits 'error' on malformed frame
new CobsParser({ strict: false }) // (default) silently drops malformed framesMalformed frames are detected by @serialpilot/cobs's decode. In strict mode a CobsError is emitted via the stream's 'error' event; in non-strict mode the bad frame is dropped and parsing resumes at the next delimiter.
License
MIT.
