Skip to content

Commit

Permalink
get_unsigned_var_int fix2
Browse files Browse the repository at this point in the history
(what am i doing idk)
  • Loading branch information
ismaileke committed Aug 29, 2024
1 parent 6c64d2a commit e3a21be
Showing 1 changed file with 15 additions and 23 deletions.
38 changes: 15 additions & 23 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,36 +368,28 @@ pub mod binary {
}

pub fn get_unsigned_var_int(&mut self) -> u32 {
let bytes = self.get(5);

match bytes {
Ok(byte) => {
let mut value = 0u32;
for i in 0..5 {
let b = byte[i];
value |= ((b & 0x7f) as u32) << (i * 7);
if b & 0x80 == 0 {
return value;
}
}
println!("Error get_unsigned_var_int()");
0
}
Err(err) => {
println!("Error get_unsigned_var_int(): {}", err);
0
let mut value = 0u32;
for i in 0..5 {
let b = self.get_byte();
value |= ((b & 0x7f) as u32) << (i * 7);
if b & 0x80 == 0 {
return value;
}
}
println!("Error get_unsigned_var_int()");
0
}

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

value = value >> 7;
}
}

Expand Down

0 comments on commit e3a21be

Please sign in to comment.