From f4dd3a9293367fa8f3d839a184e8055b22595204 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 24 Apr 2022 22:46:41 -0500 Subject: ENCRYPTION WORKS!!!!!!!!!!! --- azalea-protocol/src/mc_buf/read.rs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) (limited to 'azalea-protocol/src/mc_buf/read.rs') diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs index 1e031916..3d50e5aa 100755 --- a/azalea-protocol/src/mc_buf/read.rs +++ b/azalea-protocol/src/mc_buf/read.rs @@ -5,6 +5,7 @@ use azalea_core::{ }; use serde::Deserialize; use tokio::io::{AsyncRead, AsyncReadExt}; +use crate::mc_buf::ByteArray; use super::MAX_STRING_LENGTH; @@ -14,7 +15,7 @@ pub trait Readable { 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_byte_array(&mut self) -> Result; 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; @@ -80,9 +81,9 @@ where 10 } - async fn read_byte_array(&mut self) -> Result, String> { + async fn read_byte_array(&mut self) -> Result { let length = self.read_varint().await? as usize; - Ok(self.read_bytes_with_len(length).await?) + Ok(ByteArray(self.read_bytes_with_len(length).await?)) } async fn read_bytes_with_len(&mut self, n: usize) -> Result, String> { @@ -251,6 +252,17 @@ impl McBufReadable for Vec { } } + +#[async_trait] +impl McBufReadable for ByteArray { + async fn read_into(buf: &mut R) -> Result + where + R: AsyncRead + std::marker::Unpin + std::marker::Send, + { + buf.read_byte_array().await + } +} + // string #[async_trait] impl McBufReadable for String { -- cgit v1.2.3