pub struct RawPacket {
pub data: Vec<u8>,
}Expand description
A length-delimited on-wire packet frame.
data contains everything after the leading length VarInt: for an
uncompressed connection that is [packet_id_varint][payload], and for a
compressed connection it is [data_length_varint][compressed_or_raw_data].
Fields§
§data: Vec<u8>The raw frame data (not including the leading length VarInt).
Implementations§
Source§impl RawPacket
impl RawPacket
Sourcepub fn read_sync<R: Read>(reader: &mut R) -> Result<Self, PacketError>
pub fn read_sync<R: Read>(reader: &mut R) -> Result<Self, PacketError>
Read a length-prefixed frame from a synchronous reader.
Sourcepub fn write_sync<W: Write>(&self, writer: &mut W) -> Result<(), PacketError>
pub fn write_sync<W: Write>(&self, writer: &mut W) -> Result<(), PacketError>
Write this packet frame to a synchronous writer (length-prefixed).
Sourcepub async fn read_async<R: AsyncReadExt + Unpin>(
reader: &mut R,
) -> Result<Self, PacketError>
pub async fn read_async<R: AsyncReadExt + Unpin>( reader: &mut R, ) -> Result<Self, PacketError>
Read a length-prefixed frame from an async reader (requires async feature).
Sourcepub async fn write_async<W: AsyncWriteExt + Unpin>(
&self,
writer: &mut W,
) -> Result<(), PacketError>
pub async fn write_async<W: AsyncWriteExt + Unpin>( &self, writer: &mut W, ) -> Result<(), PacketError>
Write this packet frame to an async writer (requires async feature).
Sourcepub fn as_uncompressed(&self) -> Result<UncompressedPacket, PacketError>
pub fn as_uncompressed(&self) -> Result<UncompressedPacket, PacketError>
Interpret this frame as an uncompressed packet (no compression in effect).
Returns None if the data is empty.
Sourcepub fn uncompress(
&self,
threshold: Option<i32>,
) -> Result<UncompressedPacket, PacketError>
pub fn uncompress( &self, threshold: Option<i32>, ) -> Result<UncompressedPacket, PacketError>
Attempt to uncompress a compressed packet frame.
When threshold is None, the connection uses no compression and the
frame is interpreted as uncompressed. When threshold is Some(_) the
first field is data_length (VarInt): if 0, the rest is uncompressed;
otherwise it is the uncompressed length and the rest is zlib-deflated.
Returns Err if decompression fails.