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

    Class PacketIdAllocator

    Allocates and recycles packet identifiers.

    Uses sequential allocation with wraparound at 65535. Freed IDs are immediately available for reuse. When all IDs are exhausted, throws PacketIdExhaustedError (should not happen with proper flow control).

    const allocator = new PacketIdAllocator()
    const id1 = allocator.allocate() // 1
    const id2 = allocator.allocate() // 2
    allocator.release(id1) // 1 is now available
    const id3 = allocator.allocate() // 3 (sequential continues)
    Index

    Constructors

    Accessors

    • get count(): number

      Get the count of currently in-use packet IDs.

      Returns number

    Methods

    • Allocate the next available packet ID.

      Returns number

      The allocated packet ID (1-65535)

      PacketIdExhaustedError if all IDs are in use

    • Get all in-use packet IDs (for session persistence).

      Returns ReadonlySet<number>

    • Check if a packet ID is currently in use.

      Parameters

      • id: number

        The packet ID to check

      Returns boolean

      true if the ID is in use

    • Release a packet ID for reuse.

      Parameters

      • id: number

        The packet ID to release

      Returns void

    • Restore in-use IDs (for session restoration).

      Parameters

      • ids: Iterable<number>

        Set of packet IDs to mark as in-use

      Returns void