#include "compression.h"

#include <lz4/lz4.h>

RT_DLLEXPORT size_t rtGetCompressionBound(size_t uncompressed_size) {
    return (size_t)LZ4_compressBound((int)uncompressed_size);
}

RT_DLLEXPORT size_t rtCompressData(const void *in,
                                   size_t uncompressed_size,
                                   void *out,
                                   size_t out_capacity) {
    return (size_t)LZ4_compress_default((const char *)in,
                                        (char *)out,
                                        (int)uncompressed_size,
                                        (int)out_capacity);
}

RT_DLLEXPORT size_t rtDecompressData(const void *in,
                                     size_t compressed_size,
                                     void *out,
                                     size_t out_capacity) {
    int res =
        LZ4_decompress_safe((const char *)in, (char *)out, (int)compressed_size, (int)out_capacity);
    return (res > 0) ? (size_t)res : 0;
}