Repository navigation
Data Serialization Format
-
u8,i8,f32,f64are encoded in little-endian bytes order. -
u16,u32,u64,u128,usizeare encoded in LEB128 -
i16,i32,i64,i128,isizeare first encoded withZigZagcode, which transforms signed integers into unsigned integers with a smaller range, and then they are further encoded using LEB128
Boolean value encoded in a single byte.
-
falseis represented by the value0 -
trueis represented by the value1
The Result<T, E> type is a Tagged Union type that can represent either a value of type T or an error value of type E. Also Option<T> can represent either a value of type T or the absence of a value.
The first byte of the encoded value is used as a discriminant to indicate which variant of the type is being represented.
For the Result<T, E> type, a discriminant value of 1 indicates that the computation succeeded and 0 indicates that the computation failed.
For the Option<T> type, a discriminant value of 0 indicates that the computation returned no value, and 1 indicates that the computation returned some value.
For both tuples and array, The length is not encoded. And each value is encoded sequentially.
Examples of collections are String, BTreeSet, HashSet, BinaryHeap, LinkedList, VecDeque, Vec, HashMap, BTreeMap.
First the length of the collection is encoded using BEU30, It is a variable-length encoder type for non-negative integer values.
Then each entry is encoded sequentially. For String type, the actual data in encoded using UTF-8 format.