aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/mc_buf/read.rs
diff options
context:
space:
mode:
Diffstat (limited to 'azalea-protocol/src/mc_buf/read.rs')
-rwxr-xr-xazalea-protocol/src/mc_buf/read.rs13
1 files changed, 12 insertions, 1 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()