diff options
Diffstat (limited to 'azalea-protocol/src/mc_buf.rs')
| -rw-r--r-- | azalea-protocol/src/mc_buf.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/azalea-protocol/src/mc_buf.rs b/azalea-protocol/src/mc_buf.rs index 0a47f637..84c602ec 100644 --- a/azalea-protocol/src/mc_buf.rs +++ b/azalea-protocol/src/mc_buf.rs @@ -134,6 +134,8 @@ impl Writable for Vec<u8> { pub trait Readable { async fn read_int_id_list(&mut self) -> Result<Vec<i32>, String>; async fn read_varint(&mut self) -> Result<i32, String>; + fn get_varint_size(&mut self, value: i32) -> u8; + fn get_varlong_size(&mut self, value: i32) -> u8; async fn read_byte_array(&mut self) -> Result<Vec<u8>, String>; async fn read_bytes(&mut self, n: usize) -> Result<Vec<u8>, String>; async fn read_utf(&mut self) -> Result<String, String>; @@ -173,6 +175,26 @@ where Ok(ans) } + fn get_varint_size(&mut self, value: i32) -> u8 { + for i in 1..5 { + if (value & -1 << i * 7) != 0 { + continue; + } + return i; + } + return 5; + } + + fn get_varlong_size(&mut self, value: i32) -> u8 { + for i in 1..10 { + if (value & -1 << i * 7) != 0 { + continue; + } + return i; + } + return 10; + } + async fn read_byte_array(&mut self) -> Result<Vec<u8>, String> { let length = self.read_varint().await? as usize; Ok(self.read_bytes(length).await?) |
