aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-01-02 17:07:01 -0600
committermat <github@matdoes.dev>2022-01-02 17:07:01 -0600
commitbb566aa54131a23b6d9e605c81a8ff4d1d1c21d7 (patch)
tree157b88ee64215516e27d9f765513d3aa4fef0d64
parentbb57273f48294355d7ac863c291d80878f711c16 (diff)
downloadazalea-drasl-bb566aa54131a23b6d9e605c81a8ff4d1d1c21d7.tar.xz
implement for Vec<u8>
-rw-r--r--azalea-protocol/packet-macros/src/lib.rs7
-rw-r--r--azalea-protocol/src/mc_buf/read.rs10
-rw-r--r--azalea-protocol/src/mc_buf/write.rs6
-rw-r--r--azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs3
4 files changed, 18 insertions, 8 deletions
diff --git a/azalea-protocol/packet-macros/src/lib.rs b/azalea-protocol/packet-macros/src/lib.rs
index 22c39ea9..5b2088a1 100644
--- a/azalea-protocol/packet-macros/src/lib.rs
+++ b/azalea-protocol/packet-macros/src/lib.rs
@@ -29,9 +29,6 @@ fn as_packet_derive(
quote! { buf.write_utf(&self.#field_name)?; }
} else if path.is_ident("ResourceLocation") {
quote! { buf.write_resource_location(&self.#field_name)?; }
- // i don't know how to do this in a way that isn't terrible
- } else if path.to_token_stream().to_string() == "Vec < u8 >" {
- quote! { buf.write_bytes(&self.#field_name)?; }
} else if path.is_ident("u32") {
if f.attrs.iter().any(|attr| attr.path.is_ident("varint")) {
quote! { buf.write_varint(self.#field_name as i32)?; }
@@ -49,7 +46,7 @@ fn as_packet_derive(
}
} else {
quote! {
- crate::mc_buf::McBufVarintWritable::write_into(&self.#field_name, buf)?;
+ crate::mc_buf::McBufWritable::write_into(&self.#field_name, buf)?;
}
}
@@ -77,8 +74,6 @@ fn as_packet_derive(
quote! { let #field_name = buf.read_utf().await?; }
} else if path.is_ident("ResourceLocation") {
quote! { let #field_name = buf.read_resource_location().await?; }
- } else if path.to_token_stream().to_string() == "Vec < u8 >" {
- quote! { let #field_name = buf.read_bytes().await?; }
} else if path.is_ident("u32") {
if f.attrs.iter().any(|a| a.path.is_ident("varint")) {
quote! { let #field_name = buf.read_varint().await? as u32; }
diff --git a/azalea-protocol/src/mc_buf/read.rs b/azalea-protocol/src/mc_buf/read.rs
index c429eb7f..683c7d9a 100644
--- a/azalea-protocol/src/mc_buf/read.rs
+++ b/azalea-protocol/src/mc_buf/read.rs
@@ -228,3 +228,13 @@ impl McBufVarintReadable for i32 {
buf.read_varint().await
}
}
+
+#[async_trait]
+impl McBufReadable for Vec<u8> {
+ async fn read_into<R>(buf: &mut R) -> Result<Self, String>
+ where
+ R: AsyncRead + std::marker::Unpin + std::marker::Send,
+ {
+ buf.read_bytes().await
+ }
+}
diff --git a/azalea-protocol/src/mc_buf/write.rs b/azalea-protocol/src/mc_buf/write.rs
index 3c3375b9..7b1ac861 100644
--- a/azalea-protocol/src/mc_buf/write.rs
+++ b/azalea-protocol/src/mc_buf/write.rs
@@ -178,3 +178,9 @@ impl McBufVarintWritable for i32 {
buf.write_varint(*self)
}
}
+
+impl McBufWritable for Vec<u8> {
+ fn write_into(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
+ buf.write_bytes(self)
+ }
+}
diff --git a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs
index cd48b304..8301c089 100644
--- a/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs
+++ b/azalea-protocol/src/packets/game/clientbound_update_view_distance_packet.rs
@@ -1,6 +1,5 @@
-// i don't know the actual name of this packet, i couldn't find it in the source code!
+// i don't know the actual name of this packet, i couldn't find it in the source code
-use crate::mc_buf::{Readable, Writable};
use packet_macros::GamePacket;
#[derive(Clone, Debug, GamePacket)]