Turn fragmentation on
A frame has a size limit, 1,024 bytes by default, and some messages are larger. Fragmentation splits an oversized payload into fragments that each fit a frame, then rejoins them on the far side before protocol message assembly. It is off by default. enable_fragmentation() derives a configuration from the frame limit: messages up to sixteen frames’ worth (16 KiB by default), partial messages evicted after 30 seconds, and caps on how much a peer can leave unfinished. Both ends must speak this format, and WireframeClient does not: a client talking to a fragmenting server sees FRAG payloads.
fn budgets() -> MemoryBudgets {
let bytes = |n: usize| BudgetBytes::new(NonZeroUsize::new(n).expect("non-zero"));
MemoryBudgets::new(bytes(16 * 1024), bytes(64 * 1024), bytes(48 * 1024))
}
let received = Arc::new(Mutex::new(Vec::new()));
let handler_received = Arc::clone(&received);
let echo: Handler<Envelope> = Arc::new(move |env: &Envelope| {
*handler_received.lock().expect("record request") = env.payload_bytes().to_vec();
Box::pin(async {})
});
let app: WireframeApp = WireframeApp::new()
.expect("builder")
.enable_fragmentation()
.memory_budgets(budgets())
.route(1, echo)
.expect("a route");
The layering is fixed. Outbound, a reply is fragmented, then each fragment is serialized, wrapped by the codec, passed to before_send, and encoded, so each fragment is its own frame. Streamed frames are fragmented the same way. Pushes and stream terminators are already codec frames, and skip it. Inbound, each frame is decoded and deserialized as an envelope, then fragments are reassembled before protocol message assembly. Each fragment carries a FragmentHeader (message ID, index, and a last-fragment flag) behind a FRAG marker.
fragmentation(Some(config)) sets limits explicitly; FragmentationConfig::for_frame_budget builds one from a frame size, a maximum message size, and a reassembly timeout. Remember that changing the codec or buffer_capacity clears it.
let limit = NonZeroUsize::new(16 * 1024).expect("non-zero");
let config = FragmentationConfig::for_frame_budget(1024, limit, Duration::from_secs(30))
.expect("the budget covers the fragment header");
// At most min(frame budget, 64) partial messages at once...
assert_eq!(
config.max_concurrent_partials.map(NonZeroUsize::get),
Some(64)
);
// ...holding at most the larger of 64 frames and one whole message.
assert_eq!(
config.max_buffered_bytes.map(NonZeroUsize::get),
Some(64 * 1024)
);
A message over max_message_size counts as a deserialization failure. Exceeding max_concurrent_partials or max_buffered_bytes closes the connection immediately.
Split and rejoin by hand
The pieces the connection uses are public. Fragmenter slices a payload into capped fragments that share a message ID and count up from zero:
let fragmenter = Fragmenter::new(NonZeroUsize::new(512).expect("non-zero"));
let message = [7_u8; 1400];
let batch = fragmenter.fragment_bytes(message).expect("fragment");
assert_eq!(batch.len(), 3);
let last = batch.fragments().last().expect("a final fragment");
assert!(last.header().is_last_fragment());
Reassembler is its mirror. It buffers fragments per message ID, rejects fragments out of order, enforces the maximum assembled size, and offers purge_expired for partial messages that never finish. It takes the two aggregate caps after its other arguments; None leaves one unbounded, as in the sample. The final fragment returns the whole message.
let cap = NonZeroUsize::new(4096).expect("non-zero");
let mut reassembler = Reassembler::new(cap, Duration::from_secs(30), None, None);
let id = MessageId::new(9);
let first = FragmentHeader::new(id, FragmentIndex::zero(), false);
assert!(
reassembler
.push(first, [1_u8; 8])
.expect("accepted")
.is_none()
);
let second = FragmentHeader::new(id, FragmentIndex::new(1), true);
let whole = reassembler
.push(second, [2_u8; 8])
.expect("accepted")
.expect("the final fragment completes the message");
assert_eq!(
whole.payload(),
&[1_u8; 8].into_iter().chain([2_u8; 8]).collect::<Vec<_>>()
);
Message assembly is different
Fragmentation is wireframe’s own transport mechanism, invisible to the protocol. Some protocols define their own multi-frame messages instead, with a first frame and continuations in their own header format. For those, a MessageAssembler, installed with with_message_assembler, parses each frame’s header into a first frame or a continuation, keyed by a MessageKey.
Assembly runs after fragment reassembly and before dispatch. It can hold several messages open at once, interleaved on one connection, and, where the protocol numbers its continuations, it rejects gaps, duplicates, and frames after the last. Ordinary routes receive the completed message. A streaming route can consume validated body chunks as they arrive.
A declared total_body_len is a commitment. A length mismatch rejects a buffered message before dispatch. A live streaming handler may have read chunks before the mismatch ends its stream. None opts out of the equality check. A declared total also lets the assembler reject an oversized message on its first frame.
Memory budgets

Partial messages cost memory, and a peer can send first frames forever. MemoryBudgets caps three things per connection: the size of one message, bytes held by the connection, and bytes in flight. Without explicit budgets, wireframe derives them from the frame limit: 16, 64, and 64 times it, which is 16, 64, and 64 KiB by default.

| Tier | When | What happens |
|---|---|---|
Per frame, with a MessageAssembler only | A frame would push buffered bytes past a cap | The frame is rejected, that partial message is freed, and the failure counts as a deserialization failure |
| Soft limit | Buffered bytes reach 80% of the smaller aggregate cap | The connection pauses briefly before reading the next frame, pushing back on the sender |
| Hard cap | Buffered bytes exceed the smaller aggregate cap | The connection closes |

Read pacing and the hard cap count partial fragments, buffered assemblies, queued body chunks, and completed messages waiting behind a live body. Even with message assembly off, fragments count towards those limits.
A message’s size includes first-frame metadata plus the accumulated body. The effective limit is the smaller of max_message_size and bytes_per_message. On the first frame, a larger declared body length counts in place of the body received so far. Continuations are checked against the cap as they arrive. See the migration guide’s size-cap changes.

