Expand description
Ultra fast binary serialization and deserialization for types with a constant size (known at compile time). This
crate cannot be used to serialize or deserialize dynamically allocated types, such as,
String, Vec, HashMap, etc., and types
with unknown size at compile time such as slice, &str, etc.
§Binary Encoding Scheme
This crate uses a minimal binary encoding scheme such that the size of encoded object will be smaller than (in cases
where Rust adds padding bytes for alignment) or equal to it’s size in a running Rust program. For example, consider
the following struct:
struct MyStruct {
a: u8,
b: u16,
}Desse::serialize will serialize this struct in [u8; 3] where 3 is the sum of sizes of u8 and u16.
§Usage
Desse trait can be implemented for any struct or enum (whose size is known at compile time) using derive macro.
This crate also provides a derive macro for implementing DesseSized trait which is necessary for implementing
Desse trait.
use desse::{Desse, DesseSized};
#[derive(Debug, PartialEq, Desse, DesseSized)]
struct MyStruct {
a: u8,
b: u16,
}Now, you can use Desse::serialize and Desse::deserialize_from for serialization and deserialization of this
struct.
let my_struct = MyStruct { a: 5, b: 1005 };
let serialized: [u8; 3] = my_struct.serialize();
let new_struct = MyStruct::deserialize_from(&serialized);
assert_eq!(my_struct, new_struct);Note that Desse::serialize returns an array of fixed length (3 in above case) and Desse::deserialize takes
reference to an array of fixed length as argument.
Traits§
- Desse
- Any type must implement this trait for serialization and deserialization
- Desse
Sized - Helper trait used to compute
SIZEof a type at compile time
Functions§
- max
- Compares and returns maximum of two values.