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.
qos >= 1
packetId
Topic, payload, QoS, and optional retain/dup/packetId.
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 }); Copy
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 });
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 supplypacketId; QoS 0 must not include one.