Expand description
Documentation: format specification
The crate supports conversion for the following 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
If the derive
feature is enabled, struct
and enum
type can also be converted:
- struct
- Serializes the fields of the struct in the order in which they were defined.
- enum
- The index of the variant is serialized as an
u64
value followed by wrapped, serialized value.
- The index of the variant is serialized as an