diff options
| author | mat <github@matdoes.dev> | 2022-05-07 19:46:06 -0500 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-05-07 19:46:06 -0500 |
| commit | e53ef8b0ddd46b3a85e597e7da57139960304e35 (patch) | |
| tree | 272a3dfb42113dc53e51b5d21052e033bae92fd7 /azalea-protocol/src/mc_buf | |
| parent | 0b84e1cbb826f1a502ffc81efc000369a3c5bb85 (diff) | |
| download | azalea-drasl-e53ef8b0ddd46b3a85e597e7da57139960304e35.tar.xz | |
update advancements packet
Diffstat (limited to 'azalea-protocol/src/mc_buf')
| -rwxr-xr-x | azalea-protocol/src/mc_buf/read.rs | 13 | ||||
| -rwxr-xr-x | azalea-protocol/src/mc_buf/write.rs | 14 |
2 files changed, 25 insertions, 2 deletions
diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs index e67cfa3c..991bf53b 100755 --- a/azalea-protocol/src/mc_buf/read.rs +++ b/azalea-protocol/src/mc_buf/read.rs @@ -6,7 +6,7 @@ use azalea_core::{ }; use byteorder::{ReadBytesExt, WriteBytesExt, BE}; use serde::Deserialize; -use std::io::Read; +use std::{collections::HashMap, hash::Hash, io::Read}; use tokio::io::{AsyncRead, AsyncReadExt}; use uuid::Uuid; @@ -294,6 +294,17 @@ impl<T: McBufReadable + Send> McBufReadable for Vec<T> { } } +impl<K: McBufReadable + Send + Eq + Hash, V: McBufReadable + Send> McBufReadable for HashMap<K, V> { + default fn read_into(buf: &mut impl Read) -> Result<Self, String> { + let length = buf.read_varint()? as usize; + let mut contents = HashMap::with_capacity(length); + for _ in 0..length { + contents.insert(K::read_into(buf)?, V::read_into(buf)?); + } + Ok(contents) + } +} + impl McBufReadable for Vec<u8> { fn read_into(buf: &mut impl Read) -> Result<Self, String> { buf.read_byte_array() diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs index 10271bf8..66f129f1 100755 --- a/azalea-protocol/src/mc_buf/write.rs +++ b/azalea-protocol/src/mc_buf/write.rs @@ -5,7 +5,7 @@ use azalea_core::{ serializable_uuid::SerializableUuid, BlockPos, Direction, Slot, }; use byteorder::{BigEndian, WriteBytesExt}; -use std::io::Write; +use std::{collections::HashMap, io::Write}; use uuid::Uuid; pub trait Writable: Write { @@ -174,6 +174,18 @@ impl<T: McBufWritable> McBufWritable for Vec<T> { } } +impl<K: McBufWritable, V: McBufWritable> McBufWritable for HashMap<K, V> { + default fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { + u32::var_write_into(&(self.len() as u32), buf)?; + for (key, value) in self { + key.write_into(buf)?; + value.write_into(buf)?; + } + + Ok(()) + } +} + impl McBufWritable for Vec<u8> { fn write_into(&self, buf: &mut impl Write) -> Result<(), std::io::Error> { buf.write_byte_array(self) |
