Skip to content

Commit

Permalink
get_var_int fix 2
Browse files Browse the repository at this point in the history
(i hope)
  • Loading branch information
ismaileke committed Oct 11, 2024
1 parent ba28e2b commit 05ff2eb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
4 changes: 3 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,9 @@ pub mod binary {

pub fn get_var_int(&mut self) -> i32 {
let raw: u32 = self.get_unsigned_var_int();
((raw >> 1) as i32) ^ (-((raw & 1) as i32) & 1)
let temp = (((raw << 31) as i32) >> 31) as u32 ^ (raw >> 1);
(temp ^ (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
8 changes: 4 additions & 4 deletions tests/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ mod tests {

#[test]
fn test() {
let mut stream = Stream::new(vec![], 0);
println!("{:?}", "167".to_string().into_bytes());

stream.put_unsigned_var_long(1234456);
println!("stream: {:?}", stream.get_buffer());
let result = stream.get_unsigned_var_long();
let mut stream = Stream::new(vec![49, 54, 55], 0);

let result = stream.get_var_int();
println!("result: {}", result);

}
Expand Down

0 comments on commit 05ff2eb

Please sign in to comment.