Crate comprez

Crate comprez 

Source
Expand description

§Description

Comprez is a compression library for compressing any struct and enums

§Example

 
use comprez_macro::Comprezable;
use comprez::comprezable::Comprezable;   
 
#[derive(Comprezable, Debug)]
struct MyStruct {
    #[maxNum=10000] //Compulsory for each field
    num1: u32,
    #[maxNum=888]
    num2: u16,
    #[maxNum=100] //from -100 to 100
    num3: i8,//use i8 instead of u8
    other_struct: OtherStruct,
    vec1: Vec<u8>,
    vec2: Vec<OtherStruct>,
    #[maxNum=200] 
    vec3: Vec<u16>
}
 
#[derive(Comprezable, Debug)]
struct OtherStruct {
    #[maxNum=1000000]
    num4: u128,
}

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}],
        vec3: vec[11, 12, 13, 14],
    };
     
    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);
}

§Note

Since the compression of Vec uses LZ4 flex crate, compressing small vectors might increase the space instead. However in the future, self implementation will be created.

Modules§

comprezable
Trait for compressing structs
error

Enums§

BinaryChunk
Compressed
Wrapper for compression results and decompression arguments