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. --- .../src/packets/login/clientbound_game_profile_packet.rs | 16 ++++++++-------- .../src/packets/login/clientbound_hello_packet.rs | 12 +++++------- .../login/clientbound_login_compression_packet.rs | 8 +++----- 3 files changed, 16 insertions(+), 20 deletions(-) (limited to 'azalea-protocol/src/packets/login') diff --git a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs index ccf0f482..bcdcd105 100755 --- a/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_game_profile_packet.rs @@ -1,3 +1,5 @@ +use std::io::Read; + use super::LoginPacket; use crate::mc_buf::{Readable, Writable}; use azalea_auth::game_profile::GameProfile; @@ -23,17 +25,15 @@ impl ClientboundGameProfilePacket { Ok(()) } - pub async fn read( - buf: &mut T, - ) -> Result { + pub fn read(buf: &mut impl Read) -> Result { // TODO: we have a thing to read from the uuid now let uuid = Uuid::from_int_array([ - buf.read_int().await? as u32, - buf.read_int().await? as u32, - buf.read_int().await? as u32, - buf.read_int().await? as u32, + buf.read_int()? as u32, + buf.read_int()? as u32, + buf.read_int()? as u32, + buf.read_int()? as u32, ]); - let name = buf.read_utf_with_len(16).await?; + let name = buf.read_utf_with_len(16)?; Ok(ClientboundGameProfilePacket { game_profile: GameProfile::new(uuid, name), } diff --git a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs index 20af1bec..06f346c2 100755 --- a/azalea-protocol/src/packets/login/clientbound_hello_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_hello_packet.rs @@ -1,4 +1,4 @@ -use std::hash::Hash; +use std::{hash::Hash, io::Read}; use super::LoginPacket; use crate::mc_buf::Readable; @@ -19,12 +19,10 @@ impl ClientboundHelloPacket { panic!("ClientboundHelloPacket::write not implemented") } - pub async fn read( - buf: &mut T, - ) -> Result { - let server_id = buf.read_utf_with_len(20).await?; - let public_key = buf.read_byte_array().await?; - let nonce = buf.read_byte_array().await?; + pub fn read(buf: &mut impl Read) -> Result { + let server_id = buf.read_utf_with_len(20)?; + let public_key = buf.read_byte_array()?; + let nonce = buf.read_byte_array()?; Ok(ClientboundHelloPacket { server_id, diff --git a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs index a88c6cbf..a5ab78bb 100755 --- a/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs +++ b/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs @@ -1,4 +1,4 @@ -use std::hash::Hash; +use std::{hash::Hash, io::Read}; use crate::mc_buf::{Readable, Writable}; @@ -19,10 +19,8 @@ impl ClientboundLoginCompressionPacket { Ok(()) } - pub async fn read( - buf: &mut T, - ) -> Result { - let compression_threshold = buf.read_varint().await?; + pub fn read(buf: &mut impl Read) -> Result { + let compression_threshold = buf.read_varint()?; Ok(ClientboundLoginCompressionPacket { compression_threshold, -- cgit v1.2.3