diff options
| author | mat <github@matdoes.dev> | 2022-01-02 00:03:04 -0600 |
|---|---|---|
| committer | mat <github@matdoes.dev> | 2022-01-02 00:03:04 -0600 |
| commit | 3ec7352da2c8a9870718e6a81913f6aa1b576b95 (patch) | |
| tree | 9b067763246eb43fb5928eeacf7aed18e9e90236 /azalea-protocol/src/packets/login | |
| parent | a1afbb6031527c1db5831fc8e916bc0ecce633b4 (diff) | |
| download | azalea-drasl-3ec7352da2c8a9870718e6a81913f6aa1b576b95.tar.xz | |
add macro for a couple more packets
Diffstat (limited to 'azalea-protocol/src/packets/login')
| -rw-r--r-- | azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs | 32 |
1 files changed, 3 insertions, 29 deletions
diff --git a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs index 22e58b0d..77262c43 100644 --- a/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_custom_query_packet.rs @@ -1,38 +1,12 @@ -use super::LoginPacket; use crate::mc_buf::{Readable, Writable}; use azalea_core::resource_location::ResourceLocation; +use packet_macros::LoginPacket; use std::hash::Hash; -#[derive(Hash, Clone, Debug)] +#[derive(Hash, Clone, Debug, LoginPacket)] pub struct ClientboundCustomQueryPacket { + #[varint] pub transaction_id: u32, pub identifier: ResourceLocation, pub data: Vec<u8>, } - -impl ClientboundCustomQueryPacket { - pub fn get(self) -> LoginPacket { - LoginPacket::ClientboundCustomQueryPacket(self) - } - - pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> { - buf.write_varint(self.transaction_id as i32).unwrap(); - buf.write_utf(self.identifier.to_string().as_str()).unwrap(); - buf.write_bytes(&self.data).unwrap(); - Ok(()) - } - - pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>( - buf: &mut T, - ) -> Result<LoginPacket, String> { - let transaction_id = buf.read_varint().await? as u32; - let identifier = ResourceLocation::new(&buf.read_utf().await?)?; - let data = buf.read_bytes_with_len(1048576).await?; - Ok(ClientboundCustomQueryPacket { - transaction_id, - identifier, - data, - } - .get()) - } -} |
