diff options
| author | mat <github@matdoes.dev> | 2022-01-01 19:44:51 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-01-01 19:44:51 -0600 |
| commit | e81b85dd5bdd6d42ee84f24ed4a142f6141f170e (patch) | |
| tree | 16d950954429b403e2adcc582feb64da73da42df /azalea-protocol/src/mc_buf.rs | |
| parent | 1a961d968b80b720ef2d3900c0b95e1c16a0089e (diff) | |
| download | azalea-drasl-e81b85dd5bdd6d42ee84f24ed4a142f6141f170e.tar.xz | |
add a couple more packets
Diffstat (limited to 'azalea-protocol/src/mc_buf.rs')
| -rw-r--r-- | azalea-protocol/src/mc_buf.rs | 16 |
1 files changed, 13 insertions, 3 deletions
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<Vec<u8>, String>; - async fn read_bytes(&mut self, n: usize) -> Result<Vec<u8>, String>; + async fn read_bytes_with_len(&mut self, n: usize) -> Result<Vec<u8>, String>; + async fn read_bytes(&mut self) -> Result<Vec<u8>, String>; async fn read_utf(&mut self) -> Result<String, String>; async fn read_utf_with_len(&mut self, max_length: u32) -> Result<String, String>; async fn read_byte(&mut self) -> Result<u8, String>; @@ -230,10 +231,10 @@ where 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?) + Ok(self.read_bytes_with_len(length).await?) } - async fn read_bytes(&mut self, n: usize) -> Result<Vec<u8>, String> { + async fn read_bytes_with_len(&mut self, n: usize) -> Result<Vec<u8>, 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<Vec<u8>, 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<String, String> { self.read_utf_with_len(MAX_STRING_LENGTH.into()).await } |
