Skip to content

Commit

Permalink
Revert "propose discriminant check. Array should never contain values…
Browse files Browse the repository at this point in the history
… of differing discriminants"

This reverts commit 4fb4407.
  • Loading branch information
mat-kie authored and stadelmanma committed Jan 7, 2025
1 parent a6f45d1 commit b4f4eda
Showing 1 changed file with 1 addition and 23 deletions.
24 changes: 1 addition & 23 deletions fitparser/src/de/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ use nom::sequence::tuple;
use nom::{Err, IResult, Needed};
use std::collections::HashMap;
use std::convert::From;
use std::mem::discriminant;
use std::sync::Arc;

/// Define an is_valid function needed for parsing here, this function is not needed for normal use
Expand All @@ -37,23 +36,7 @@ impl Value {
Value::SInt64(val) => *val != 0x7FFF_FFFF_FFFF_FFFF,
Value::UInt64(val) => *val != 0xFFFF_FFFF_FFFF_FFFF,
Value::UInt64z(val) => *val != 0x0,
Value::Array(vals) => {
if let Some(first) = vals
.iter()
.find(|&v| !matches!(v, Value::Invalid))
.map(discriminant)
{
let mut same_type = true;
let mut any_valid = false;
for v in vals {
same_type &= matches!(v, Value::Invalid) || discriminant(v) == first;
any_valid |= v.is_valid();
}
same_type && any_valid
} else {
false
}
}
Value::Array(vals) => !vals.is_empty() && vals.iter().any(|v| v.is_valid()),
Value::Invalid => false,
}
}
Expand Down Expand Up @@ -827,10 +810,5 @@ mod tests {
!val.is_valid(),
"This Value array should be invalid since it contains no valid values"
);
let val = Value::Array(vec![Value::Byte(0x12), Value::UInt8(42u8)]);
assert!(
!val.is_valid(),
"This Value array should be invalid since it contains differing discriminants"
);
}
}

0 comments on commit b4f4eda

Please sign in to comment.