1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 14:26:04 +00:00
azalea/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
mat 567c6f4f2c 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.
2022-05-01 21:54:03 -05:00

30 lines
768 B
Rust
Executable file

use std::{hash::Hash, io::Read};
use crate::mc_buf::{Readable, Writable};
use super::LoginPacket;
#[derive(Hash, Clone, Debug)]
pub struct ClientboundLoginCompressionPacket {
pub compression_threshold: i32,
}
impl ClientboundLoginCompressionPacket {
pub fn get(self) -> LoginPacket {
LoginPacket::ClientboundLoginCompressionPacket(self)
}
pub fn write(&self, buf: &mut Vec<u8>) -> Result<(), std::io::Error> {
buf.write_varint(self.compression_threshold).unwrap();
Ok(())
}
pub fn read(buf: &mut impl Read) -> Result<LoginPacket, String> {
let compression_threshold = buf.read_varint()?;
Ok(ClientboundLoginCompressionPacket {
compression_threshold,
}
.get())
}
}