Skip to content
This repository was archived by the owner on Dec 1, 2026. It is now read-only.

Fix u64 support - #27

Merged
LelsersLasers merged 1 commit into
mainfrom
millan/fix_u64
May 8, 2026
Merged

LelsersLasers merged 1 commit into
mainfrom
millan/fix_u64

Conversation

@LelsersLasers

Copy link
Copy Markdown
Member

If you use i64, you run into issues with u64 -> i64. Now uses i128. Looks like can_dbc has not considered this as well?

If you use i64, you run into issues with u64 -> i64. Now use i128. Looks like can_dbc has not considered this as well.

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

This PR updates the decoding/encoding pipeline to correctly handle 64-bit unsigned raw signal values by widening internal/public “raw value” representations and adjusting signed conversion logic.

Changes:

  • Widened decoded raw signal storage from i64 to i128 to represent full u64 ranges without wraparound.
  • Updated enum value-description mapping to use i128 keys and aligned decoding lookups accordingly.
  • Simplified signed sign-extension during decoding and fixed signed-range computation during encoding to avoid overflow at 64-bit widths.
Comments suppressed due to low confidence (2)

src/lib.rs:144

  • This changes a public API type (DecodedSignalValue::raw and related constructors) from i64 to i128, which is a breaking change for downstream crates. Consider introducing a public type alias (e.g., pub type RawSignalValue = i128) and using that in the struct/constructors to make the API change explicit and reduce future churn (and to help callers migrate by updating a single import/type).
/// Represents the decoded value of a CAN signal.
#[derive(Debug, Clone)]
pub struct DecodedSignalValue {
    /// The physical value of the signal after applying scaling and offset.
    pub physical: f64,
    /// Contains the raw integer value (with sign accounting).
    /// Present unless the signal is an IEEE float/double.
    pub raw: Option<i128>,
    /// If the signal/value has an enum mapping, this contains the corresponding enum label.
    pub enum_label: Option<String>,
}

impl DecodedSignalValue {
    /// Creates a new `DecodedSignalValue` for a numeric signal that is backed by
    /// an integer (signed or unsigned).
    pub fn new_integer_backed_numeric(physical: f64, raw_value: i128) -> Self {
        Self {
            physical,
            raw: Some(raw_value),
            enum_label: None,

src/lib.rs:241

  • SignalMeta is a public struct, and changing enum_map keys from i64 to i128 is another breaking API change. If the wider goal is to support u64-sized raw values, consider also using the same exported raw-value type alias for this map key so the public surface stays consistent and easier to migrate.
/// Also includes the signal-level description/comment from the DBC, if available.
#[derive(Debug, Clone, Default)]
pub struct SignalMeta {
    /// Maps raw signal values to string enum labels from DBC value descriptions.
    pub enum_map: std::collections::HashMap<i128, String>,

    /// The IEEE-754 float format, if this signal is an IEEE float/double.
    pub float_format: Option<FloatFormat>,


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@LelsersLasers
LelsersLasers requested a review from irvingywang May 8, 2026 22:37
@LelsersLasers
LelsersLasers merged commit 6ee097f into main May 8, 2026
5 checks passed
@LelsersLasers
LelsersLasers deleted the millan/fix_u64 branch May 8, 2026 22:45
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants