Module nuts_bytes::doc_format
source · Expand description
Documentation: format specification
The Serde data model defines the following types:
- 14 primitive types
bool
- An
u8
value of0
is defined to befalse
. - Any other value is
true
. - Note that an
u8
value of1
is serialized fortrue
.
- An
i8
,u8
,i16
,u16
,i32
,u32
,i64
,u64
,i128
,u128
- Are serialized in big endian encoding. See the corresponding
<type>::from_be_bytes
functions for more information. - They will take up exactly 1 (for
i8
/u8
), 2 (fori16
/u16
), 4 (fori32
/u32
), 8 (fori64
/u64
) and 16 (fori128
/u128
) bytes.
- Are serialized in big endian encoding. See the corresponding
f32
,f64
- Are serialized in big endian encoding. See the corresponding
<type>::from_be_bytes
functions for more information. - They will take up exactly 4 (for
f32
) and 8 (forf64
) bytes.
- Are serialized in big endian encoding. See the corresponding
char
- Is casted into a
u32
for serialization. - Note that not all
u32
s are validchar
s, so deserialization might fail.
- Is casted into a
- string
- Serializes the number of bytes as an
u64
value followed by the byte data itself.
- Serializes the number of bytes as an
- byte array -
[u8]
- Similar to strings, serializes the number of bytes as an
u64
value followed by the byte data itself.
- Similar to strings, serializes the number of bytes as an
- option
- unit
- No data are required here.
- unit_struct
- No data are required here.
- unit_variant
- The index of the variant is encoded as an
u32
value.
- The index of the variant is encoded as an
- newtype_struct
- The wrapped value is serialized.
- newtype_variant
- The index of the variant is serialized as an
u32
value followed by wrapped, serialized value.
- The index of the variant is serialized as an
- seq
- Serializes the number of elements as an
u64
value followed by serialized elements itself.
- Serializes the number of elements as an
- tuple
- Serializes the elements of the tuple one after the other.
- tuple_struct
- Serializes the wrapped elements of the tuple struct one after ther other.
- tuple_variant
- The index of the variant is serialized as an
u32
value followed by wrapped, serialized values.
- The index of the variant is serialized as an
- map
- Serializes the number of elements in the map as an
u64
value followed by (key, value) pair of all elements. - Note that iterating over a map does not preserve the order. So, serializing a map a second time can change to order.
- Serializes the number of elements in the map as an
- struct
- Serializes the fields of the struct in the order in which they were defined.
- struct_variant
- The index of the variant is serialized as an
u32
value followed by wrapped, serialized fields in the order in which the were defined.
- The index of the variant is serialized as an