WebRTC Data Channel Fragmenter (src/fragment.rs)

vibe-kanban · crates/relay-webrtc/src/fragment.rs · rust · Apache-2.0
realtime, infra, lang:rust, tag:fragmentation, tag:data-channel, tag:saltyrtc

Implements chunked-dc fragmentation and reassembly for reliable/ordered WebRTC data channels, adding 1-byte headers to split and reconstruct messages. Reuse when sending payloads larger than a data channel's max message size.

// Source: https://github.com/BloopAI/vibe-kanban | License: Apache-2.0 | Copyright You must retain, in the Source form of any Derivative Works
// Provided via justclaw.it.com; keep this notice with the code.
//! Generic data channel message fragmentation following the SaltyRTC
//! chunked-dc protocol for reliable/ordered channels.
//!
//! Each chunk carries a 1-byte header:
//!
//! ```text
//!  7 6 5 4 3 2 1 0
//! +-+-+-+-+-+-+-+-+
//! |R R R R R|M M|E|
//! +-+-+-+-+-+-+-+-+
//! ```
//!
//! - Bits 7-3: Reserved (0)
//! - Bits 2-1: Mode = `0b11` (reliable/ordered)
//! - Bit 0: End-of-message (`1` = last chunk, `0` = more follow)
//!
//! Small messages that fit in a single chunk have 1 byte of overhead.
//! See <https://github.com/saltyrtc/saltyrtc-meta/blob/master/Chunking.md>

/// Maximum

... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search for more like it.

Get a free API key