Skip to content

Encoding

ph0llux edited this page Feb 15, 2024 · 3 revisions

The individual data types have different encodings. The following table lists the individual data types and their respective encoding:

Note for programmers using the reference library: The encoding of the data types listed below is implemented by the "ValueEncoder" or "ValueDecoder" trait. Note that the type identifiers only be used in the Metadata extented map of logical files!

Type type identifier values (currently only used in metadata extended maps) Encoding description Example (unencoded) Example (encoded)
uint8 0 8 bit unsigned integer (or a single byte): it is stored as it is (This is just one byte). There is no special coding for this. 0x67 0x67
uint16 1 16 bit unsigned integer: This value is stored in little Endian format. 12383 0x5f30
uint32 2 32 bit unsigned integer: This value is stored in little Endian format. 123837423 0x0fbe1976
uint64 3 64 bit unsigned integer: This value is stored in little endian format. 12383323838474829183 0x7f3debe26b67daab
int8 4 64 bit signed integer: This value is stored in little endian format. TODO TODO
int16 5 64 bit signed integer: This value is stored in little endian format. TODO TODO
int32 6 64 bit signed integer: This value is stored in little endian format. TODO TODO
int64 7 64 bit signed integer: This value is stored in little endian format. 12383323838474829183 0x7f3debe26b67daab
String 8 For strings, first the length is stored encoded as uint64. The length is the number of bytes (strings are generally stored UTF-8 encoded and interpreted/expected as such). This is followed by the string itself. "hello" length: 0x0500000000000000 string: 0x68656c6c6f2a => 0x050000000000000068656c6c6f2a
HashMap<K,V> 9 A HashMap (also known as a "Dictionary" in some programming languages). Here, similar to a string, first the "length" of the HashMap is stored coded as uint64 (the length corresponds here to the number of key-value pairs). Afterwards the key-value pairs follow always alternating. Key and value can be different types, which can also be coded according to this table. HashMaps HashMap<uint64, uint64> with one key-value pair: <1234, 4321> length: 0x0100000000000000 key: 0xD204000000000000, value: 0xE110000000000000 => 0x0100000000000000D20
4000000000000E110000000000000
BTreeMap<K,V> 10 A BTreeMap (same as a HashMap, but with sorted keys). Here, similar to a string, first the "length" of the HashMap is stored coded as uint64 (the length corresponds here to the number of key-value pairs). Afterwards the key-value pairs follow always alternating. Key and value can be different types, which can also be coded according to this table. BTreeMaps BTreeMap<uint64, uint64> with one key-value pair: <1234, 4321> length: 0x0100000000000000 key: 0xD204000000000000, value: 0xE110000000000000 => 0x0100000000000000D20
4000000000000E110000000000000
bytes 11 A loose sequence of bytes. Here first the number of bytes is encoded as uint64 followed by the actual bytes. 0x1234 0x02000000000000001234
float32 12 32 bit float: This value is stored in little endian format 1.05 0x6666863f
float64 13 64 bit float: This value is stored in little endian format 1.05 TODO
Array and Vector 14 For an array/vector, the length - encoded as uint64 - of the array/vector (=number of elements) is again stored followed by the elements themselves. [u8;3] -> [1, 2, 3] 0x0300000000000000010203
bool 15 A boolean value. This is stored as a single byte. 0x00 for false, 0x01 for true. true 0x01
Tuple(A, B) - A tuple of two elements. The elements are stored in the order they appear in the tuple. (u8, u16) -> (1, 2) 0x010000000000000002

how to handle fields with an identifier

A field with an identifier is special. The following is an example of a string with identifier:

Name type length in bytes description
identifier length uint8 1 The length of the identifier, in the following field.
identifier String =identifier length The identifier itself.
length of the String uint64 8 The length of the string, in the following field.
Value (String) itself String variable The String value itself.
Clone this wiki locally