Skip to content

Commit 15ddd40

Browse files
Fix tiny int handling (#252)
* Fix tiny int handling * fix test * fix missed test
1 parent ae93007 commit 15ddd40

File tree

3 files changed

+17
-5
lines changed

3 files changed

+17
-5
lines changed

lib/src/messages/discard.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod tests {
5656
assert_eq!(&*marker_signature, &[0xB1, 0x2F]);
5757
let extra: BoltMap = BoltMap::parse(Version::V4_1, &mut bytes).unwrap();
5858

59-
assert_eq!(extra.get::<i64>("n").unwrap(), 255);
60-
assert_eq!(extra.get::<i64>("qid").unwrap(), 255);
59+
assert_eq!(extra.get::<i64>("n").unwrap(), -1);
60+
assert_eq!(extra.get::<i64>("qid").unwrap(), -1);
6161
}
6262
}

lib/src/messages/pull.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ mod tests {
5656
assert_eq!(&*marker_signature, &[0xB1, 0x3F]);
5757
let extra: BoltMap = BoltMap::parse(Version::V4_1, &mut bytes).unwrap();
5858

59-
assert_eq!(extra.get::<i64>("n").unwrap(), 255);
60-
assert_eq!(extra.get::<i64>("qid").unwrap(), 255);
59+
assert_eq!(extra.get::<i64>("n").unwrap(), -1);
60+
assert_eq!(extra.get::<i64>("qid").unwrap(), -1);
6161
}
6262
}

lib/src/types/integer.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl BoltWireFormat for BoltInteger {
6969

7070
fn parse(_version: Version, input: &mut Bytes) -> Result<Self> {
7171
let value: i64 = match input.get_u8() {
72-
marker if (-16..=127).contains(&(marker as i8)) => marker as i64,
72+
marker if (-16..=127).contains(&(marker as i8)) => (marker as i8) as i64,
7373
INT_8 => input.get_i8() as i64,
7474
INT_16 => input.get_i16() as i64,
7575
INT_32 => input.get_i32() as i64,
@@ -145,6 +145,18 @@ mod tests {
145145

146146
#[test]
147147
fn should_deserialize_integer() {
148+
let mut b = Bytes::from_static(&[0x00]);
149+
let bolt_int: BoltInteger = BoltInteger::parse(Version::V4_1, &mut b).unwrap();
150+
assert_eq!(bolt_int.value, 0);
151+
152+
let mut b = Bytes::from_static(&[0xF0]);
153+
let bolt_int: BoltInteger = BoltInteger::parse(Version::V4_1, &mut b).unwrap();
154+
assert_eq!(bolt_int.value, -16);
155+
156+
let mut b = Bytes::from_static(&[0x7F]);
157+
let bolt_int: BoltInteger = BoltInteger::parse(Version::V4_1, &mut b).unwrap();
158+
assert_eq!(bolt_int.value, 127);
159+
148160
let mut b = Bytes::from_static(&[0x2A]);
149161
let bolt_int: BoltInteger = BoltInteger::parse(Version::V4_1, &mut b).unwrap();
150162
assert_eq!(bolt_int.value, 42);

0 commit comments

Comments
 (0)