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.
FrameDecoder::reserve_read also makes room for the read first.
Sourcepub fn reserve_read(&mut self) -> &mut BytesMut
pub fn reserve_read(&mut self) -> &mut BytesMut
The receive buffer with room for the next read: at least the rest of the frame being
received, at least a couple of KB otherwise. The consumed front is reused in place when
no packet still shares the buffer. After appending call FrameDecoder::commit with
the length before the read, as with FrameDecoder::buffer_mut.
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 set_detach_frames(&mut self, on: bool)
pub fn set_detach_frames(&mut self, on: bool)
Copies uncompressed frames out of the receive buffer instead of sharing it with the packets (off by default). A packet body that something keeps (a registry entry, a profile property) then does not keep a whole receive buffer alive. Meant for the short login and configuration states: it costs an allocation per frame.
Sourcepub fn rehome(&mut self)
pub fn rehome(&mut self)
Moves the buffered bytes to a fresh receive buffer of the standard size. Packets split off before keep the old buffer (only) to themselves; call it at a state change (the end of the configuration) so that the packets of the new state do not share a buffer with data kept from the old one.
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).