diff options
| author | mat <github@matdoes.dev> | 2021-12-16 23:33:06 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2021-12-16 23:33:06 -0600 |
| commit | c4eecaf13a4f8f0a81dc278078727df23caa8411 (patch) | |
| tree | 5082f54d1a9242281d80c250e587235a3ac3755b /azalea-protocol/src/mc_buf.rs | |
| parent | 1dc56b6f519f386b6e0b5eac47a84576cedbbb33 (diff) | |
| download | azalea-drasl-c4eecaf13a4f8f0a81dc278078727df23caa8411.tar.xz | |
try to implement compression
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?) |
