| Crates.io | minibit |
| lib.rs | minibit |
| version | 0.1.1 |
| created_at | 2025-09-19 13:03:51.197764+00 |
| updated_at | 2025-09-19 13:08:07.012023+00 |
| description | Ultra-fast wire protocol for financial and low-latency messaging |
| homepage | |
| repository | https://github.com/sameteraslan/minibit |
| max_upload_size | |
| id | 1846420 |
| size | 14,144,950 |
Ultra-fast wire protocol for financial and low-latency messaging systems.
MiniBit provides zero-copy, allocation-free encoding and decoding of binary wire protocol frames with support for both fixed and variable-length fields. Designed for maximum performance in high-frequency trading, real-time systems, and other latency-critical applications.
no_std support with optional alloc+------------+---------+---------+-----------+-----------+---------+
| Magic u16 | Ver u8 | Flags u8| MsgType u16| Seq u32 | Len u32 |
+------------+---------+---------+-----------+-----------+---------+
| [HeaderExt? varint+bytes] |
| Body (Len bytes) |
| CRC32C u32 (Castagnoli) |
+-------------------------------------------------------------------+
Add to your Cargo.toml:
[dependencies]
minibit = "0.1"
use minibit::*;
// Encode a trade message
let mut buf = [0u8; 1024];
let size = messages::trade::encode(
&mut buf,
12345, // sequence number
1_000_000_000, // timestamp (ns)
50_000_000, // price (fixed-point)
100, // quantity
Some(b"AAPL"), // symbol (optional)
None, // note (optional)
)?;
// Decode the message
let (header, ts_ns, price, qty, symbol, note) = messages::trade::decode(&buf[..size])?;
assert_eq!(header.seq, 12345);
assert_eq!(symbol, Some(&b"AAPL"[..]));
use minibit::*;
let mut buf = [0u8; 256];
let mut encoder = FrameEncoder::new(&mut buf);
// Create header
let header = FrameHeader::new(1, 12345, 0); // msg_type, seq, len (updated automatically)
encoder.begin(&header)?;
// Write fixed fields
encoder.put_u64(1_000_000_000)?; // timestamp
encoder.put_i64(50_000_000)?; // price
encoder.put_u32(100)?; // quantity
// Write optional fields with presence bitmap
encoder.put_bitmap(0b01)?; // field 0 present
encoder.put_varbytes(b"AAPL")?; // symbol
// Finish with CRC32C
let frame_size = encoder.finish_crc32c()?;
// Decode
let decoder = FrameDecoder::new(&buf[..frame_size]);
let header = decoder.header()?;
decoder.verify_crc32c()?;
let mut body = decoder.body()?;
let timestamp = body.get_u64()?;
let price = body.get_i64()?;
let quantity = body.get_u32()?;
let bitmap = body.get_bitmap()?;
if bitmap & 1 != 0 {
let symbol = body.get_varbytes()?; // Zero-copy slice
}
MiniBit includes predefined message schemas:
ts_ns (u64), price (i64), qty (u32)symbol (bytes), note (bytes)ts_ns (u64), bid (i64), ask (i64), level (u8)symbol (bytes)MiniBit is optimized for minimal latency:
Actual performance depends on message complexity, hardware, and compiler optimizations.
Run benchmarks with: cargo bench
std (default): Standard library support with I/O and benchmarkslz4: LZ4 compression supportaead: ChaCha20-Poly1305 encryption supportFor no_std usage:
[dependencies]
minibit = { version = "0.1", default-features = false, features = ["alloc"] }
MiniBit automatically uses hardware acceleration when available:
MiniBit supports forward and backward compatibility:
See the examples/ directory for complete usage examples:
basic_usage.rs: High-level message encoding/decodinglow_level.rs: Manual frame constructionperformance.rs: Benchmarking and optimizationRun examples with: cargo run --example basic_usage
MiniBit includes comprehensive tests:
Run tests with: cargo test
Licensed under either of
at your option.
Contributions are welcome! Please feel free to submit a Pull Request.