diff --git a/src/lib.rs b/src/lib.rs index 4239439..d7e5325 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -380,6 +380,7 @@ pub mod binary { return value; } } + println!("Error get_unsigned_var_int()"); 0 } Err(err) => { @@ -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 { diff --git a/tests/lib.rs b/tests/lib.rs index abb79f4..7b5b30e 100644 --- a/tests/lib.rs +++ b/tests/lib.rs @@ -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()); } }