pub struct FrameCompressor { /* private fields */ }compression only.Expand description
Encodes/decodes Frames into compressed wire form.
Wire format (inside a Frame::Binary, big-endian irrelevant — single
byte header):
+-------+---------------------------------+
| flags | payload |
+-------+---------------------------------+
bit 0: payload is raw-DEFLATE compressed (else identity)
bit 1: original frame was Text (else Binary)Cloning is cheap; share one compressor across tasks (&self API).
Implementations§
Source§impl FrameCompressor
impl FrameCompressor
Sourcepub fn new(config: CompressionConfig) -> Self
pub fn new(config: CompressionConfig) -> Self
A compressor with the given settings.
Sourcepub fn with_defaults() -> Self
pub fn with_defaults() -> Self
A compressor with CompressionConfig::default settings.
Sourcepub fn config(&self) -> &CompressionConfig
pub fn config(&self) -> &CompressionConfig
Active settings.
Sourcepub fn compress(&self, data: &[u8]) -> Result<Vec<u8>, WsError>
pub fn compress(&self, data: &[u8]) -> Result<Vec<u8>, WsError>
Compress a payload into the envelope form.
Payloads below CompressionConfig::min_size — or payloads deflate
cannot shrink (already-compressed data) — are stored as identity;
the envelope still marks them so the peer decodes either way.
Sourcepub fn decompress(&self, enveloped: &[u8]) -> Result<Vec<u8>, WsError>
pub fn decompress(&self, enveloped: &[u8]) -> Result<Vec<u8>, WsError>
Decode an envelope produced by FrameCompressor::compress,
returning the original payload bytes.
Enforces the decompression-bomb guard during inflation.
Sourcepub fn compress_frame(&self, frame: Frame) -> Result<Frame, WsError>
pub fn compress_frame(&self, frame: Frame) -> Result<Frame, WsError>
Compress a Frame into a wire-ready Frame::Binary envelope.
Frame::Binary payloads pass through as-is bytes; Frame::Text
payloads are compressed from and restored to their exact UTF-8
bytes — never re-validated through lossy conversion.
Sourcepub fn decompress_frame(&self, frame: Frame) -> Result<Frame, WsError>
pub fn decompress_frame(&self, frame: Frame) -> Result<Frame, WsError>
Restore a Frame from a FrameCompressor::compress_frame
envelope. Text frames come back as Frame::Text (invalid UTF-8 is
a hard error — no lossy coercion), binary as Frame::Binary.