UNPKG

webserial-core

Version:

A strongly-typed, event-driven, abstract TypeScript library for the Web Serial API with custom parsers, command queue, handshake validation, and auto-reconnect.

24 lines (23 loc) 795 B
import { SerialParser } from '../types/index.js'; /** * Creates a fixed-length parser that buffers bytes and emits * `Uint8Array` chunks of exactly `length` bytes. * * Excess bytes are retained in the internal buffer for the next emission. * * @param length - The exact number of bytes per emitted chunk. Must be > 0. * @returns A {@link SerialParser} that emits `Uint8Array` values. * @throws {Error} If `length` is not a positive integer. * * @example * ```ts * import { AbstractSerialDevice, fixedLength } from 'webserial-core'; * * class SensorDevice extends AbstractSerialDevice<Uint8Array> { * constructor() { * super({ baudRate: 115200, parser: fixedLength(8) }); * } * } * ``` */ export declare function fixedLength(length: number): SerialParser<Uint8Array>;