Skip to content

Improve parser internals - #22

Closed
LelsersLasers wants to merge 1 commit into
mainfrom
millan/parser_internals
Closed

Improve parser internals#22
LelsersLasers wants to merge 1 commit into
mainfrom
millan/parser_internals

Conversation

@LelsersLasers

Copy link
Copy Markdown
Member

Correct rebase of #21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_defs maps with a unified msg_entries: HashMap<u32, MsgEntry>.
  • Unify enum and float formatting metadata into FormatDef keyed 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 thread src/lib.rs
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 thread src/lib.rs
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
}
Comment thread src/lib.rs
if byte_idx >= data.len() {
// Out of bounds: should not be considered a successful decode
return None;
break;
Comment thread src/lib.rs
Comment on lines +660 to +662
for _ in 0..size {
let byte_idx = bit_pos / 8;
let bit_idx = 7 - (bit_pos % 8);
@LelsersLasers
LelsersLasers removed the request for review from irvingywang May 3, 2026 01:40
@LelsersLasers
LelsersLasers marked this pull request as draft May 3, 2026 01:40
@LelsersLasers

Copy link
Copy Markdown
Member Author

dang it the rebase didn't work

@LelsersLasers

Copy link
Copy Markdown
Member Author

Succeeded by #23

@LelsersLasers
LelsersLasers deleted the millan/parser_internals branch May 8, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants