Crates.io | comprez_macro |
lib.rs | comprez_macro |
version | 0.2.7 |
source | src |
created_at | 2022-09-01 06:43:09.97528 |
updated_at | 2022-09-28 10:57:46.191682 |
description | Partner in crime with comprez, a library to compress structs and enums |
homepage | |
repository | https://github.com/Najidnadri/comprez_macro |
max_upload_size | |
id | 656499 |
size | 20,204 |
A rust library for compressing and decompressing structs. Note that the library is still under heavy development and breaking changes may occur.
The library is not complete yet, For now only struct with unsigned integers fields are supported. Many more will come. Stay tune.
Put this into your cargo.toml
[dependencies]
comprez_macro = 0.2.7
comprez = 0.2.7
use comprez_macro::Comprezable;
use comprez::comprezable::Comprezable;
#[derive(Comprezable, Debug, Clone)]
struct MyStruct {
[#maxNum=10000] //Compulsory for each integer field except for u8
num1: u32,
[#maxNum=888]
num2: u16,
[#maxNum=100]
num3: i8, //use i8 instead of u8
other_struct: OtherStruct,
vec1: Vec<u8>,
vec2: Vec<OtherStruct>,
enum1: MyEnum::Num5(10)
}
#[derive(Comprezable, Debug, Clone)]
struct OtherStruct {
#[maxNum=1000000]
num4: u128,
}
#[derive(Comprezable, Debug, Clone)]
enum MyEnum {
#[maxNum=100]
Num5(u32),
Vec3(Vec<u8>)
}
fn main() {
let demo_data = Mystruct {
num1: 900,
num2: 100,
num3: 10,
other_struct: OtherStruct { num4: 200 },
vec1: vec![1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
vec2: vec![OtherStruct{num4: 100}, OtherStruct{num4: 200}],
};
let compressed = demo_data.compress().unwrap();
let compressed_bytes = compressed.to_bytes();
let compressed_binaries = compressed.to_binaries();
let compressed = Compressed::from_bytes(compressed_bytes);
let compressed = Compressed::from_binaries(compressed_binaries);
let decompressed = Mystruct::decompressed(compressed).unwrap();
println!("{:?}", decompressed);
}
TODO!
Unsigned
Signed
Vec::u8
Vec of Comprezable(s)
enums
Async Write/Read
Even numbers
Strings
Slices & Vectors
Vector of u8 are compressed using LZ4 flex library.