pub enum CompressionContext {
Disabled,
Dedicated(DeflateContext),
Shared {
pool: Arc<SharedCompressorPool>,
decoder: DeflateDecoder,
config: DeflateConfig,
},
}Expand description
A compression context that can be either dedicated or shared
Variants§
Disabled
No compression
Dedicated(DeflateContext)
Dedicated per-connection compressor
Shared compressor from pool (encoder only, decoder is per-connection)
Implementations§
Source§impl CompressionContext
impl CompressionContext
Sourcepub fn server(mode: Compression) -> Self
pub fn server(mode: Compression) -> Self
Create a new compression context for the given mode (server role)
Sourcepub fn client(mode: Compression) -> Self
pub fn client(mode: Compression) -> Self
Create a new compression context for the given mode (client role)
Create a shared context that uses an existing pool
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check if compression is enabled
Sourcepub fn compress(&mut self, data: &[u8]) -> Result<Option<Bytes>>
pub fn compress(&mut self, data: &[u8]) -> Result<Option<Bytes>>
Compress a message payload
Returns None if compression is disabled or if compression wouldn’t reduce size.
Sourcepub fn decompress(&mut self, data: &[u8], max_size: usize) -> Result<Bytes>
pub fn decompress(&mut self, data: &[u8], max_size: usize) -> Result<Bytes>
Decompress a message payload
Sourcepub fn config(&self) -> Option<&DeflateConfig>
pub fn config(&self) -> Option<&DeflateConfig>
Get the DeflateConfig for this context
Auto Trait Implementations§
impl Freeze for CompressionContext
impl !RefUnwindSafe for CompressionContext
impl Send for CompressionContext
impl Sync for CompressionContext
impl Unpin for CompressionContext
impl !UnwindSafe for CompressionContext
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