diff options
| author | Ubuntu <github@matdoes.dev> | 2022-11-11 21:04:18 +0000 |
|---|---|---|
| committer | Ubuntu <github@matdoes.dev> | 2022-11-11 21:04:18 +0000 |
| commit | 4a1ec068fc13393e249853403085be6958a807a4 (patch) | |
| tree | bdaf6de36f1682eef0839122af1ba9037fa95165 /azalea-protocol/src/write.rs | |
| parent | dc62ada865db6534e7c4a5a958d82c44e42bf089 (diff) | |
| download | azalea-drasl-4a1ec068fc13393e249853403085be6958a807a4.tar.xz | |
improved docs
Diffstat (limited to 'azalea-protocol/src/write.rs')
| -rwxr-xr-x | azalea-protocol/src/write.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/azalea-protocol/src/write.rs b/azalea-protocol/src/write.rs index 8e56e5fc..10f09165 100755 --- a/azalea-protocol/src/write.rs +++ b/azalea-protocol/src/write.rs @@ -1,3 +1,5 @@ +//! Write packets to a stream. + use crate::{packets::ProtocolPacket, read::MAXIMUM_UNCOMPRESSED_LENGTH}; use async_compression::tokio::bufread::ZlibEncoder; use azalea_buf::McBufVarWritable; @@ -6,10 +8,11 @@ use std::fmt::Debug; use thiserror::Error; use tokio::io::{AsyncReadExt, AsyncWrite, AsyncWriteExt}; -fn frame_prepender(data: &mut Vec<u8>) -> Result<Vec<u8>, std::io::Error> { +/// Prepend the length of the packet to it. +fn frame_prepender(mut data: Vec<u8>) -> Result<Vec<u8>, std::io::Error> { let mut buf = Vec::new(); (data.len() as u32).var_write_into(&mut buf)?; - buf.append(data); + buf.append(&mut data); Ok(buf) } @@ -82,7 +85,7 @@ where if let Some(threshold) = compression_threshold { buf = compression_encoder(&buf, threshold).await.unwrap(); } - buf = frame_prepender(&mut buf).unwrap(); + buf = frame_prepender(buf).unwrap(); // if we were given a cipher, encrypt the packet if let Some(cipher) = cipher { azalea_crypto::encrypt_packet(cipher, &mut buf); |
