@qualithm/mqtt-wire - v0.1.5
    Preparing search index...

    Class StreamFramer

    A buffer that accumulates chunks and extracts complete packets.

    This class handles the complexity of MQTT framing over a byte stream:

    • Accumulates incoming chunks
    • Extracts complete packets
    • Manages partial packet state
    const framer = new StreamFramer()

    // Receive chunks from transport
    for (const chunk of chunks) {
    framer.push(chunk)

    // Extract all complete packets
    while (true) {
    const result = framer.read()
    if (result.status === 'incomplete') break
    if (result.status === 'error') throw new Error(result.error.message)

    handlePacket(result.packetData)
    }
    }
    Index

    Constructors

    Accessors

    Methods

    Constructors

    Accessors

    • get bufferedLength(): number

      Gets the number of buffered bytes.

      Returns number

    Methods

    • Pushes a chunk of data into the buffer.

      Parameters

      • chunk: Uint8Array

        The data chunk to add

      Returns void

    • Attempts to read a complete packet from the buffer.

      If a complete packet is available, it is removed from the buffer and returned. If not enough data is available, returns incomplete. If the data is malformed, returns an error.

      Returns FrameResult

      Frame result