1
2
Fork 0
mirror of https://github.com/mat-1/azalea.git synced 2025-08-02 06:16:04 +00:00
azalea/azalea-protocol/src/packets/login/clientbound_login_compression_packet.rs
2021-12-16 23:33:06 -06:00

32 lines
821 B
Rust

use std::hash::Hash;
use tokio::io::BufReader;
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>) {
buf.write_varint(self.compression_threshold).unwrap();
}
pub async fn read<T: tokio::io::AsyncRead + std::marker::Unpin + std::marker::Send>(
buf: &mut T,
) -> Result<LoginPacket, String> {
let compression_threshold = buf.read_varint().await?;
Ok(ClientboundLoginCompressionPacket {
compression_threshold,
}
.get())
}
}