Skip to content

Commit

Permalink
get_unsigned_var_int fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ismaileke committed Aug 29, 2024
1 parent 597f138 commit 6c64d2a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
12 changes: 8 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,7 @@ pub mod binary {
return value;
}
}
println!("Error get_unsigned_var_int()");
0
}
Err(err) => {
Expand All @@ -388,13 +389,16 @@ pub mod binary {
}
}
}

pub fn put_unsigned_var_int(&mut self, mut value: u32) {
while value > 0x7f {
self.buffer.push((value & 0x7f) as u8 | 0x80);
for _ in 0..5 {
if value >> 7 != 0 {
self.buffer.push(((value & 0x7f) | 0x80) as u8);
} else {
self.buffer.push(value as u8 & 0x7f);
}
value >>= 7;
}

self.buffer.push(value as u8);
}

pub fn get_var_int(&mut self) -> i32 {
Expand Down
6 changes: 4 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ mod tests {

#[test]
fn test() {
let mut stream = Stream::new(vec![0, 52, 255], 0);
println!("{:?}", stream.get(1));
let mut stream = Stream::new(vec![], 0);
stream.put_unsigned_var_int(2322211);
println!("{:?}", stream.get_buffer());
println!("{}", stream.get_unsigned_var_int());

}
}

0 comments on commit 6c64d2a

Please sign in to comment.