lsalzman / enet

ENet reliable UDP networking library
MIT License
2.71k stars 668 forks source link

enet_range_coder_compress always returns 0 #152

Closed moien007 closed 3 years ago

moien007 commented 3 years ago

enet_range_coder_compress() always returns zero.

The following code reproduces the problem (assertion fails).

int main(int argc, char const *argv[])
{
    void* range_coder = enet_range_coder_create();

    const char uncompressed[] = "Hello World!"; 
    char compressed[sizeof(uncompressed) + 1];

    ENetBuffer buffer;
    buffer.data = uncompressed;
    buffer.dataLength = sizeof(uncompressed);
    size_t compressedLen = enet_range_coder_compress(range_coder, &buffer, 1, UINT_MAX, compressed, sizeof(compressed));

    assert(compressedLen != 0);

    return 0;
}
lsalzman commented 3 years ago

It returns zero because there is insufficient space in the output buffer to store the result. Compression algorithms are never guaranteed to always make data smaller, especially when the data to be compressed is smaller and not very repetitive in the first place.

RealYukiSan commented 3 months ago

Is there any function like enet_range_coder_compress but doing decompress instead of compress?

bjorn commented 3 months ago

@RealYukiSan Yes, it's called enet_range_coder_decompress. :-)