Skip to content

Commit

Permalink
get_var_int fix
Browse files Browse the repository at this point in the history
(i think i have some other things to fix)
  • Loading branch information
ismaileke committed Aug 29, 2024
1 parent e3a21be commit 62571dc
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ pub mod binary {

pub fn get_var_int(&mut self) -> i32 {
let raw: u32 = self.get_unsigned_var_int();
(((raw << 31) >> 31) ^ raw >> 1 ^ (raw & (1 << 31))) as i32
((raw >> 1) as i32) ^ (-((raw & 1) as i32) & 1)
}

pub fn put_var_int(&mut self, value: i32) {
Expand Down
4 changes: 2 additions & 2 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ mod tests {
#[test]
fn test() {
let mut stream = Stream::new(vec![], 0);
stream.put_unsigned_var_int(2322211);
stream.put_var_int(2322211);
println!("{:?}", stream.get_buffer());
println!("{}", stream.get_unsigned_var_int());
println!("{}", stream.get_var_int());

}
}

0 comments on commit 62571dc

Please sign in to comment.