Skip to content

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

Description

@cerilloderek

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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions