| Crates.io | can-dbc |
| lib.rs | can-dbc |
| version | 8.1.0 |
| created_at | 2018-12-09 20:37:26.637289+00 |
| updated_at | 2026-01-23 06:59:58.403018+00 |
| description | A parser for the DBC format. The DBC format is used to exchange CAN network data. |
| homepage | |
| repository | https://github.com/oxibus/can-dbc |
| max_upload_size | |
| id | 100994 |
| size | 510,287 |
A CAN-dbc format parser written with Rust's Pest grammar library. CAN databases are used to exchange details about a CAN network, e.g. what messages are being send over the CAN bus and what data do they contain.
Read dbc file and generate Rust structs based on the messages/signals defined in the dbc.
use std::fs;
use can_dbc::Dbc;
use codegen::Scope;
fn main() {
let data = fs::read_to_string("./examples/sample.dbc").expect("Unable to read input file");
let dbc = Dbc::try_from(data.as_str()).expect("Failed to parse dbc file");
let mut scope = Scope::new();
for msg in dbc.messages {
let msg_struct = scope.new_struct(&msg.name);
for signal in msg.signals {
msg_struct.field(&signal.name.to_lowercase(), "f64");
}
}
println!("{}", scope.to_string());
}
For a proper implementation for reading or writing CAN frames according to the DBC, I recommend you take a look at dbc-codegen.
The file parser simply parses a dbc input file and prints the parsed content.
cargo run --example file_parser -- --input examples/sample.dbc
versionnew_symbolsbit_timing (deprecated but mandatory)nodesvalue_tablesmessagesmessage_transmittersenvironment_variablesenvironment_variables_datasignal_typescommentsattribute_definitionssigtype_attr_list (format missing documentation)attribute_defaultsattribute_valuesvalue_descriptionscategory_definitions (deprecated)categories (deprecated)filter (deprecated)signal_type_refssignal_groupssignal_extended_value_type_listSIG_GROUP 13.VAL_ suffix may be ; or ;Test dbcs files were copied from the cantools project.
make.just.just test.just blessLicensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual-licensed as above, without any additional terms or conditions.