From e81b85dd5bdd6d42ee84f24ed4a142f6141f170e Mon Sep 17 00:00:00 2001 From: mat Date: Sat, 1 Jan 2022 19:44:51 -0600 Subject: add a couple more packets --- azalea-protocol/src/mc_buf.rs | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (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 538fc212..860f61f2 100644 --- a/azalea-protocol/src/mc_buf.rs +++ b/azalea-protocol/src/mc_buf.rs @@ -166,7 +166,8 @@ pub trait Readable { 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_bytes_with_len(&mut self, n: usize) -> Result, String>; + async fn read_bytes(&mut self) -> Result, String>; async fn read_utf(&mut self) -> Result; async fn read_utf_with_len(&mut self, max_length: u32) -> Result; async fn read_byte(&mut self) -> Result; @@ -230,10 +231,10 @@ where async fn read_byte_array(&mut self) -> Result, String> { let length = self.read_varint().await? as usize; - Ok(self.read_bytes(length).await?) + Ok(self.read_bytes_with_len(length).await?) } - async fn read_bytes(&mut self, n: usize) -> Result, String> { + async fn read_bytes_with_len(&mut self, n: usize) -> Result, String> { let mut bytes = vec![0; n]; match AsyncReadExt::read_exact(self, &mut bytes).await { Ok(_) => Ok(bytes), @@ -241,6 +242,15 @@ where } } + async fn read_bytes(&mut self) -> Result, String> { + // read to end of the buffer + let mut bytes = vec![]; + AsyncReadExt::read_to_end(self, &mut bytes) + .await + .map_err(|_| "Error reading bytes".to_string())?; + Ok(bytes) + } + async fn read_utf(&mut self) -> Result { self.read_utf_with_len(MAX_STRING_LENGTH.into()).await } -- cgit v1.2.3