Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] What should heatshrink_encoder_poll and heatshrink_encoder_finish return if nothing has been sunk? #75

Open
cerilloderek opened this issue Jan 20, 2023 · 1 comment

Comments

@cerilloderek
Copy link

New to heatshrink, and I'm running into an issue where I'm getting stuck in a while loop while polling on what I imagine is an empty encoder.

uint8_t buf[32];
heatshrink_encoder_reset(&hse);

// some logic here that reads some file contents and sinks it into the encoder - it's possible that `heatshrink_encoder_sink` is not called at all here

while (heatshrink_encoder_finish(&hse)==HSER_FINISH_MORE) {
    heatshrink_encoder_poll(&hse, buf, 32, &num_compressed_bytes_output);
    // do something with buf
}

In cases where the "some logic" part calls heatshrink_encoder_sink at least once, this works just fine
When heatshrink_encoder_sink never gets called, that while loop at the end continues forever and seems to be filling the buf with stuff from memory. I had expected heatshrink_encoder_finish(&hse)==HSER_FINISH_MORE to be true if nothing was sunk into the encoder, but clearly I"m missing something.

My current fix is just to sink a blank string into the encoder before starting to poll, and that seems to work out

        size_t num_bytes_sunk = 0;
        uint8_t dummyBuf[1] = "";
        heatshrink_encoder_sink(&hse, dummyBuf, 1,&num_bytes_sunk);

Any advice on the proper way to poll when there might not be anything sunk into the encoder?

@BenBE
Copy link

BenBE commented Jan 20, 2023

Cf. issue #57.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants