From 2466185ccca0cf5f5ae1781cb2dab8904ba31fd1 Mon Sep 17 00:00:00 2001 From: Natalia Portillo Date: Sat, 30 Oct 2021 22:58:03 +0100 Subject: [PATCH] Add stubs to export BZIP2, LZFSE, LZMA and ZSTD. --- library.c | 84 +++++++++++++++++++++++++++++++++++++++++++++++-- library.h | 55 ++++++++++++++++++++++++++++++++ tests/bzip2.cpp | 15 ++++----- tests/lzfse.cpp | 10 +++--- tests/lzma.cpp | 9 +++--- tests/zstd.cpp | 8 ++--- 6 files changed, 160 insertions(+), 21 deletions(-) diff --git a/library.c b/library.c index 556f0a0..32c523f 100644 --- a/library.c +++ b/library.c @@ -18,8 +18,88 @@ #include #include -#include #include "library.h" +#include "3rdparty/bzip2/bzlib.h" +#include "3rdparty/lzfse/src/lzfse.h" +#include "3rdparty/lzma-21.03beta/C/LzmaLib.h" +#include "3rdparty/zstd-1.5.0/lib/zstd.h" -void hello(void) { printf("Hello, World!\n"); } +AARU_EXPORT int32_t AARU_CALL AARU_bzip2_decode_buffer(uint8_t* dst_buffer, + uint32_t* dst_size, + const uint8_t* src_buffer, + uint32_t src_size) +{ + return BZ2_bzBuffToBuffDecompress((char*)dst_buffer, dst_size, (char*)src_buffer, src_size, 0, 0); +} + +AARU_EXPORT int32_t AARU_CALL AARU_bzip2_encode_buffer(uint8_t* dst_buffer, + uint32_t* dst_size, + const uint8_t* src_buffer, + uint32_t src_size, + int32_t blockSize100k) +{ + return BZ2_bzBuffToBuffCompress((char*)dst_buffer, dst_size, (char*)src_buffer, src_size, blockSize100k, 0, 0); +} + +AARU_EXPORT size_t AARU_CALL AARU_lzfse_decode_buffer(uint8_t* dst_buffer, + size_t dst_size, + const uint8_t* src_buffer, + size_t src_size, + void* scratch_buffer) +{ + return lzfse_decode_buffer(dst_buffer, dst_size, src_buffer, src_size, scratch_buffer); +} +AARU_EXPORT size_t AARU_CALL AARU_lzfse_encode_buffer(uint8_t* dst_buffer, + size_t dst_size, + const uint8_t* src_buffer, + size_t src_size, + void* scratch_buffer) +{ + return lzfse_encode_buffer(dst_buffer, dst_size, src_buffer, src_size, scratch_buffer); +} + +AARU_EXPORT int32_t AARU_CALL AARU_lzma_decode_buffer(uint8_t* dst_buffer, + size_t* dst_size, + const uint8_t* src_buffer, + size_t* srcLen, + const uint8_t* props, + size_t propsSize) +{ + return LzmaUncompress(dst_buffer, dst_size, src_buffer, srcLen, props, propsSize); +} + +AARU_EXPORT int32_t AARU_CALL AARU_lzma_encode_buffer(uint8_t* dst_buffer, + size_t* dst_size, + const uint8_t* src_buffer, + size_t srcLen, + uint8_t* outProps, + size_t* outPropsSize, + int32_t level, + uint32_t dictSize, + int32_t lc, + int32_t lp, + int32_t pb, + int32_t fb, + int32_t numThreads) +{ + return LzmaCompress( + dst_buffer, dst_size, src_buffer, srcLen, outProps, outPropsSize, level, dictSize, lc, lp, pb, fb, numThreads); +} + +AARU_EXPORT size_t AARU_CALL AARU_zstd_decode_buffer(void* dst_buffer, + size_t dst_size, + const void* src_buffer, + size_t src_size) +{ + return ZSTD_decompress(dst_buffer, dst_size, src_buffer, src_size); +} + +AARU_EXPORT size_t AARU_CALL AARU_zstd_encode_buffer(void* dst_buffer, + size_t dst_size, + const void* src_buffer, + size_t src_size, + int32_t compressionLevel) +{ + return ZSTD_compress(dst_buffer, dst_size, src_buffer, src_size, compressionLevel); +} \ No newline at end of file diff --git a/library.h b/library.h index 2ede1f7..e79e75c 100644 --- a/library.h +++ b/library.h @@ -97,4 +97,59 @@ AARU_EXPORT int32_t AARU_CALL AARU_lzip_encode_buffer(uint8_t* dst_buffer, int32_t dictionary_size, int32_t match_len_limit); +AARU_EXPORT int32_t AARU_CALL AARU_bzip2_decode_buffer(uint8_t* dst_buffer, + uint32_t* dst_size, + const uint8_t* src_buffer, + uint32_t src_size); + +AARU_EXPORT int32_t AARU_CALL AARU_bzip2_encode_buffer(uint8_t* dst_buffer, + uint32_t* dst_size, + const uint8_t* src_buffer, + uint32_t src_size, + int32_t blockSize100k); + +AARU_EXPORT size_t AARU_CALL AARU_lzfse_decode_buffer(uint8_t* dst_buffer, + size_t dst_size, + const uint8_t* src_buffer, + size_t src_size, + void* scratch_buffer); + +AARU_EXPORT size_t AARU_CALL AARU_lzfse_encode_buffer(uint8_t* dst_buffer, + size_t dst_size, + const uint8_t* src_buffer, + size_t src_size, + void* scratch_buffer); + +AARU_EXPORT int32_t AARU_CALL AARU_lzma_decode_buffer(uint8_t* dst_buffer, + size_t* dst_size, + const uint8_t* src_buffer, + size_t* src_size, + const uint8_t* props, + size_t propsSize); + +AARU_EXPORT int32_t AARU_CALL AARU_lzma_encode_buffer(uint8_t* dst_buffer, + size_t* dst_size, + const uint8_t* src_buffer, + size_t src_size, + uint8_t* outProps, + size_t* outPropsSize, + int32_t level, + uint32_t dictSize, + int32_t lc, + int32_t lp, + int32_t pb, + int32_t fb, + int32_t numThreads); + +AARU_EXPORT size_t AARU_CALL AARU_zstd_decode_buffer(void* dst_buffer, + size_t dst_size, + const void* src_buffer, + size_t src_size); + +AARU_EXPORT size_t AARU_CALL AARU_zstd_encode_buffer(void* dst_buffer, + size_t dst_size, + const void* src_buffer, + size_t src_size, + int32_t compressionLevel); + #endif // AARU_COMPRESSION_NATIVE_LIBRARY_H diff --git a/tests/bzip2.cpp b/tests/bzip2.cpp index d9ab36e..1094563 100644 --- a/tests/bzip2.cpp +++ b/tests/bzip2.cpp @@ -17,9 +17,10 @@ */ #include +#include #include -#include "../3rdparty/bzip2/bzlib.h" +#include "../library.h" #include "crc32.h" #include "gtest/gtest.h" @@ -66,9 +67,9 @@ TEST_F(bzip2Fixture, bzip2) uint real_size = 1048576; auto* outBuf = (uint8_t*)malloc(1048576); - auto bz_err = BZ2_bzBuffToBuffDecompress((char*)outBuf, &real_size, (char*)buffer, 1053934, 0, 0); + auto bz_err = AARU_bzip2_decode_buffer(outBuf, &real_size, buffer, 1053934); - EXPECT_EQ(bz_err, BZ_OK); + EXPECT_EQ(bz_err, 0); EXPECT_EQ(real_size, 1048576); @@ -110,14 +111,14 @@ TEST_F(bzip2Fixture, bzip2Compress) original_crc = crc32_data(original, original_len); // Compress - bz_err = BZ2_bzBuffToBuffCompress((char*)(cmp_buffer), &cmp_len, (char*)original, original_len, 9, 0, 0); + bz_err = AARU_bzip2_encode_buffer(cmp_buffer, &cmp_len, original, original_len, 9); - EXPECT_EQ(bz_err, BZ_OK); + EXPECT_EQ(bz_err, 0); // Decompress - bz_err = BZ2_bzBuffToBuffDecompress((char*)decmp_buffer, &decmp_len, (char*)cmp_buffer, cmp_len, 0, 0); + bz_err = AARU_bzip2_decode_buffer(decmp_buffer, &decmp_len, cmp_buffer, cmp_len); - EXPECT_EQ(bz_err, BZ_OK); + EXPECT_EQ(bz_err, 0); EXPECT_EQ(decmp_len, original_len); diff --git a/tests/lzfse.cpp b/tests/lzfse.cpp index c666f44..0c423a3 100644 --- a/tests/lzfse.cpp +++ b/tests/lzfse.cpp @@ -17,8 +17,10 @@ */ #include +#include +#include -#include "../3rdparty/lzfse/src/lzfse.h" +#include "../library.h" #include "crc32.h" #include "gtest/gtest.h" @@ -64,7 +66,7 @@ TEST_F(lzfseFixture, lzfse) { auto* outBuf = (uint8_t*)malloc(1048576); - auto decoded = lzfse_decode_buffer(outBuf, 1048576, buffer, 1059299, NULL); + auto decoded = AARU_lzfse_decode_buffer(outBuf, 1048576, buffer, 1059299, nullptr); EXPECT_EQ(decoded, 1048576); @@ -106,11 +108,11 @@ TEST_F(lzfseFixture, lzfseCompress) original_crc = crc32_data(original, original_len); // Compress - newSize = lzfse_encode_buffer(cmp_buffer, cmp_len, original, original_len, nullptr); + newSize = AARU_lzfse_encode_buffer(cmp_buffer, cmp_len, original, original_len, nullptr); cmp_len = newSize; // Decompress - newSize = lzfse_decode_buffer(decmp_buffer, decmp_len, cmp_buffer, cmp_len, nullptr); + newSize = AARU_lzfse_decode_buffer(decmp_buffer, decmp_len, cmp_buffer, cmp_len, nullptr); decmp_len = newSize; EXPECT_EQ(decmp_len, original_len); diff --git a/tests/lzma.cpp b/tests/lzma.cpp index b51fd0a..6a157a4 100644 --- a/tests/lzma.cpp +++ b/tests/lzma.cpp @@ -17,9 +17,9 @@ */ #include +#include #include -#include "../3rdparty/lzma-21.03beta/C/LzmaLib.h" #include "../library.h" #include "crc32.h" #include "gtest/gtest.h" @@ -69,7 +69,7 @@ TEST_F(lzmaFixture, lzma) size_t srcLen = 1200275; auto* outBuf = (uint8_t*)malloc(8388608); - auto err = LzmaUncompress(outBuf, &destLen, buffer, &srcLen, params, 5); + auto err = AARU_lzma_decode_buffer(outBuf, &destLen, buffer, &srcLen, params, 5); EXPECT_EQ(err, 0); EXPECT_EQ(destLen, 8388608); @@ -114,11 +114,12 @@ TEST_F(lzmaFixture, lzmaCompress) original_crc = crc32_data(original, original_len); // Compress - err = LzmaCompress(cmp_buffer, &cmp_len, original, original_len, props, &props_len, 9, 1048576, 3, 0, 2, 273, 2); + err = AARU_lzma_encode_buffer( + cmp_buffer, &cmp_len, original, original_len, props, &props_len, 9, 1048576, 3, 0, 2, 273, 2); EXPECT_EQ(err, 0); // Decompress - err = LzmaUncompress(decmp_buffer, &decmp_len, cmp_buffer, &cmp_len, props, props_len); + err = AARU_lzma_decode_buffer(decmp_buffer, &decmp_len, cmp_buffer, &cmp_len, props, props_len); EXPECT_EQ(err, 0); EXPECT_EQ(decmp_len, original_len); diff --git a/tests/zstd.cpp b/tests/zstd.cpp index 59a8b65..e621118 100644 --- a/tests/zstd.cpp +++ b/tests/zstd.cpp @@ -17,9 +17,9 @@ */ #include +#include #include -#include "../3rdparty/zstd-1.5.0/lib/zstd.h" #include "../library.h" #include "crc32.h" #include "gtest/gtest.h" @@ -66,7 +66,7 @@ TEST_F(zstdFixture, zstd) { auto* outBuf = (uint8_t*)malloc(1048576); - auto decoded = ZSTD_decompress(outBuf, 1048576, buffer, 1048613); + auto decoded = AARU_zstd_decode_buffer(outBuf, 1048576, buffer, 1048613); EXPECT_EQ(decoded, 1048576); @@ -108,11 +108,11 @@ TEST_F(zstdFixture, zstdCompress) original_crc = crc32_data(original, original_len); // Compress - newSize = ZSTD_compress(cmp_buffer, cmp_len, original, original_len, 22); + newSize = AARU_zstd_encode_buffer(cmp_buffer, cmp_len, original, original_len, 22); cmp_len = newSize; // Decompress - newSize = ZSTD_decompress(decmp_buffer, decmp_len, cmp_buffer, cmp_len); + newSize = AARU_zstd_decode_buffer(decmp_buffer, decmp_len, cmp_buffer, cmp_len); decmp_len = newSize; EXPECT_EQ(decmp_len, original_len);