diff options
| author | mat <github@matdoes.dev> | 2022-05-05 22:12:54 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-05 22:12:54 -0500 |
| commit | 4dac004635e50682d9ebe8812fdf654a0c1808f1 (patch) | |
| tree | 46257a144ec069ba3e0a812eabca6e9ed246db6b /azalea-protocol/src | |
| parent | 57b76ef52b7a9b516710aea5ba5d6f0141c8d6cf (diff) | |
| download | azalea-drasl-4dac004635e50682d9ebe8812fdf654a0c1808f1.tar.xz | |
Fix chunk decoding
Diffstat (limited to 'azalea-protocol/src')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/mod.rs | 2 | ||||
| -rwxr-xr-x | azalea-protocol/src/mc_buf/read.rs | 11 | ||||
| -rwxr-xr-x | azalea-protocol/src/mc_buf/write.rs | 7 |
3 files changed, 20 insertions, 0 deletions
diff --git a/azalea-protocol/src/mc_buf/mod.rs b/azalea-protocol/src/mc_buf/mod.rs index a82334fb..debf2991 100755 --- a/azalea-protocol/src/mc_buf/mod.rs +++ b/azalea-protocol/src/mc_buf/mod.rs @@ -12,6 +12,8 @@ pub use write::{McBufVarintWritable, McBufWritable, Writable}; const MAX_STRING_LENGTH: u16 = 32767; // const MAX_COMPONENT_STRING_LENGTH: u32 = 262144; +// TODO: maybe get rid of the readable/writable traits so there's not two ways to do the same thing and improve McBufReadable/McBufWritable + // TODO: have a definitions.rs in mc_buf that contains UnsizedByteArray and BitSet /// A Vec<u8> that isn't prefixed by a VarInt with the size. diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs index e1ae321c..a8c44bdf 100755 --- a/azalea-protocol/src/mc_buf/read.rs +++ b/azalea-protocol/src/mc_buf/read.rs @@ -255,6 +255,17 @@ impl McBufVarintReadable for i32 { } } +impl<T: McBufVarintReadable> McBufVarintReadable for Vec<T> { + fn varint_read_into(buf: &mut impl Read) -> Result<Self, String> { + let length = u32::varint_read_into(buf)?; + let mut vec = Vec::with_capacity(length as usize); + for _ in 0..length { + vec.push(T::varint_read_into(buf)?); + } + Ok(vec) + } +} + impl McBufReadable for UnsizedByteArray { fn read_into(buf: &mut impl Read) -> Result<Self, String> { Ok(UnsizedByteArray(buf.read_bytes()?)) diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs index 3a4a02f8..cc5f2284 100755 --- a/azalea-protocol/src/mc_buf/write.rs +++ b/azalea-protocol/src/mc_buf/write.rs @@ -210,6 +210,13 @@ impl McBufVarintWritable for u32 { } } +// Vec<T> varint +impl<T: McBufVarintWritable> McBufVarintWritable for Vec<T> { + fn varint_write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + buf.write_list(self, |buf, i| i.varint_write_into(buf)) + } +} + // u16 impl McBufWritable for u16 { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { |
