From 567c6f4f2c39976d170111b816806453636f8241 Mon Sep 17 00:00:00 2001 From: mat Date: Sun, 1 May 2022 21:54:03 -0500 Subject: Reduce usage of AsyncRead We already receive everything from the server when it tells us the length, so we can actually just treat the stream as a Read instead of an AsyncRead. --- .../packets/game/clientbound_player_info_packet.rs | 23 ++++++++-------------- 1 file changed, 8 insertions(+), 15 deletions(-) (limited to 'azalea-protocol/src/packets/game/clientbound_player_info_packet.rs') diff --git a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs index 3d4c3ac7..97b68259 100644 --- a/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs +++ b/azalea-protocol/src/packets/game/clientbound_player_info_packet.rs @@ -1,10 +1,7 @@ -// i don't know the actual name of this packet, i couldn't find it in the source code - use crate::mc_buf::{McBufReadable, McBufWritable, Readable, Writable}; -use async_trait::async_trait; use azalea_chat::component::Component; use packet_macros::{GamePacket, McBufReadable, McBufWritable}; -use tokio::io::AsyncRead; +use std::io::Read; use uuid::Uuid; #[derive(Clone, Debug, GamePacket)] @@ -64,19 +61,15 @@ pub struct RemovePlayer { uuid: Uuid, } -#[async_trait] impl McBufReadable for Action { - async fn read_into(buf: &mut R) -> Result - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - let id = buf.read_byte().await?; + fn read_into(buf: &mut impl Read) -> Result { + let id = buf.read_byte()?; Ok(match id { - 0 => Action::AddPlayer(Vec::::read_into(buf).await?), - 1 => Action::UpdateGameMode(Vec::::read_into(buf).await?), - 2 => Action::UpdateLatency(Vec::::read_into(buf).await?), - 3 => Action::UpdateDisplayName(Vec::::read_into(buf).await?), - 4 => Action::RemovePlayer(Vec::::read_into(buf).await?), + 0 => Action::AddPlayer(Vec::::read_into(buf)?), + 1 => Action::UpdateGameMode(Vec::::read_into(buf)?), + 2 => Action::UpdateLatency(Vec::::read_into(buf)?), + 3 => Action::UpdateDisplayName(Vec::::read_into(buf)?), + 4 => Action::RemovePlayer(Vec::::read_into(buf)?), _ => panic!("Unknown player info action id: {}", id), }) } -- cgit v1.2.3