Crates.io | serialize_bits |
lib.rs | serialize_bits |
version | 0.1.0 |
source | src |
created_at | 2023-10-30 12:45:00.427233 |
updated_at | 2023-10-30 12:45:00.427233 |
description | Serialization/Deserialization in bits |
homepage | |
repository | https://github.com/gr3gdev/serialize-bits |
max_upload_size | |
id | 1018444 |
size | 70,465 |
Rust serializer/deserializer : Struct to bits, bits to Struct.
The library already implements the traits for :
Implement the SerializerData trait.
Example :
impl SerializerData for String {
fn to_data(&self) -> Vec<u8> {
let mut res = Vec::new();
res.append(&mut self.len().to_data());
res.append(&mut self.as_bytes().to_vec());
res
}
}
Implement the DeserializerData trait.
Example :
impl DeserializerData for String {
fn from_data(data: &Vec<u8>, index: usize) -> (Self, usize)
where
Self: Sized,
{
let (size, index) = usize::from_data(data, index);
let list = sub("String", data, index, size);
(String::from_utf8(list).unwrap(), index + size)
}
}