pub struct FastDbc { /* private fields */ }Expand description
High-performance DBC wrapper with optimized message lookup and decoding.
§Performance Optimizations
- Direct array lookup: Standard CAN IDs (0-2047) use direct array indexing
- Pre-computed decode plans: All bit positions, masks, and flags computed at build time
- Identity transform detection: Skips factor/offset math when factor=1, offset=0
- Cache-friendly layout: Decode parameters packed for optimal cache usage
- FxHash for extended IDs: Fast hash function for non-standard IDs
Cloning is O(1) due to internal Arc usage.
Implementations§
Source§impl FastDbc
impl FastDbc
Sourcepub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
pub fn from_file<P: AsRef<Path>>(path: P) -> Result<Self>
Load a DBC file from disk and wrap it for fast access.
Sourcepub fn new(dbc: Dbc) -> Self
pub fn new(dbc: Dbc) -> Self
Create a new FastDbc wrapper from a Dbc.
This pre-computes all decode parameters for maximum runtime performance.
Sourcepub fn get_extended(&self, id: u32) -> Option<&Message>
pub fn get_extended(&self, id: u32) -> Option<&Message>
Get a message by extended (29-bit) CAN ID.
Sourcepub fn get_any(&self, id: u32) -> Option<&Message>
pub fn get_any(&self, id: u32) -> Option<&Message>
Get a message by CAN ID, trying extended if standard not found.
Sourcepub fn decode_into(
&self,
id: u32,
data: &[u8],
out: &mut [f64],
) -> Option<usize>
pub fn decode_into( &self, id: u32, data: &[u8], out: &mut [f64], ) -> Option<usize>
Decode a message by standard CAN ID into the output buffer.
This is the primary high-speed decode path:
- O(1) message lookup via direct array indexing
- Pre-computed decode parameters
- Identity transform detection (skips math when factor=1, offset=0)
- Zero allocation
§Arguments
id- Standard (11-bit) CAN IDdata- Raw CAN payload bytesout- Output buffer for physical values
§Returns
Number of signals decoded, or None if message not found or payload too short.
Sourcepub fn decode_extended_into(
&self,
id: u32,
data: &[u8],
out: &mut [f64],
) -> Option<usize>
pub fn decode_extended_into( &self, id: u32, data: &[u8], out: &mut [f64], ) -> Option<usize>
Decode a message by extended CAN ID into the output buffer.
Sourcepub fn decode_raw_into(
&self,
id: u32,
data: &[u8],
out: &mut [i64],
) -> Option<usize>
pub fn decode_raw_into( &self, id: u32, data: &[u8], out: &mut [i64], ) -> Option<usize>
Decode raw values by standard CAN ID.
Sourcepub fn max_signals(&self) -> usize
pub fn max_signals(&self) -> usize
Get the maximum number of signals in any single message.
Use this to pre-allocate decode buffers.
Sourcepub fn total_signals(&self) -> usize
pub fn total_signals(&self) -> usize
Get the total number of signals across all messages.
Sourcepub fn message_count(&self) -> usize
pub fn message_count(&self) -> usize
Get the number of messages.
Sourcepub fn contains_extended(&self, id: u32) -> bool
pub fn contains_extended(&self, id: u32) -> bool
Check if a message with this extended CAN ID exists.