Skip to main content

Module message

Module message 

Source
Expand description

Per-message compression for WebSocket permessage-deflate (RFC 7692).

A message is compressed with a sync flush and sent without the trailing 00 00 FF FF; the receiver appends those four bytes and inflates. With context takeover the window carries over between messages; without it every message stands alone (the safer default: secrets in one message cannot leak through the compressed size of the next, RFC 7692 section 8).

This module does the codec part only. Negotiating Sec-WebSocket-Extensions, the RSV1 bit, and the per-message opt-out belong to the WebSocket layer.

use compress_lib::message::{Compressor, Decompressor, MessageConfig};

let config = MessageConfig::new().with_window_bits(12);
let mut tx = Compressor::new(config)?;
let mut rx = Decompressor::new(config)?;
let mut wire = Vec::new();
tx.compress_message(b"{\"hello\":\"world\"}", &mut wire)?;
let mut text = Vec::new();
rx.decompress_message(&wire, &mut text, 1 << 20)?;
assert_eq!(text, b"{\"hello\":\"world\"}");

Structsยง

Compressor
Compresses messages for permessage-deflate.
Decompressor
Decompresses permessage-deflate messages.
MessageConfig
Settings for one direction of a permessage-deflate connection.