azamcodec-rs
An encoder and decoder implementation in Rust for Azam Codec, a lexicographically sortable multi-section base16 encoding of byte array. Zero external dependencies.
License
MIT Licence Copyright (c) 2022 Azamshul Azizy
Usage
Import the crate and start using it.
Decoding
use ;
// Decode first section of Azam-encoded string as u32, using trait [`AzamDecode`] on uint type.
// "xytxvyyf" decodes to 0xdeadbeefu32, the rest of string is ignored.
let x = u32azam_decode; // 0xdeadbeefu32
// Decode multiple sections of Azam-encoded string to a tuple using azam_decode! macro.
// "xytxvyyf" decodes to 0xdeadbeefu32.
// "h5" decodes to 0x15u8.
// "wgg1" decodes to 0xc001u16.
let = azam_decode!.unwrap; // (0xdeadbeefu32, 0x15u8, c001u16)
// Decode multiple sections of Azam-encoded string into custom struct.
Encoding
use ;
// Encode u32 value as Azam-encoded string as u32, using trait [`AzamEncode`] on uint type.
// 0xdeadbeefu32 encodes to "xytxvyyf".
let x = 0xdeadbeefu32.azam_encode; // "xytxvyyf"
// Encode multiple values as Azam-encoded string, using [`azam_decode!`] macro.
// 0xdeadbeefu32 encodes to "xytxvyyf".
// 0x15u8 encodes to "h5".
// 0xc001u16 encodes to "wgg1".
let x = azam_encode!; // "xytxvyyfh5wgg1"
// Encode multiple values as Azam-encoded string from custom struct.
Development
Standard Rust development applies. Benchmark is also included, executable via cargo bench.