edgeport - v1.0.3
    Preparing search index...

    Function encodePublish

    • Encodes a PUBLISH packet.

      Places the topic in the variable header, then a packet identifier when qos >= 1, then the raw payload. The QoS, retain, and DUP bits go into the fixed-header flags nibble. A QoS 1 or 2 publish must supply packetId; QoS 0 must not include one.

      Parameters

      • opts: PublishOptions

        Topic, payload, QoS, and optional retain/dup/packetId.

      Returns Uint8Array

      The complete PUBLISH packet bytes.

      If qos >= 1 without a packetId.

      1.0.0

      import { encodePublish } from 'edgeport/mqtt';

      const enc = new TextEncoder();
      const qos0 = encodePublish({ topic: 'a/b', payload: enc.encode('hi'), qos: 0 });
      const qos1 = encodePublish({ topic: 'a/b', payload: enc.encode('hi'), qos: 1, packetId: 7 });