mirror of
https://github.com/mat-1/azalea.git
synced 2025-08-02 14:26:04 +00:00
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.
30 lines
768 B
Rust
Executable file
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())
|
|
}
|
|
}
|