Improve parser internals - #22
Closed
LelsersLasers wants to merge 1 commit into
Closed
Conversation
There was a problem hiding this comment.
Pull request overview
Refactors the DBC parser’s internal storage by consolidating per-message metadata (message definition + per-signal formatting like enums and float types) into a single entry structure, and updates decode/encode paths to use that structure.
Changes:
- Replace separate
msg_defs/enum_defs/float_defsmaps with a unifiedmsg_entries: HashMap<u32, MsgEntry>. - Unify enum and float formatting metadata into
FormatDefkeyed by signal name. - Rework big-endian signal bit extraction logic.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+129
to
+131
| /// For integer-backed signals this is the physical value after applying | ||
| /// factor and offset. For IEEE float/double signals (`SIG_VALTYPE_`) this | ||
| /// is the decoded floating-point value directly from the raw bits. |
Comment on lines
+152
to
+194
| #[derive(Copy, Clone)] | ||
| pub enum FloatFormat { | ||
| F32, | ||
| F64, | ||
| } | ||
|
|
||
| impl FloatFormat { | ||
| pub fn from_dbc_def(def: can_dbc::SignalExtendedValueType) -> Option<Self> { | ||
| match def { | ||
| can_dbc::SignalExtendedValueType::IEEEfloat32Bit => Some(FloatFormat::F32), | ||
| can_dbc::SignalExtendedValueType::IEEEdouble64bit => Some(FloatFormat::F64), | ||
| can_dbc::SignalExtendedValueType::SignedOrUnsignedInteger => None, | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[derive(Clone)] | ||
|
|
||
| pub struct FormatDef { | ||
| pub enum_map: std::collections::HashMap<i64, String>, | ||
| pub float_format: Option<FloatFormat>, | ||
| } | ||
|
|
||
| #[derive(Debug, Clone)] | ||
| pub struct FloatDef { | ||
| /// Signal name this float-type definition belongs to. | ||
| pub signal_name: String, | ||
| /// The DBC extended value type (`IEEEfloat32Bit` or `IEEEdouble64bit`). | ||
| pub float_def: can_dbc::SignalExtendedValueType, | ||
| impl FormatDef { | ||
| pub fn new_enum(enum_map: std::collections::HashMap<i64, String>) -> Self { | ||
| Self { | ||
| enum_map, | ||
| float_format: None, | ||
| } | ||
| } | ||
|
|
||
| pub fn new_float(float_format: FloatFormat) -> Self { | ||
| Self { | ||
| enum_map: std::collections::HashMap::new(), | ||
| float_format: Some(float_format), | ||
| } | ||
| } | ||
| } | ||
|
|
||
| pub struct MsgEntry { | ||
| pub msg_def: can_dbc::Message, | ||
| pub format_defs: std::collections::HashMap<String, FormatDef>, // signal name -> format definition | ||
| } |
| if byte_idx >= data.len() { | ||
| // Out of bounds: should not be considered a successful decode | ||
| return None; | ||
| break; |
Comment on lines
+660
to
+662
| for _ in 0..size { | ||
| let byte_idx = bit_pos / 8; | ||
| let bit_idx = 7 - (bit_pos % 8); |
LelsersLasers
marked this pull request as draft
May 3, 2026 01:40
Member
Author
|
dang it the rebase didn't work |
Merged
Member
Author
|
Succeeded by #23 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Correct rebase of #21