Fix u64 support#27
Merged
Merged
Conversation
If you use i64, you run into issues with u64 -> i64. Now use i128. Looks like can_dbc has not considered this as well.
There was a problem hiding this comment.
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
i64toi128to represent fullu64ranges without wraparound. - Updated enum value-description mapping to use
i128keys 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::rawand related constructors) fromi64toi128, 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
SignalMetais a public struct, and changingenum_mapkeys fromi64toi128is 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.
irvingywang
approved these changes
May 8, 2026
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.
If you use i64, you run into issues with u64 -> i64. Now uses i128. Looks like can_dbc has not considered this as well?