-------+-----+-----+-----+-----+-----------------+----------------+
| bytes | 0 | 1 | 2 | 3 | 5 | 6 .. end |
+-------+-----+-----+-----+-----+-----------------+----------------+
| | variable length | common header | payload |
+-------+-----------------------+-----------------+----------------
The length of the remaining part(common header + payload) is indicated by the Length Header of each packet
------+-----+-----+-----+-----+-----+-----+-----+-----+
| bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
+------+-----+-----+-----+-----+-----+-----+-----+-----+
| | packet type | shared flags |
+------+-----------------------+-----------------------+
+----------+-----------+
| type | usage |
+----------+-----------+
| 0 | handshake |
+----------+-----------+
| 1 | forward |
+----------+-----------+
| 2 | heartbeat |
+----------+-----------+
The usage of each bit is determined by the type of packet
+-------+---------------+---------------+
| bytes | 0 | 1 |
+-------+---------------+---------------+
| | common header | version |
+-------+---------------+---------------+
+------+---+---+---+---+---+---+---+-----+-----------+
| bits | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | ... |
+------+---+---+---+---+---+---+---+-----+-----------+
| | | | ACK | |
| | packet type +-----------+----- payload |
| | | forward flags | |
------+---------------+-----------------+-----------
------+-------------------------------------------+
| flag | usage |
+------+-------------------------------------------+
| ACK | This packet need a ACK response |
+------+-------------------------------------------
-------+-----+-------+-----+-----+-----+-----+
| bytes | 0 | .. | n | n+1 | .. | x |
+-------+-----+-------+-----+-----+-----+-----+
| | Content Length | Message Content |
+-------+-------------------+-----------------
{ id: "0006081CCFF3D48F03C10000058B0000", // unique message id qos: 1, flags: {dup: false, retain: false}, from: "clientid", topic: "t/1", payload: "hello, world", timestamp: 1697786555281 }
-------+---------------+
| bytes | 0 |
+-------+---------------+
| | common header |
+-------+---------------