Expand description
Binary framing: message ids, fragmentation and reassembly.
After the Noise handshake every application message is one Noise transport message. Its
plaintext starts with a one-byte binary message id: 0 carries a UTF-8 JSON body, 1 is the
fragmentation channel, and each role owns its own ids (for example 4 for player audio).
MAX_PLAINTEXT_LEN bounds one plaintext, so a larger payload has to be split.
Fragmentation keeps the byte layout of the published protocol:
first fragment [1][flags with the first bit][original message id][data]
later fragments [1][flags][data]Bit 0 of the flags byte marks the last fragment, bit 1 the first one, and bits 2-7 must be
zero. Only one fragmented message may be in flight per direction, so the receiver appends every
fragment to one buffer and dispatches the result when the last flag arrives. Reassembler
does that for a session reading frame by frame; reassemble_binary does it for a sequence
already in hand. This module does no I/O.
Re-exports§
pub use crate::noise::MAX_PLAINTEXT_LEN;
Structs§
- Reassembler
- Incremental reassembler for one direction of a connection.
Enums§
- Frame
- One plaintext frame, classified by its leading message id.
Constants§
- BINARY_
MESSAGE_ ID_ FRAGMENT - Binary message id of a fragment.
- BINARY_
MESSAGE_ ID_ JSON - Binary message id of a JSON message body.
- FRAGMENT_
FLAGS_ RESERVED - Fragment flag bits that are reserved and must be zero.
- FRAGMENT_
FLAG_ FIRST - Fragment flag marking the first fragment of a message.
- FRAGMENT_
FLAG_ LAST - Fragment flag marking the last fragment of a message.
- MAX_
REASSEMBLED_ LEN - Largest reassembled message, bounding the buffer a peer can make the receiver allocate.
Functions§
- decode_
frame - Decodes one Noise transport plaintext into a
Frame. - encode_
binary - Encodes one binary message: the id byte followed by the payload.
- max_
audio_ payload - Largest encoded-audio payload that fits one frame without fragmentation.
- reassemble_
binary - Reassembles a complete sequence of frames into the original message.
- split_
binary - Splits a binary message into plaintext frames that each fit
max_plaintext.