edgeport - v1.0.3
    Preparing search index...

    Function decodePacket

    • Decodes one complete MQTT control packet from a buffer.

      Reads the fixed header, then dispatches on the packet type to parse the variable header and payload, returning a DecodedPacket discriminated on type. The buffer must hold exactly one full packet starting at offset 0; callers framing a stream should use decodeRemainingLength to size each packet before slicing it out. A CONNACK is decoded loosely so a v5 broker's extra trailing bytes (properties) are ignored rather than rejected.

      Parameters

      • bytes: Uint8Array

        A buffer beginning with a single complete packet.

      Returns DecodedPacket

      The decoded packet.

      If the header is malformed or the type is unsupported.

      1.0.0

      import { decodePacket, PacketType } from 'edgeport/mqtt';

      const pkt = decodePacket(new Uint8Array([0x20, 0x02, 0x00, 0x00]));
      if (pkt.type === PacketType.CONNACK) console.log(pkt.returnCode); // 0