pub struct FrameDecoder { /* private fields */ }Expand description
Splits a byte stream into packets.
Implementations§
Source§impl FrameDecoder
impl FrameDecoder
Sourcepub fn new() -> Self
pub fn new() -> Self
A decoder with no compression, no encryption, default limits and no filter.
Sourcepub fn set_limits(&mut self, limits: FrameLimits)
pub fn set_limits(&mut self, limits: FrameLimits)
Sets the limits.
Sourcepub fn set_compression(&mut self, threshold: i32)
pub fn set_compression(&mut self, threshold: i32)
Turns compression on or off (from the server’s Set Compression packet; a negative threshold means off). Call it right after decoding that packet.
Sourcepub fn compression(&self) -> bool
pub fn compression(&self) -> bool
Whether compression is on.
Sourcepub fn enable_encryption(&mut self, secret: &[u8; 16])
pub fn enable_encryption(&mut self, secret: &[u8; 16])
Turns on decryption. Bytes already buffered but not yet split into frames are decrypted too, since the server encrypts everything after its encryption request was answered.
Sourcepub fn is_encrypted(&self) -> bool
pub fn is_encrypted(&self) -> bool
Whether decryption is on.
Sourcepub fn set_filter(&mut self, filter: PacketFilter)
pub fn set_filter(&mut self, filter: PacketFilter)
Sets the per-id interest filter.
Sourcepub fn filter(&self) -> &PacketFilter
pub fn filter(&self) -> &PacketFilter
The current filter.
Sourcepub fn stats(&self) -> DecoderStats
pub fn stats(&self) -> DecoderStats
Counters.
Sourcepub fn push(&mut self, data: &[u8])
pub fn push(&mut self, data: &[u8])
Appends received bytes (decrypting them if encryption is on).
Sourcepub fn buffer_mut(&mut self) -> &mut BytesMut
pub fn buffer_mut(&mut self) -> &mut BytesMut
The receive buffer, for reading directly into it. After appending n bytes call
FrameDecoder::commit with the length before the read.
Sourcepub fn commit(&mut self, old_len: usize)
pub fn commit(&mut self, old_len: usize)
Decrypts bytes appended to FrameDecoder::buffer_mut since old_len.
Sourcepub fn needed(&self) -> Option<usize>
pub fn needed(&self) -> Option<usize>
How many more bytes are needed to complete the next frame, if known.
Sourcepub fn next_packet(&mut self) -> Result<Option<RawPacket>, FrameError>
pub fn next_packet(&mut self) -> Result<Option<RawPacket>, FrameError>
Splits off the next packet that passes the filter.
Returns Ok(None) when more bytes are needed. Errors are fatal for the
connection (the stream position is lost).