pub struct CompressionPolicy { /* private fields */ }Expand description
Policy controlling when compression is applied.
By default, messages below 1 KiB are not compressed — at that size, compression overhead (headers, Huffman tables, checksums) typically exceeds the space savings, and the CPU cost of initializing the compressor dominates.
§Example
use connectrpc::CompressionPolicy;
// Only compress messages >= 4 KiB
let policy = CompressionPolicy::default().min_size(4096);
assert!(!policy.should_compress(1024));
assert!(policy.should_compress(8192));
// Disable compression entirely
let policy = CompressionPolicy::disabled();
assert!(!policy.should_compress(1_000_000));Implementations§
Source§impl CompressionPolicy
impl CompressionPolicy
Sourcepub fn min_size(self, size: usize) -> Self
pub fn min_size(self, size: usize) -> Self
Set the minimum message size for compression.
Messages smaller than this (in bytes, before compression) will be sent uncompressed even if compression is negotiated.
Sourcepub fn should_compress(&self, message_size: usize) -> bool
pub fn should_compress(&self, message_size: usize) -> bool
Check whether compression should be applied for a message of the given size.
Zero-length bodies are compressed when min_size == 0 (useful for
conformance testing where the runner checks that advertised encodings
are used even for empty payloads). The Connect spec requires receivers
to skip decompression for zero-length content, so this is safe.
Trait Implementations§
Source§impl Clone for CompressionPolicy
impl Clone for CompressionPolicy
Source§fn clone(&self) -> CompressionPolicy
fn clone(&self) -> CompressionPolicy
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more