aboutsummaryrefslogtreecommitdiff
path: root/azalea-protocol/src/packets/mod.rs
diff options
context:
space:
mode:
authormat <27899617+mat-1@users.noreply.github.com>2022-05-02 03:10:52 +0000
committerGitHub <noreply@github.com>2022-05-02 03:10:52 +0000
commit728f0399ff1a03f5ce8134b46e6150daf1e2076d (patch)
tree5a21ef239d8e5cabdc0b5d3d511e35dc25435041 /azalea-protocol/src/packets/mod.rs
parentc2262a212328e7a9e00091d7b41a8d8bfb5b3007 (diff)
parente1b6bc965a3f71d64b4dc3075da21c578ab5b508 (diff)
downloadazalea-drasl-728f0399ff1a03f5ce8134b46e6150daf1e2076d.tar.xz
Merge pull request #4 from mat-1/sync-decoding
Reduce usage of AsyncRead
Diffstat (limited to 'azalea-protocol/src/packets/mod.rs')
-rwxr-xr-xazalea-protocol/src/packets/mod.rs21
1 files changed, 5 insertions, 16 deletions
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<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
- id: u32,
- flow: &PacketFlow,
- buf: &mut T,
- ) -> Result<Self, String>
- where
- Self: Sized;
+ fn read(id: u32, flow: &PacketFlow, buf: &mut impl Read) -> Result<Self, String>;
fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error>;
}
-#[async_trait]
impl McBufReadable for ConnectionProtocol {
- async fn read_into<R>(buf: &mut R) -> Result<Self, String>
- where
- R: AsyncRead + std::marker::Unpin + std::marker::Send,
- {
- ConnectionProtocol::from_i32(buf.read_varint().await?)
+ fn read_into(buf: &mut impl Read) -> Result<Self, String> {
+ ConnectionProtocol::from_i32(buf.read_varint()?)
.ok_or_else(|| "Invalid intention".to_string())
}
}