#[non_exhaustive]pub struct MessageConfig { /* private fields */ }Expand description
Settings for one direction of a permessage-deflate connection.
| Setting | Default | RFC 7692 parameter |
|---|---|---|
| window bits | 15 | server_max_window_bits / client_max_window_bits |
| context takeover | off | server_no_context_takeover / client_no_context_takeover absent |
| level | 1 | (local choice) |
Idle connections: without takeover nothing carries over between
messages, so an idle connection can drop its engines and build new ones
when traffic returns (construction allocates the sizes below once, about
a microsecond for a decompressor). With takeover the window is
connection state and must be kept; Compressor::wipe and
Decompressor::wipe zero it when the connection ends.
Memory per direction: without takeover a Decompressor holds only its
decode tables (about 11 KiB, no window); with takeover it adds the window
(2^window_bits bytes). A Compressor holds a deflater sized by the
window bits (about 270 KiB at 15, under 100 KiB at 9).
§Examples
use compress_lib::{Level, message::MessageConfig};
let config = MessageConfig::new().with_window_bits(10).with_context_takeover(true).with_level(Level::DEFAULT);
assert_eq!(config.window_bits(), 10);
assert!(config.context_takeover());Implementations§
Source§impl MessageConfig
impl MessageConfig
Sourcepub const fn new() -> Self
pub const fn new() -> Self
Window bits 15, no context takeover, level 1.
§Examples
use compress_lib::message::MessageConfig;
assert_eq!(MessageConfig::new(), MessageConfig::default());
assert!(!MessageConfig::new().context_takeover());Sourcepub const fn with_window_bits(self, bits: u8) -> Self
pub const fn with_window_bits(self, bits: u8) -> Self
Sets the window bits, 8 to 15 (checked when an engine is built).
§Examples
assert_eq!(compress_lib::message::MessageConfig::new().with_window_bits(9).window_bits(), 9);Sourcepub const fn with_context_takeover(self, on: bool) -> Self
pub const fn with_context_takeover(self, on: bool) -> Self
Keeps the window from one message to the next.
§Examples
assert!(compress_lib::message::MessageConfig::new().with_context_takeover(true).context_takeover());Sourcepub const fn with_level(self, level: Level) -> Self
pub const fn with_level(self, level: Level) -> Self
Sets the compression level (the compressor only).
§Examples
use compress_lib::{Level, message::MessageConfig};
assert_eq!(MessageConfig::new().with_level(Level::BEST).level(), Level::BEST);Sourcepub const fn with_memory(self, memory: MemoryConfig) -> Self
pub const fn with_memory(self, memory: MemoryConfig) -> Self
Sizes the compressor’s hash table and symbol buffer (see
MemoryConfig); the decompressor is not affected.
§Examples
use compress_lib::{deflate::MemoryConfig, message::MessageConfig};
let config = MessageConfig::new().with_memory(MemoryConfig::new().with_hash_bits(10));
assert_eq!(config.memory().hash_bits(), 10);Sourcepub const fn memory(&self) -> MemoryConfig
pub const fn memory(&self) -> MemoryConfig
The compressor’s memory settings.
§Examples
assert_eq!(compress_lib::message::MessageConfig::new().memory().hash_bits(), 0);Sourcepub const fn window_bits(&self) -> u8
pub const fn window_bits(&self) -> u8
The window bits.
§Examples
assert_eq!(compress_lib::message::MessageConfig::new().window_bits(), 15);Sourcepub const fn context_takeover(&self) -> bool
pub const fn context_takeover(&self) -> bool
Whether the window carries over between messages.
§Examples
assert!(!compress_lib::message::MessageConfig::new().context_takeover());