Message fragmentation

Version 0.3.0 Updated Apr 06, 2026

WireframeApp keeps transport fragmentation disabled by default. Enable it explicitly with enable_fragmentation() or provide a bespoke FragmentationConfig using fragmentation(Some(cfg)). When enabled, payloads that exceed the frame budget are split into fragments carrying a FragmentHeader (message_id, fragment_index, is_last_fragment) wrapped with the FRAG marker. The connection reassembles fragments before invoking handlers, so handlers continue to work with complete Envelope values.[^6]

Layering order is fixed. Outbound processing runs serializer → fragmentation → codec wrapping. Inbound processing runs codec decode → fragment reassembly → deserialization.

Fragmented messages enforce two guards: max_message_size caps the total reassembled payload, and reassembly_timeout evicts stale partial messages. Customize or disable fragmentation via the builder:

use std::{num::NonZeroUsize, time::Duration};
use wireframe::{
    app::WireframeApp,
    fragment::FragmentationConfig,
};

// Assume `handler` is defined elsewhere; any Handler compatible with WireframeApp works.
let cfg = FragmentationConfig::for_frame_budget(
    1024,
    NonZeroUsize::new(16 * 1024).unwrap(),
    Duration::from_secs(30),
).expect("frame budget too small for fragments");

let app = WireframeApp::new()?
    .fragmentation(Some(cfg))
    .route(42, handler)?;

Call fragmentation(None) to keep fragmentation disabled after explicit configuration (for example, when the transport already supports large frames or fragmentation is delegated to an upstream gateway). The ConnectionActor mirrors the same behaviour for push traffic and streaming responses through enable_fragmentation, ensuring client-visible frames follow the same format.

On the server side, a unified FramePipeline applies the same fragmentation logic to all outbound Envelope values — handler responses, streaming frames, and multi-packet channels — before serialization and codec wrapping. This guarantees that a single connection-scoped FragmentationState manages both outbound fragmentation and inbound reassembly.