pub struct Compressor { /* private fields */ }Expand description
Compresses messages for permessage-deflate.
§Examples
use compress_lib::message::{Compressor, MessageConfig};
let mut tx = Compressor::new(MessageConfig::new())?;
let mut wire = Vec::new();
tx.compress_message(b"Hello", &mut wire)?;
assert_eq!(wire, [0xF2, 0x48, 0xCD, 0xC9, 0xC9, 0x07, 0x00]); // RFC 7692 7.2.3.1Implementations§
Source§impl Compressor
impl Compressor
Sourcepub fn new(config: MessageConfig) -> Result<Self, Error>
pub fn new(config: MessageConfig) -> Result<Self, Error>
A compressor for one direction of a connection.
§Errors
ErrorKind::InvalidWindowBits outside 8 to 15.
§Examples
use compress_lib::message::{Compressor, MessageConfig};
assert!(Compressor::new(MessageConfig::new().with_window_bits(8)).is_ok());
assert!(Compressor::new(MessageConfig::new().with_window_bits(16)).is_err());Sourcepub fn compress_message(
&mut self,
message: &[u8],
out: &mut Vec<u8>,
) -> Result<usize, Error>
pub fn compress_message( &mut self, message: &[u8], out: &mut Vec<u8>, ) -> Result<usize, Error>
Compresses one message, appending the payload (without the trailing
00 00 FF FF) to out. Returns the payload length. An empty
message compresses to the single byte 00.
The payload can be longer than the message for incompressible data;
the WebSocket layer may then send the message uncompressed instead
(with takeover the compressor’s window has advanced either way, so
call reset and tell the peer, or keep sending
compressed).
§Errors
ErrorKind::AllocationFailed when out cannot grow.
§Examples
use compress_lib::message::{Compressor, MessageConfig};
let mut tx = Compressor::new(MessageConfig::new())?;
let mut wire = Vec::new();
assert_eq!(tx.compress_message(b"", &mut wire)?, 1);
assert_eq!(wire, [0x00]);Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Forgets the window (for a connection that restarts its context).
§Examples
use compress_lib::message::{Compressor, MessageConfig};
let mut tx = Compressor::new(MessageConfig::new().with_context_takeover(true))?;
tx.reset();Sourcepub fn memory_in_use(&self) -> usize
pub fn memory_in_use(&self) -> usize
Heap bytes held.
§Examples
use compress_lib::message::{Compressor, MessageConfig};
let small = Compressor::new(MessageConfig::new().with_window_bits(9))?;
let big = Compressor::new(MessageConfig::new())?;
assert!(small.memory_in_use() < big.memory_in_use());Trait Implementations§
Auto Trait Implementations§
impl Forget for Compressor
impl Freeze for Compressor
impl RefUnwindSafe for Compressor
impl Send for Compressor
impl Sync for Compressor
impl Unpin for Compressor
impl UnsafeUnpin for Compressor
impl UnwindSafe for Compressor
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more