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>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>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.
Trait Implementations§
Source§impl Clone for DeflateOptions
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