Home

Serialisation Primitives

This document describes how primitive types are encoded within Dijets platform which uses a simple, uniform, and elegant representation for all internal data.

Following are the basic primitive types used when encoding a transaction.

Byte#

Bytes are packed "as is" into the message payload.

Example:


_10
Packing:
_10
0x01
_10
Results in:
_10
[0x01]

Short#

Shorts are packed in BigEndian format into the message payload.

Example:


_10
Packing:
_10
0x0102
_10
Results in:
_10
[0x01, 0x02]

Integer#

Integers are 32-bit values packed in BigEndian format into the message payload.

Example:


_10
Packing:
_10
0x01020304
_10
Results in:
_10
[0x01, 0x02, 0x03, 0x04]

Long Integers#

Long integers are 64-bit values packed in BigEndian format into the message payload.

Example:


_10
Packing:
_10
0x0102030405060708
_10
Results in:
_10
[0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08]

IP Addresses#

IP addresses are represented as 16-byte IPv6 format, with the port appended into the message payload as a Short. IPv4 addresses are padded with 12 bytes of leading 0x00s.

IPv4 example:


_10
Packing:
_10
"127.0.0.1:9650"
_10
Results in:
_10
[
_10
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
_10
0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01,
_10
0x25, 0xb2,
_10
]

IPv6 example:


_10
Packing:
_10
"[2001:0db8:ac10:fe01::]:12345"
_10
Results in:
_10
[
_10
0x20, 0x01, 0x0d, 0xb8, 0xac, 0x10, 0xfe, 0x01,
_10
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
_10
0x30, 0x39,
_10
]

Fixed-Length Array#

Fixed-length arrays, whose length is known ahead of time and by context, are packed in order.

Byte array example:


_10
Packing:
_10
[0x01, 0x02]
_10
Results in:
_10
[0x01, 0x02]

Integer array example:


_10
Packing:
_10
[0x03040506]
_10
Results in:
_10
[0x03, 0x04, 0x05, 0x06]

Variable Length Array#

The length of the array is prefixed in Integer format, followed by the packing of the array contents in Fixed Length Array format.

Byte array example:


_10
Packing:
_10
[0x01, 0x02]
_10
Results in:
_10
[0x00, 0x00, 0x00, 0x02, 0x01, 0x02]

Int array example:


_10
Packing:
_10
[0x03040506]
_10
Results in:
_10
[0x00, 0x00, 0x00, 0x01, 0x03, 0x04, 0x05, 0x06]

String#

A String is packed similarly to a variable-length byte array. However, the length prefix is a short rather than an int. Strings are encoded in UTF-8 format.

Example:


_10
Packing:
_10
"Dijets"
_10
Results in:
_10
[0x00, 0x06, 0x44, 0x69, 0x6a, 0x65, 0x74, 0x73]