pub struct DeflateOptions {
pub level: CompressionLevel,
pub server_max_window_bits: Option<u8>,
pub client_max_window_bits: Option<u8>,
pub server_no_context_takeover: bool,
pub client_no_context_takeover: bool,
}Expand description
Configuration options for WebSocket message compression using the Deflate algorithm.
The WebSocket protocol supports per-message compression using a Deflate-based algorithm (RFC 7692) to reduce bandwidth usage. This struct allows fine-grained control over compression behavior and memory usage through several key settings:
§Compression Level
Controls the tradeoff between compression ratio and CPU usage via the level field.
Higher levels provide better compression but require more processing time.
§Context Management
Offers two modes for managing the compression context:
-
Context Takeover (default): Maintains compression state between messages, providing better compression ratios at the cost of increased memory usage. Ideal for applications prioritizing bandwidth efficiency.
-
No Context Takeover: Resets compression state after each message, reducing memory usage at the expense of compression efficiency. Better suited for memory-constrained environments.
§Memory Window Size
When the zlib feature is enabled, allows precise control over the compression
window size for both client and server, enabling further optimization of the
memory-compression tradeoff.
§Example
use yawc::{DeflateOptions, CompressionLevel};
let opts = DeflateOptions {
level: CompressionLevel::default(),
server_no_context_takeover: true,
..Default::default()
};Fields§
§level: CompressionLevelSets the compression level (0-9), balancing compression ratio against CPU usage.
- 0: No compression (fastest)
- 1-3: Low compression (fast)
- 4-6: Medium compression (default)
- 7-9: High compression (slow)
server_max_window_bits: Option<u8>zlib only.Controls the compression window size (in bits) for server-side compression.
Larger windows improve compression but use more memory. Available only with
the zlib feature enabled. Valid range: 8-15 bits.
client_max_window_bits: Option<u8>zlib only.Controls the compression window size (in bits) for client-side compression.
Larger windows improve compression but use more memory. Available only with
the zlib feature enabled. Valid range: 8-15 bits.
server_no_context_takeover: boolControls server-side compression context management.
When true, compression state is reset after each message, reducing
memory usage at the cost of compression efficiency.
client_no_context_takeover: boolControls client-side compression context management.
When true, compression state is reset after each message, reducing
memory usage at the cost of compression efficiency.
Implementations§
Source§impl DeflateOptions
impl DeflateOptions
Sourcepub fn low_latency() -> Self
Available on non-WebAssembly only.
pub fn low_latency() -> Self
Creates compression settings optimized for low latency.
This profile uses:
- Fast compression level (level 1)
- No context takeover on both sides to minimize memory and processing
Best for real-time applications where latency is critical.
Sourcepub fn high_compression() -> Self
Available on non-WebAssembly only.
pub fn high_compression() -> Self
Creates compression settings optimized for maximum compression.
This profile uses:
- Best compression level (level 9)
- Context takeover enabled for better compression ratios
Best for bandwidth-constrained scenarios where CPU is available.
Trait Implementations§
Source§impl Clone for DeflateOptions
Available on non-WebAssembly only.
impl Clone for DeflateOptions
Source§fn clone(&self) -> DeflateOptions
fn clone(&self) -> DeflateOptions
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more