| Crates.io | fbe |
| lib.rs | fbe |
| version | 0.2.0 |
| created_at | 2025-10-21 22:54:44.530918+00 |
| updated_at | 2025-10-25 22:32:43.871093+00 |
| description | Fast Binary Encoding (FBE) for Rust - High-performance, zero-copy binary serialization with 100% C++ FBE parity and binary compatibility |
| homepage | https://github.com/panilux/fbe-rust |
| repository | https://github.com/panilux/fbe-rust |
| max_upload_size | |
| id | 1894577 |
| size | 293,282 |
High-performance, zero-copy binary serialization library for Rust, fully compatible with the Fast Binary Encoding specification.
Add this to your Cargo.toml:
[dependencies]
fbe = "0.1"
Or use cargo:
cargo add fbe
use fbe::{WriteBuffer, ReadBuffer};
#[derive(Debug, Clone, PartialEq)]
pub struct Order {
pub id: i32,
pub symbol: String,
pub price: f64,
pub quantity: i32,
}
impl Default for Order {
fn default() -> Self {
Self {
id: 0,
symbol: String::new(),
price: 0.0,
quantity: 0,
}
}
}
// Create order
let order = Order {
id: 123,
symbol: "AAPL".to_string(),
price: 150.50,
quantity: 100,
};
// Serialize
let mut buffer = WriteBuffer::new();
buffer.reserve(100);
buffer.write_i32(0, order.id);
buffer.write_string(4, &order.symbol);
buffer.write_f64(8 + order.symbol.len(), order.price);
buffer.write_i32(16 + order.symbol.len(), order.quantity);
// Get binary data
let binary = buffer.data();
// Create read buffer
let mut buffer = ReadBuffer::new();
buffer.attach_buffer(binary, 0, binary.len());
// Deserialize
let id = buffer.read_i32(0);
let symbol = buffer.read_string(4);
let price = buffer.read_f64(8 + symbol.len());
let quantity = buffer.read_i32(16 + symbol.len());
let order = Order { id, symbol, price, quantity };
bool - Boolean (1 byte)u8 - Unsigned byte (1 byte)i8, u8 - 8-bit integersi16, u16 - 16-bit integersi32, u32 - 32-bit integersi64, u64 - 64-bit integersf32 - 32-bit floating pointf64 - 64-bit floating pointVec<u8> - Binary data (bytes)Decimal - High-precision decimal (16 bytes)String - UTF-8 stringu64 - Unix timestamp[u8; 16] - UUID[T; N] - Fixed-size arrayVec<T> - Dynamic vectorVec<T> - ListBTreeMap<K, V> - Ordered mapHashMap<K, V> - Hash map#[derive(Debug, Clone)]
pub struct Person {
pub name: String,
pub age: i32,
}
#[derive(Debug, Clone)]
pub struct Employee {
pub person: Person, // Embedded base
pub company: String,
pub salary: f64,
}
#[derive(Debug, Clone)]
pub struct Manager {
pub employee: Employee, // Embedded base
pub team_size: i32,
}
use std::collections::HashMap;
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct Order {
pub id: i32,
pub symbol: String,
pub price: i32, // Use integer for hash
}
impl Order {
pub fn key(&self) -> i32 {
self.id
}
}
// Use in HashMap
let mut orders: HashMap<i32, Order> = HashMap::new();
orders.insert(order.key(), order);
#[derive(Debug, Clone)]
pub struct Config {
pub timeout: i32,
pub name: String,
pub enabled: bool,
pub threshold: f64,
}
impl Default for Config {
fn default() -> Self {
Self {
timeout: 30,
name: "Default".to_string(),
enabled: true,
threshold: 0.95,
}
}
}
Model - With 4-byte size header (versioning support):
let mut buffer = WriteBuffer::new();
let size = product.serialize_model(&mut buffer); // Includes 4-byte header
FinalModel - Without header (maximum performance):
let mut buffer = WriteBuffer::new();
let size = product.serialize_final(&mut buffer); // No header, compact
[4-byte size][struct data]
Example: 1e 00 00 00 7b 00 00 00 ... (30 bytes)
^header ^data
[struct data]
Example: 7b 00 00 00 ... (26 bytes)
^data only
FBE Rust is 100% binary compatible with:
# Run all tests
cargo test
# Run with output
cargo test -- --nocapture
# Run specific test suite
cargo test --test test_types
cargo test --test test_enum
cargo test --test test_flags
# Run benchmarks
cargo bench
97 comprehensive tests covering:
100% passing - All 97 tests verified ✅
✅ 100% FBE C++ Spec Compliant
See FBE_SPEC_COMPLIANCE.md and FBE_COMPREHENSIVE_TEST_REPORT.md for detailed documentation.
See the examples/ directory for complete examples:
# Run basic example
cargo run --example basic
# Run inheritance example
cargo run --example inheritance
# Run cross-platform example
cargo run --example cross_platform
# Generate and open documentation
cargo doc --open
This project is licensed under the MIT License - see the LICENSE file for details.