Giter VIP home page Giter VIP logo

comprez_macro's Introduction

Rust Library for Compressing Structs and Enums.

A rust library for compressing and decompressing structs. Note that the library is still under heavy development and breaking changes may occur.

Description

The library is not complete yet, For now only struct with unsigned integers fields are supported. Many more will come. Stay tune.

Installation

Put this into your cargo.toml

[dependencies]
comprez_macro = 0.2.7
comprez = 0.2.7

Example

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);
}

Performance

TODO!

Features

  • Unsigned
  • Signed
  • Vec::u8
  • Vec of Comprezable(s)
  • enums
  • Async Write/Read
  • Even numbers
  • Strings
  • Slices & Vectors

Credits

  • Vector of u8 are compressed using LZ4 flex library.

A coffee?

"Buy Me A Coffee"

comprez_macro's People

Contributors

najidnadri avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.