Skip to content

Commit

Permalink
still break
Browse files Browse the repository at this point in the history
  • Loading branch information
nothendev committed Oct 9, 2023
1 parent f08fcd5 commit 27e4951
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 1 addition & 2 deletions protocol/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ impl PlayerNet {

let compressing = Arc::new(AtomicBool::new(false));

let compressing_ = compressing.clone();
let send_task = tokio::spawn(async move {
let Err::<!, _>(e) = async {
loop {
Expand All @@ -203,7 +202,7 @@ impl PlayerNet {
trace!("[send]not compressing");
packet.serialize()?
};
trace!(?packet, ?data, "sending packet");
trace!(initial_packet=?packet, ?data, "sending packet");
write.write_all(&data).await?;
}
}
Expand Down
20 changes: 14 additions & 6 deletions protocol/src/model/packets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,24 @@ impl SerializedPacket {

pub fn serialize_compressing(&self, compression: Option<usize>) -> Result<Bytes, Error> {
if let Some(cmp) = compression {
let maybe_data_length = self.length + self.id.length_of();
let (data_length, length) = if maybe_data_length >= cmp {
let (data_length, length) = if self.length >= cmp {
(
maybe_data_length,
Zlib::encode(&self.data)?.len() + VarInt(maybe_data_length as i32).length_of(),
self.length,
Compress((&self.id, &self.data), Zlib).serialize()?.len()
+ VarInt(self.length as i32).length_of(),
)
} else {
trace!("packet was smaller than threshold {cmp}, sending uncompressed");
(0, self.length)
trace!(
threshold=%cmp,
actual_length=%self.length,
cmpr_length=%self.length + 1,
id_length=%self.id.length_of(),
data_length=%self.data.len(),
"packet was smaller than threshold, sending uncompressed"
);
(0, self.length + 1)
};

let pack = SerializedPacketCompressed {
length,
data_length,
Expand Down

0 comments on commit 27e4951

Please sign in to comment.