How to use the heatshrink encoder and decoder API
masterThe encoder and decoder operate as state machines using a streaming pattern. Follow these steps to process data:
- Initialize: Allocate a
heatshrink_encoderorheatshrink_decoderstate machine using their respectiveallocfunctions, or statically allocate one and call theirresetfunction to initialize it. - Sink Input: Use
sinkto feed an input buffer into the state machine. Theinput_sizepointer argument will be updated to indicate how many bytes were actually consumed. Ifinput_sizeis 0, the buffer is full. - Poll Output: Use
pollto move data from the state machine into an output buffer. Theoutput_sizepointer argument will be updated to indicate how many bytes were output. The return value indicates if further output is available. - Finish Stream: When the input stream ends, call
finishto notify the state machine. Iffinishindicates output remains, continue callingpolluntil it indicates the output is exhausted.
Note: You cannot sink more data after calling finish without calling reset first.