pub enum Compression {
Disabled,
Dedicated,
Shared,
Window256B,
Window1KB,
Window2KB,
Window4KB,
Window8KB,
Window16KB,
Window32KB,
}Expand description
Compression mode for WebSocket connections (RFC 7692 permessage-deflate)
This enum controls how compression is handled for WebSocket connections.
Per RFC 7692, the LZ77 sliding window size is limited to 8-15 bits (256 bytes to 32KB). Larger windows provide better compression but use more memory per connection.
§Memory Usage per Connection
| Mode | Description | Window Bits | Window Size |
|---|---|---|---|
Disabled | No compression | - | - |
Dedicated | Per-connection compressor | 15 | 32KB |
Shared | Shared compressor pool | 15 | 32KB |
Window256B | Minimal memory | 8 | 256B |
Window1KB | 1KB sliding window | 10 | 1KB |
Window2KB | 2KB sliding window | 11 | 2KB |
Window4KB | 4KB sliding window | 12 | 4KB |
Window8KB | 8KB sliding window | 13 | 8KB |
Window16KB | 16KB sliding window | 14 | 16KB |
Window32KB | 32KB sliding window (max) | 15 | 32KB |
Variants§
Disabled
No compression
Dedicated
Dedicated compressor per connection (32KB window, best compression)
Shared compressor pool (32KB window, good for many connections)
Window256B
256 byte sliding window (window_bits=8, minimal memory)
Window1KB
1KB sliding window (window_bits=10)
Window2KB
2KB sliding window (window_bits=11)
Window4KB
4KB sliding window (window_bits=12)
Window8KB
8KB sliding window (window_bits=13)
Window16KB
16KB sliding window (window_bits=14)
Window32KB
32KB sliding window (window_bits=15, maximum per RFC 7692)
Implementations§
Source§impl Compression
impl Compression
Sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Returns true if compression is enabled
Returns true if this mode uses shared compression
Sourcepub fn is_dedicated(&self) -> bool
pub fn is_dedicated(&self) -> bool
Returns true if this mode uses dedicated per-connection compression
Sourcepub fn window_bits(&self) -> u8
pub fn window_bits(&self) -> u8
Get the window bits for this compression mode
Returns the LZ77 window bits (8-15) for RFC 7692 compliance.
Sourcepub fn compression_threshold(&self) -> usize
pub fn compression_threshold(&self) -> usize
Get the compression threshold for this mode
Messages smaller than this threshold won’t be compressed. Larger window modes benefit more from compressing smaller messages.
Sourcepub fn context_takeover(&self) -> bool
pub fn context_takeover(&self) -> bool
Whether to use context takeover (preserve compression dictionary between messages)
Smaller window modes disable context takeover to reduce memory. Shared mode also disables context takeover since the encoder pool cannot maintain context across different connections. Larger dedicated modes enable it for better compression across messages.
Sourcepub fn to_deflate_config(&self) -> Option<DeflateConfig>
pub fn to_deflate_config(&self) -> Option<DeflateConfig>
Convert to DeflateConfig
Trait Implementations§
Source§impl Clone for Compression
impl Clone for Compression
Source§fn clone(&self) -> Compression
fn clone(&self) -> Compression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more