summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-23 20:47:51 +0100
committerDaniel Silverstone <dsilvers@digital-scurf.org>2018-04-23 20:47:51 +0100
commit3156a6fccb665231580cacf284323419386345f0 (patch)
treeee8553f248f73e4f4048a5d6e88bef890462c2c6
parentfcbcf253b4534585d08d2603ada104295881c475 (diff)
downloadcanopied-3156a6fccb665231580cacf284323419386345f0.tar.bz2
Support signed values
-rw-r--r--src/definitions.rs32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/definitions.rs b/src/definitions.rs
index 3cecccb..32ee8be 100644
--- a/src/definitions.rs
+++ b/src/definitions.rs
@@ -159,6 +159,38 @@ impl RawECUEntry {
.into(),
_ => panic!("Unhandled length: {}", entry.length),
},
+ "unsigned-le" => match entry.length {
+ 1 => payload[entry.offset].into(),
+ 2 => (((payload[entry.offset + 1] as u16) << 8)
+ + (payload[entry.offset] as u16))
+ .into(),
+ 3 => (((payload[entry.offset + 2] as u32) << 16)
+ + ((payload[entry.offset + 1] as u32) << 8)
+ + (payload[entry.offset] as u32))
+ .into(),
+ 4 => (((payload[entry.offset + 3] as u32) << 24)
+ + ((payload[entry.offset + 2] as u32) << 16)
+ + ((payload[entry.offset + 1] as u32) << 8)
+ + (payload[entry.offset] as u32))
+ .into(),
+ _ => panic!("Unhandled length: {}", entry.length),
+ },
+ "signed-le" => match entry.length {
+ 1 => (payload[entry.offset] as i8).into(),
+ 2 => ((((payload[entry.offset + 1] as u16) << 8)
+ + (payload[entry.offset] as u16)) as i16)
+ .into(),
+ 3 => ((((payload[entry.offset + 2] as u32) << 16)
+ + ((payload[entry.offset + 1] as u32) << 8)
+ + (payload[entry.offset] as u32)) as i32)
+ .into(),
+ 4 => ((((payload[entry.offset + 3] as u32) << 24)
+ + ((payload[entry.offset + 2] as u32) << 16)
+ + ((payload[entry.offset + 1] as u32) << 8)
+ + (payload[entry.offset] as u32)) as i32)
+ .into(),
+ _ => panic!("Unhandled length: {}", entry.length),
+ },
"bit" => ((payload[entry.offset] & (1 << entry.base.unwrap())) != 0).into(),
_ => {
panic!("Unhandled");