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. --- azalea-protocol/src/packets/mod.rs | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) (limited to 'azalea-protocol/src/packets/mod.rs') diff --git a/azalea-protocol/src/packets/mod.rs b/azalea-protocol/src/packets/mod.rs index 98741a75..67fa92e9 100755 --- a/azalea-protocol/src/packets/mod.rs +++ b/azalea-protocol/src/packets/mod.rs @@ -3,14 +3,14 @@ pub mod handshake; pub mod login; pub mod status; +use std::io::Read; + use crate::{ connect::PacketFlow, mc_buf::{McBufReadable, McBufWritable, Readable, Writable}, }; -use async_trait::async_trait; use num_derive::FromPrimitive; use num_traits::FromPrimitive; -use tokio::io::AsyncRead; pub const PROTOCOL_VERSION: u32 = 758; @@ -31,7 +31,6 @@ pub enum Packet { } /// An enum of packets for a certain protocol -#[async_trait] pub trait ProtocolPacket where Self: Sized, @@ -39,24 +38,14 @@ where fn id(&self) -> u32; /// Read a packet by its id, ConnectionProtocol, and flow - async fn read( - id: u32, - flow: &PacketFlow, - buf: &mut T, - ) -> Result - where - Self: Sized; + fn read(id: u32, flow: &PacketFlow, buf: &mut impl Read) -> Result; fn write(&self, buf: &mut Vec) -> Result<(), std::io::Error>; } -#[async_trait] impl McBufReadable for ConnectionProtocol { - async fn read_into(buf: &mut R) -> Result - where - R: AsyncRead + std::marker::Unpin + std::marker::Send, - { - ConnectionProtocol::from_i32(buf.read_varint().await?) + fn read_into(buf: &mut impl Read) -> Result { + ConnectionProtocol::from_i32(buf.read_varint()?) .ok_or_else(|| "Invalid intention".to_string()) } } -- cgit v1.2.3