Skip to content

Tagged Tail

Dmitry Zavalishin edited this page Feb 14, 2019 · 12 revisions

In order to support various extensions to basic protocol, it is supposed to add Tagged Tail packet content extension.

With UDP we already know size of packet send. It means that packet length encoded according to classic MQTT protocol is not really needed when we decode packet contents.

But it can be used to mark end of packet encoded accordiong to classic MQTT and rest of the packet can be encoded in different way and carry extended information.

Tagged Tail is a set of records (TTRs) added to classic MQTT/UDP packet.

Each record is encoded as {type}{length}{content}, where length is variable length field (same as traditional MQTT packet length), type is one byte, and content is type specific. Value of length field is length of content field only.

Example

Here is PUBLISH packet with TT byte by byte:

Position (Dec) Description Data (Hex) Comment
00 packet type byte 0x30 Low byte is flags
01 packet payload len (excl TTRs) 0x10 Can take >= 1 byte
02 topic len byte (hi) 0x00 payload start
03 topic len byte (lo) 0x08
04-11 topic string ...
12-19 value string ... last payload field
20 1st TTR type 'n' TTR start
21 1st TTR len 0x04 Can take >= 1 byte
22-25 packet number ...
26 2nd TTR type 'p' TTR start
27 2nd TTR len 0x08 Can take >= 1 byte
28-35 8 byte time ...

Full length is defined by UDP packet size.

Types

If record type is A...Z (upper case letter), packet can not be decoded correctly without handling this record. It must be ignored.

n - sequential packet number

4 bytes in network order.

Mostly needed to make signature to be different for PUBLISH packets with the same value. See Java TTR_PacketNumber class.

r - number of packet that we reply to

Used when we answer to some packet. See Java TTR_ReplyTo class.

Payload is 32 bit integer in network (big endian) byte order.

s - MD5 signature

Signature covers all packet bytes that precede this record. See Java TTR_Signature class.

NB! Note that packet number or some other packet ID that is changing from packet to packet even when packet value is the same must precede signature record!

Record payload is binary signature (16 bytes), not hex string.

t - Measure time and date

Preliminary

Time and date of moment when corresponding item was measured. See Java TTR_MeasureTimeDate class.

Payload is 64 bit integer in network (big endian) byte order. Time and date encoded as number of 1 msec intervals since the Unix time_t zero (= time_t * 1000LL).

p - Protocol time and date

Preliminary

Time and date of moment when corresponding item was sent by origin. See Java TTR_ProtocolTimeDate class.

Payload is 64 bit integer in network (big endian) byte order. Time and date encoded as number of 1 msec intervals since the Unix time_t zero (= time_t * 1000LL).