BSON
BSON allows saving precious bytes compared to JSON, while offering the advantages of a schema-less protocol.
Consider, for example, a simple value and timestamp payload. The encoded JSON version, {"v":25.367812,"t":1537346756844} counts 33 bytes.
The hexdump of the same message encoded with BSON is:
0000000 1b 00 00 00 09 74 00 ec e0 01 f1 65 01 00 00 01
0000020 76 00 8c 13 5f ed 28 5e 39 40 00
that fits just in 27 bytes.
BSON format
BSON is a really simple binary format, breaking down the previous example is very easy thanks to BSON simplicity: the first 4 bytes (1b 00 00 00) are the document size header, follows the timestamp marker (09), the timestamp key name (74 00, that is "t"), the timestamp value (5f 48 06 f1 65 01 00 00 as int64), the double value marker (01), the value key name (76 00, that is "v"), the actual value (cd cc cc cc cc 4c 39 40 as 64-bit IEEE 754-2008 floating point) and the end of document marker (00).
Data Orchestrator payload standard fields
| Key | Type | Mandatory | Description |
|---|---|---|---|
| v | Any Data Orchestrator type | Yes | The value being sent (both properties and datastream) |
| t | UTC datetime | No | Explicit timestamp, if present (optional, datastream only) |
Data Orchestrator data types to BSON types
| Data Orchestrator Data Type | BSON Type | Size in Bytes |
|---|---|---|
| double | double (0x01) | 8 |
| integer | int32 (0x10) | 4 |
| boolean | boolean (0x08) | 1 |
| longinteger | int64 (0x12) | 8 |
| string | UTF-8 string (0x02) | ≥ length (encoding dependent) |
| binaryblob | binary (0x05) | length |
| datetime | UTC datetime (0x09) | 8 |
| doublearray | Array (0x04) | (8 + keysize) × count |
| integerarray | Array (0x04) | (4 + keysize) × count |
| booleanarray | Array (0x04) | (1 + keysize) × count |
| longintegerarray | Array (0x04) | (1 + keysize) × count |
| stringarray | Array (0x04) | depends on count, length, keys length and encoding |
| binaryblobarray | Array (0x04) | depends on count, keys length and length |
integer and long integer are signed integer values, double must be a valid number (+inf, NaN, etc... are not supported), variable data types might be subject to size limitations and object aggregations are encoded as embedded documents.