12 releases
Uses new Rust 2024
| 0.2.1 | Dec 29, 2025 |
|---|---|
| 0.2.0 | Dec 29, 2025 |
| 0.1.4 | Dec 29, 2025 |
#840 in Parser implementations
Used in can-viewer
650KB
12K
SLoC
mdf4-rs
A safe, efficient Rust library for reading and writing ASAM MDF 4 (Measurement Data Format) files.
Features
- 100% safe Rust -
#![forbid(unsafe_code)] - Minimal dependencies - Only
serde/serde_jsonfor serialization - Memory efficient - Streaming index for large files (335x faster, 50x less memory)
- Full read/write - Create, read, and modify MDF4 files
- CAN logging - Integrated CAN bus data logging with DBC support
Quick Start
[dependencies]
mdf4-rs = "0.2"
Reading
use mdf4_rs::MDF;
let mdf = MDF::from_file("recording.mf4")?;
for group in mdf.channel_groups() {
for channel in group.channels() {
let values = channel.values()?;
println!("{}: {} samples", channel.name()?.unwrap_or_default(), values.len());
}
}
Writing
use mdf4_rs::{MdfWriter, DataType};
let mut writer = MdfWriter::new("output.mf4")?;
writer.init_mdf_file()?;
let cg = writer.add_channel_group(None, |_| {})?;
writer.add_channel(&cg, None, |ch| {
ch.data_type = DataType::FloatLE;
ch.name = Some("Temperature".into());
ch.bit_count = 64;
})?;
// ... write data
CAN Logging
use mdf4_rs::can::CanDbcLogger;
let dbc = dbc_rs::Dbc::parse(dbc_content)?;
let mut logger = CanDbcLogger::builder(&dbc).build()?;
logger.log(0x100, timestamp_us, &frame_data);
let mdf_bytes = logger.finalize()?;
Minimal (no_std)
[dependencies]
mdf4-rs = { version = "0.2", default-features = false, features = ["alloc"] }
See examples/ for complete working examples:
read_file.rs- Reading MDF4 fileswrite_file.rs- Creating MDF4 filescan_logging.rs- CAN bus logging with DBC supportethernet_logging.rs- Ethernet frame logginglin_logging.rs- LIN bus loggingflexray_logging.rs- FlexRay bus loggingindex_operations.rs- Efficient file indexingmerge_files.rs- Merging multiple MDF4 filescut_file.rs- Extracting time segmentsno_std_write.rs- Writing MDF4 in no_std environments
Feature Flags
| Feature | Description | Default |
|---|---|---|
std |
Standard library with serde/serde_json | Yes |
alloc |
Heap allocation | Via std |
can |
CAN bus support via embedded-can |
Yes |
dbc |
DBC decoding via dbc-rs |
Yes |
serde |
Serialization support | Via std |
compression |
DZ block decompression via miniz_oxide |
No |
Documentation
- API Reference
- ARCHITECTURE.md - Internal design
License
MIT OR Apache-2.0. See LICENSING.md.
Dependencies
~0–530KB
~11K SLoC