From c4eecaf13a4f8f0a81dc278078727df23caa8411 Mon Sep 17 00:00:00 2001 From: mat Date: Thu, 16 Dec 2021 23:33:06 -0600 Subject: try to implement compression --- azalea-protocol/src/mc_buf.rs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'azalea-protocol/src/mc_buf.rs') 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 { pub trait Readable { async fn read_int_id_list(&mut self) -> Result, String>; async fn read_varint(&mut self) -> Result; + 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, String>; async fn read_bytes(&mut self, n: usize) -> Result, String>; async fn read_utf(&mut self) -> Result; @@ -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, String> { let length = self.read_varint().await? as usize; Ok(self.read_bytes(length).await?) -- cgit v1.2.3