A lightweight binary serialization library designed for high-performance operations in resource-constrained environments like sBPF programs and embedded systems.
Run:
cargo add jaguar
Or add to your Cargo.toml
:
[dependencies]
jaguar = "1.0.0"
With primitive types:
use jaguar::{JaguarSerializer, JaguarDeserializer};
let pubkey = [1u8; 32];
let mut ser = JaguarSerializer::new();
pubkey.serialize(&mut ser).unwrap();
let data = ser.finish();
let mut de = JaguarDeserializer::new(&data);
let decoded = <[u8; 32]>::deserialize(&mut de).unwrap();
With custom data structures:
use jaguar::{JaguarSerialize, JaguarDeserialize, JaguarSerializer, JaguarDeserializer};
#[derive(JaguarSerialize, JaguarDeserialize)]
struct MyData {
authority: [u8; 32],
amount: u64,
bump: u8,
}
let mut ser = JaguarSerializer::new();
let instance = MyData { /* struct field values */ }.serialize(&mut ser).unwrap();
let mut de = JaguarDeserializer::new(&instance);
let value = MyData::deserialize(&de).unwrap();
- Primitive integers (u8/i8, u16/i16, u64/i64, etc...)
- Booleans
- Floats (f32, f64)
- Strings and byte slices
- Arrays and vectors of supported types
- Custom structs
- Enums
Benchmarks on an M1 Mac Pro:
SimpleStruct
: ~60.04nsComplexStruct
: ~1.121µsVec<SimpleStruct>
: ~46.12µsVec<u8>
: ~348.49ns,Vec<i8>
: ~19.31µsVec<u16>
: ~22.01µsVec<i16>
: ~20.50µsVec<u64>
: ~22.14µsVec<i64>
: ~20.55µsVec<bool>
: ~4.07µs
SimpleStruct
: ~46.7nsComplexStruct
: ~1.153µsVec<SimpleStruct>
: ~39.4µsVec<u8>
: ~171ns,Vec<i8>
: ~11.36µsVec<u16>
: ~9.71µsVec<i16>
: ~12.09µsVec<u64>
: ~9.82µsVec<i64>
: ~11.92µsVec<bool>
: ~4.07µs
Contributions are welcome! Please read the Contributing Guide for details on the process for submitting pull requests.
This project is MIT licensed - see LICENSE for details.