From 4a1ec068fc13393e249853403085be6958a807a4 Mon Sep 17 00:00:00 2001 From: Ubuntu Date: Fri, 11 Nov 2022 21:04:18 +0000 Subject: improved docs --- azalea-protocol/src/read.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'azalea-protocol/src/read.rs') 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, -- cgit v1.2.3