blob: 410bb6284716b5560c7613acf768a280fdf58a43 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
# transient-0
transient-0 is a binary encoding of hobgoblin data is for transient data where
forwards and backwards compatibility is not required, such as IPC between
different instances of the same program.
The encoder and decoder must use the same version of hobgoblin and the same data
definitions for decoding to succeed.
transient-0 does not support:
* Compatibility between different versions of hobgoblin. The exact encoding is
an implementation detail that may change between any two versions of
hobgoblin.
* Compatibility between different data definitions. For instance, if a field is
added to a struct, there is no guarantee that data encoded before the field
was added can be decoded using the new data definition.
## Encoding
This describes the current encoding of transient-0.
* `Bool`: a one-byte integer where true and false are represented by
1 and 0 respectively.
* `Int32`: a four-byte little endian integer.
* `Int64`: an eight-byte little endian integer.
* `String`: the length of the UTF-8 encoding of the string written as per
`Int64`, followed by that UTF-8 encoding.
* `Option[T]`: if `none`, encoded as per `false`, otherwise encoded as per
`true` followed by the encoding of the value as per `T`.
* `List[T]`: the number of elements in the list encoded as per `Int64`, followed
by each of the elements in the list encoded as per `T`.
* A struct is encoded by encoding each of its fields in definition order.
* An enum is encoded by the index of the variant as per `Int32`.
* A sum is encoded by the index of the variant as per `Int32` followed by the
encoding as per the type of the variant.
|