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/read.rs | |
| parent | dc62ada865db6534e7c4a5a958d82c44e42bf089 (diff) | |
| download | azalea-drasl-4a1ec068fc13393e249853403085be6958a807a4.tar.xz | |
improved docs
Diffstat (limited to 'azalea-protocol/src/read.rs')
| -rw-r--r-- | azalea-protocol/src/read.rs | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/azalea-protocol/src/read.rs b/azalea-protocol/src/read.rs index 8d8bc731..a459d3bb 100644 --- a/azalea-protocol/src/read.rs +++ b/azalea-protocol/src/read.rs @@ -1,3 +1,5 @@ +//! Read packets from a stream. + use crate::packets::ProtocolPacket; use azalea_buf::BufReadError; use azalea_buf::McBufVarReadable; @@ -157,6 +159,8 @@ pub enum DecompressionError { AboveCompressionThreshold { size: u32, maximum: u32 }, } +/// Get the decompressed bytes from a packet. It must have been decrypted +/// first. fn compression_decoder( stream: &mut Cursor<&[u8]>, compression_threshold: u32, @@ -192,6 +196,12 @@ fn compression_decoder( Ok(decoded_buf) } +/// Read a single packet from a stream. +/// +/// The buffer is required because servers may send multiple packets in the +/// same frame, so we need to store the packet data that's left to read. +/// +/// The current protocol state must be passed as a generic. pub async fn read_packet<'a, P: ProtocolPacket + Debug, R>( stream: &'a mut R, buffer: &mut BytesMut, |
