#arithmetic-coding #lossless #encoding

nightly minnow

A library and derive macro for extremely compact encoding of structs using arithmetic coding

1 unstable release

0.1.0 Aug 6, 2022

#13 in #arithmetic-coding

GPL-3.0 license

24KB
573 lines

Minnow

Minnow is a library for serialising objects into extremely compact binary representations using arithmetic coding.

Minnow is a derive macro and convenience layer over the Arithmetic-Coding library.

use minnow::Encodeable;

#[derive(Debug, Encodeable, PartialEq)]
pub struct NavigationReport {
    #[encode(float(min = -10_000.0, max = 10_000.0, precision = 1))]
    pub x: f64,
    #[encode(float(min = -10_000.0, max = 10_000.0, precision = 1))]
    pub y: f64,
    #[encode(float(min = -5_000.0, max = 0.0, precision = 0))]
    pub z: f64,
    pub vehicle_class: Option<VehicleClass>,
    pub battery_ok: Option<bool>,
}

#[derive(Debug, Encodeable, PartialEq)]
pub enum VehicleClass {
    Auv,
    Usv,
    Ship,
}

let input = NavigationReport {
    x: 450.0,
    y: 550.0,
    z: -100.0,
    vehicle_class: Some(VehicleClass::Auv),
    battery_ok: Some(true),
};

let compressed = input.encode_bytes().unwrap();
let output = NavigationReport::decode_bytes(&compressed).unwrap();

assert_eq!(input, output);

Minnow was originally conceived as a library for creating compact messages for underwater acoustic communications. It is heavily inspired by Dynamic Compact Control Language (DCCL)

Licensing

This project is publicly available under the GNU General Public License v3.0. It may optionally be distibruted under the permissive MIT license by commercial arrangement.

Dependencies

~1.1–1.7MB
~30K SLoC