dbc-parse
DBC file parser: CAN message definitions, signal layout (bit-offset/length/endianness/scaling), value tables, extended multiplexing.
Layer: L0: leaf · Estate deps: zero (own minimal CanId) ·
Runtime deps: zero · no_std + alloc (CI exercises
thumbv7em-none-eabihf).
What's here
| Module | Contents |
|---|---|
model |
Dbc (Dbc::parse), Message::unpack, Signal::decode_raw/encode_raw, Node, ValueTable, Attribute, ExtendedMux, CanId |
bits |
The two DBC bit-numbering systems: Motorola (big-endian, @0: start_bit is the MSB, sawtooth walk) and Intel (little-endian, @1: start_bit is the LSB, linear) |
parser |
The Vector DBC grammar: VERSION, NS_, BS_, BU_, BO_, SG_ (M/m<N>/m<N>M), CM_, VAL_, VAL_TABLE_, BA_, BA_DEF_, BA_DEF_DEF_, SG_MUL_VAL_ |
error |
DbcError: the single typed, exhaustive error |
Motorola bit numbering: done right
DBC files number bits per byte, LSB-first; the byte orders differ in what
start_bit names and the direction of travel:
- Intel (
@1):start_bitis the LSB; bits ascend linearly. - Motorola (
@0):start_bitis the MSB; extraction descends within each byte and jumps from bit 0 of one byte to bit 7 of the next (+15in DBC numbering: the sawtooth). A39|16@0+signal is a big-endianu16across bytes 4–5; motohawk's0|12@0-Temperature straddles three bytes.
The coding is cross-verified against cantools 44.1.0 on the same embedded sample files (golden decode and encode vectors).
Guarantees
- Total parser:
Dbc::parsenever panics: every failure is a typedDbcError::Syntaxwith a line number (unknown vendor keywords are skipped, not rejected). Deny-level lints (unwrap_used/expect_used/panic/indexing_slicing) on the lib target, a cargo-fuzz target (dbc_parse), 30 s CI smoke, miri. - Zero-copy decode:
Signal::decode_rawborrows the payload; bits beyond a short buffer read as zero (documented semantics). - Range-checked encode:
encode_rawenforces the declared[min|max]range (whenmin < max), the bit width, and buffer bounds. - Multiplexing:
M/m<N>filter inMessage::unpack;SG_MUL_VAL_extended-multiplexing ranges are parsed intoDbc::extended_multiplexing.
Example
use ;
let dbc = parse.unwrap;
let values = dbc.messages.unpack;
assert_eq!;
assert!; // cantools-verified golden
Attribution
The embedded test files tests/files/motohawk.dbc and
tests/files/multiplex.dbc come from the cantools test corpus (MIT
license); golden vectors were produced with cantools 44.1.0.
License
MIT OR Apache-2.0: see LICENSE-MIT and LICENSE-APACHE.