protocol_v1.org 2.9 KB

Packet Format

-------+-----+-----+-----+-----+-----------------+----------------+ | 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

Common Header

Types

Shared Flags

Handshake Packet

Forward 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 | | ------+---------------+-----------------+-----------

Flags

------+-------------------------------------------+ | flag | usage | +------+-------------------------------------------+ | ACK | This packet need a ACK response | +------+-------------------------------------------

Payload

-------+-----+-------+-----+-----+-----+-----+ | bytes | 0 | .. | n | n+1 | .. | x | +-------+-----+-------+-----+-----+-----+-----+ | | Content Length | Message Content | +-------+-------------------+-----------------

  • Content length is a variable length number.
  • Message content is a list in an opaque binary format whose element is a map structure

Message Content map structure

{ id: "0006081CCFF3D48F03C10000058B0000", // unique message id qos: 1, flags: {dup: false, retain: false}, from: "clientid", topic: "t/1", payload: "hello, world", timestamp: 1697786555281 }

Heartbeat Packet

-------+---------------+ | bytes | 0 | +-------+---------------+ | | common header | +-------+---------------