Htsmsgbinary » History » Version 3
Andreas Smas, 2010-12-08 21:38
| 1 | 1 | Andreas Smas | |
|---|---|---|---|
| 2 | 3 | Andreas Smas | h1. Message structure |
| 3 | 1 | Andreas Smas | |
| 4 | 3 | Andreas Smas | |
| 5 | A message can be of either *map* or *list* type. In a *map* each field has a name, in a *list* the members do not have names, but the order should be preserved. |
||
| 6 | |||
| 7 | 1 | Andreas Smas | The field types are: |
| 8 | |||
| 9 | ||Name||ID||Description |
||
| 10 | ||Map||1||Sub message of type map |
||
| 11 | ||S64||2||Signed 64bit integer |
||
| 12 | ||Str||3||UTF-8 encoded string |
||
| 13 | ||Bin||4||Binary blob |
||
| 14 | ||List||5||Sub message of type list |
||
| 15 | |||
| 16 | 3 | Andreas Smas | All in all the message structure is quite similar to JSON but most notably; no *boolean* nor *null* type exist and HTSMSG supports *binary* objects. |
| 17 | 1 | Andreas Smas | |
| 18 | |||
| 19 | 3 | Andreas Smas | h1. HTSMSG binary format |
| 20 | |||
| 21 | |||
| 22 | 1 | Andreas Smas | The binary format is designed to for back-to-back transmission of messages over a network (TCP) connection. |
| 23 | |||
| 24 | 3 | Andreas Smas | The root message must always be of type *map*. |
| 25 | 2 | Andreas Smas | |
| 26 | 1 | Andreas Smas | |
| 27 | 3 | Andreas Smas | h2. Root body |
| 28 | |||
| 29 | |||
| 30 | 1 | Andreas Smas | ||Length||4 byte integer||Total length of message (including this length field itself) |
| 31 | ||Body||HTSMSG-Field * N||Fields in the root body |
||
| 32 | |||
| 33 | |||
| 34 | 3 | Andreas Smas | h2. HTSMSG-Field |
| 35 | |||
| 36 | |||
| 37 | 1 | Andreas Smas | ||Type||1 byte integer||Type of field (see field type IDs above) |
| 38 | ||Namelength||1 byte integer||Length of name of field. If a field is part of a list message this must be 0 |
||
| 39 | ||Datalength||4 byte integer||Length of field data |
||
| 40 | ||Name||N bytes||Field name, length as specified by Namelength |
||
| 41 | ||Data||N bytes||Field payload, for details see below |
||
| 42 | |||
| 43 | |||
| 44 | 3 | Andreas Smas | h3. Field encoding for type: map and list |
| 45 | |||
| 46 | |||
| 47 | 1 | Andreas Smas | The data is repeated HTSMSG-Fields exactly as the root body. Note the subtle difference in that for the root-message the length includes the 4 bytes of length field itself whereas in the field encoding the length written includes just the actual payload. |
| 48 | |||
| 49 | |||
| 50 | 3 | Andreas Smas | h3. Field encoding for type: s64 |
| 51 | |||
| 52 | |||
| 53 | 1 | Andreas Smas | Integers are encoded using a very simple variable length encoding. All leading bytes that are 0 is discarded. So to encode the value 100, datalength should be 1 and the data itself should be just one byte [0x64]. To encode 1337; datalength=2, data=[0x05 0x39]. |
| 54 | |||
| 55 | Note that there is no sign extension in this encoding scheme so if you need to encode -1 you need to set datalength=8 and data = [0xff 0xff 0xff 0xff 0xff 0xff 0xff 0xff]. This can certainly be thought of as a bug, but it is the way it is. |
||
| 56 | |||
| 57 | |||
| 58 | 3 | Andreas Smas | h3. Field encoding for type: str |
| 59 | |||
| 60 | |||
| 61 | 1 | Andreas Smas | Datalength should be the length of the string (NOT including the null terminating character). Thus the null terminator should not be present in data either. |
| 62 | |||
| 63 | 3 | Andreas Smas | |
| 64 | h3. Field encoding for type: bin |
||
| 65 | |||
| 66 | 1 | Andreas Smas | |
| 67 | Datalength should be the length of the binary object. Data is the binary object itself. |
||
| 68 | |||
| 69 |