Skip to main content

Module framing

Module framing 

Source
Expand description

Transport framing over SimpleX direct connections (specification §5).

An envelope’s compact JSON text travels as one whole frame message (zaun:1:<json>) or, when it does not fit the per-message budget, as 2–32 fragment messages (zaun:1f:<frag_id>:<index>:<count>:<chunk>). encode produces the messages, classify recognises an inbound text, and a Reassembler per connection joins fragments under the bounds of §5.2. Every message emitted costs one SMP message against the in-flight window (§10.5), so EncodedFrame::smp_messages is what flow control counts.

Pure: no I/O, no clock (time is now_ms), no randomness (the caller supplies FragId).

Modules§

app_data
How one frame message travels as SimpleX application data (specification §5.1): content type DATA_TAG, the frame text under FRAME_KEY, and the fixed FALLBACK_TEXT an app without Zaun shows.

Structs§

EncodedFrame
The transport messages of one frame, in sending order.
FragId
A fragment id: 8 random bytes, unique per sender per connection among open reassemblies.
Fragment
One fragment message (§5.1), borrowing its chunk from the received text.
Reassembler
Per-connection reassembly state machine (§5.2).

Enums§

DiscardReason
Why a reassembly (or a fragment that would start one) was discarded. A discard produces no response; the sender’s retry repairs it (§5.2, §7.3).
EncodeError
Why an envelope cannot be framed.
Inbound
What an inbound transport text is (§5.3).
Pushed
The result of pushing one fragment.

Constants§

FRAGMENT_PREFIX
Prefix of a fragment message.
FRAG_ID_CHARS
Length of an encoded FragId (8 bytes, base64url without padding).
MIN_BUDGET
The smallest accepted per-message budget: a fragment header plus one character at its largest escaped (six bytes, escaped_len).
PROTOCOL_PREFIX
Prefix shared by every protocol message; text without it is not a protocol message (§5.3).
WHOLE_PREFIX
Prefix of a whole-envelope message.

Functions§

classify
Classifies one inbound text message. The zaun:1f: prefix is tested before zaun:1: (they differ at the 7th byte, so the order is only for clarity).
encode
Frames the compact envelope JSON json (§5.1).
escaped_len
The bytes text takes written inside a JSON string, as a frame message travels in its application data (§5.1): " and \ take two, the control characters JSON writes as \b, \t, \n, \f, \r two, every other control character six (\u00XX).