Decode an MQTT packet from binary data.
The version parameter is used for packets where the version affects the encoding (e.g., properties in 5.0). For CONNECT packets, the version is determined from the packet itself.
Buffer containing the packet
Protocol version (default: "5.0")
Starting offset in buffer (default: 0)
Decoded packet and bytes read
const result = decodePacket(buffer, "5.0")if (result.ok) { console.log(result.value.packet.type)} Copy
const result = decodePacket(buffer, "5.0")if (result.ok) { console.log(result.value.packet.type)}
Decode an MQTT packet from binary data.
The version parameter is used for packets where the version affects the encoding (e.g., properties in 5.0). For CONNECT packets, the version is determined from the packet itself.