Open James-NZ opened 2 years ago
In the develop
branch there's no fallthrough but an explicit return HSER_POLL_EMPTY;
, so the functionality is essentially the same.
It seems that you're right and HSER_POLL_MORE
should be returned in this case.
Do you have the input and parameters (window size, backref length) with which you observe the bug?
heatshrink_encoder_poll() is returning 'HSER_POLL_EMPTY' rather than 'HSER_POLL_MORE' when finishing and the output buffer is full. Is a break missing from the 'HSES_FLUSH_BITS' case? As implemented, it is dropping through to the 'HSES_DONE' case and returning 'HSER_POLL_EMPTY' rather than running through the 'HSER_POLL_MORE' check?
Logging without break:
I observe the desired behaviour with:
Logging with break:
This behaviour is not seen in the example usage, since heatshrink_decoder_poll is also called until 'poll_sz == 0', rather than just until pres != HSDR_POLL_MORE.
If heatshrink_encoder_poll() is returns 'HSER_POLL_MORE' when finishing and the output buffer is full, the usage can be simplified by only needing to call heatshrink_decoder_finish() once to set the finish flag. If it returns 'HSDR_FINISH_MORE', keep calling heatshrink_encoder_poll() until it returns 'HSER_POLL_EMPTY' i.e. same as when sinking.
Pseudo code without error handling:
I believe the encoder example in the following pull request has an issue without changing the fall-through to a break in the 'HSES_FLUSH_BITS' case, as this is what I based my implementation on i.e. a single call to heatshrink_encoder_finish(): https://github.com/atomicobject/heatshrink/pull/54/commits