Skip to content

ImprovOpReassembler

Source: ImprovOpReassembler.h

ImprovOpReassembler

class ImprovOpReassembler
src/core/util/ImprovOpReassembler.h:28

The state machine that joins chunked Improv op frames back into one op-JSON buffer.

Public Methods

inline ImprovOpReassembler(char * buf, size_t cap) : Reassemble into buf, of which one byte is reserved for the NUL.

inline Result feed(uint8_t seq, bool last, const uint8_t * chunk, size_t chunkLen) : Feed one chunk, seq being its 0-based index and last true on the final one.

inline const char * out() const : The reassembled op, complete and NUL-terminated once [feed] returns Ready.

inline size_t len() const : How many bytes of [out] the finished op filled.

inline void reset() : Drop any partial op, for a consumer that wants a clean slate.

Public Types

enum Result : What a fed chunk left the reassembler in.

Value Description
Continue
Ready
Error

More info

Where it sits

This is the pure logic behind the device's 0xFC handler, which treats Improv as REST over serial. The platform layer in platform_esp32_improv.cpp owns the serial I/O, reading frames, sending acks and errors, and holding the single-buffer opReady atomic; it hands each chunk's [seq][last][bytes] here. That is the same core-against-platform line ImprovFrame.h draws, so the reassembly and its sequence guard are proven on the desktop without hardware.

Why the sequence guard is real

A chunk carries [seq][last][chunk bytes]. Sequence 0 starts a fresh op and resets the buffer, and every later chunk must be the next sequence in order. A duplicate, which an installer retry on a misread timeout produces, or an out-of-order chunk would splice garbage into the buffer. Both are rejected and the buffer is reset. USB serial delivers in order, but the installer's send is open-loop and can re-emit a chunk, so the guard guards something that happens.

Joins the chunks of one op into a NUL-terminated buffer the caller owns.