Skip to content

Commit

Permalink
bitfields: Lift 32-bit range limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Sh3Rm4n committed Dec 20, 2020
1 parent 424fff8 commit 2c3b878
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 5 deletions.
23 changes: 23 additions & 0 deletions decoder/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,29 @@ mod tests {
);
}

#[test]
fn bitfields_u128() {
let bytes = [
0, // index
2, // timestamp
0b1111_0000,
0b1110_0101, // u16
0b1111_0000,
0b1110_0101, // u16
0b1111_0000,
0b1110_0101, // u16
0b1111_0000,
0b1110_0101, // u16
0b1111_0000,
0b1110_0101, // u16
0b1111_0000,
0b1110_0101, // u16
0b1111_0000,
0b1110_0101, // u16
];
decode_and_expect("x: {0=119..124:b}", &bytes, "0.000002 INFO x: 0b1011");
}

#[test]
fn slice() {
let bytes = [
Expand Down
10 changes: 5 additions & 5 deletions parser/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn parse_range(mut s: &str) -> Option<(Range<u8>, usize /* consumed */)> {
return None;
}

if start >= 32 || end >= 32 {
if start >= 128 || end >= 128 {
return None;
}

Expand Down Expand Up @@ -886,10 +886,10 @@ mod tests {
assert!(parse("{=0..0}", ParserMode::Strict).is_err());
// start > end
assert!(parse("{=1..0}", ParserMode::Strict).is_err());
// out of 32-bit range
assert!(parse("{=0..32}", ParserMode::Strict).is_err());
// just inside 32-bit range
assert!(parse("{=0..31}", ParserMode::Strict).is_ok());
// out of 128-bit range
assert!(parse("{=0..128}", ParserMode::Strict).is_err());
// just inside 128-bit range
assert!(parse("{=0..127}", ParserMode::Strict).is_ok());

// missing parts
assert!(parse("{=0..4", ParserMode::Strict).is_err());
Expand Down

0 comments on commit 2c3b878

Please sign in to comment.