MOSH fragmentation allows a logical message payload to be larger than a single on-wire frame.
The MOSH protocol standard limits the maximum encoded frame size to 1470 bytes. That full frame includes:
That means the largest unfragmented payload is:
1470 - 13 - 2 = 1455 bytes
Any payload larger than 1455 bytes must be split into multiple fragment frames before transmission.
A fragment is still a normal MOSH frame, but it has the `FLAG_IS_FRAGMENT` bit set and uses the first 4 bytes of its payload as a fragment header:
The remaining payload bytes in the fragment are fragment data.
For a transport with a 1470-byte frame limit:
When a frame is sent, MOSH first checks whether the encoded frame would exceed the transport's maximum frame length.
If it fits:
If it does not fit:
This means a large logical payload is transmitted as a sequence of smaller wire-safe frames.
On receipt, each frame is decoded normally.
If the fragment flag is not set:
If the fragment flag is set:
A fragment set is considered valid only if:
If the fragment metadata changes mid-stream, or the final payload length does not match, the reassembly buffer is discarded.
There are two important limits:
In practice, the true upper limit is also constrained by available RAM, especially on embedded devices such as the ESP32.
On the current MOSH implementation:
As a result, application code can work with large payloads without needing to manually split or reassemble them.