-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds experimental ZSTD compression algorithm support
Signed-off-by: Alexis Jeandet <alexis.jeandet@member.fsf.org>
- Loading branch information
Showing
10 changed files
with
164 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#pragma once | ||
/*------------------------------------------------------------------------------ | ||
-- This file is a part of the CDFpp library | ||
-- Copyright (C) 2024, Plasma Physics Laboratory - CNRS | ||
-- | ||
-- This program is free software; you can redistribute it and/or modify | ||
-- it under the terms of the GNU General Public License as published by | ||
-- the Free Software Foundation; either version 2 of the License, or | ||
-- (at your option) any later version. | ||
-- | ||
-- This program is distributed in the hope that it will be useful, | ||
-- but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
-- GNU General Public License for more details. | ||
-- | ||
-- You should have received a copy of the GNU General Public License | ||
-- along with this program; if not, write to the Free Software | ||
-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
-------------------------------------------------------------------------------*/ | ||
/*-- Author : Alexis Jeandet | ||
-- Mail : alexis.jeandet@member.fsf.org | ||
----------------------------------------------------------------------------*/ | ||
#include "../cdf-debug.hpp" | ||
#include "cdfpp/no_init_vector.hpp" | ||
#include <cstddef> | ||
#include <vector> | ||
#include <zstd.h> | ||
|
||
|
||
namespace cdf::io::zstd | ||
{ | ||
namespace _internal | ||
{ | ||
|
||
template <typename T> | ||
CDF_WARN_UNUSED_RESULT std::size_t impl_inflate( | ||
const T& input, char* output, const std::size_t output_size) | ||
{ | ||
const auto ret = ZSTD_decompress(output, output_size, input.data(), std::size(input)); | ||
|
||
if (ret != ZSTD_isError(ret)) | ||
return ret; | ||
else | ||
return 0; | ||
} | ||
|
||
template <typename T> | ||
CDF_WARN_UNUSED_RESULT no_init_vector<char> impl_deflate(const T& input) | ||
{ | ||
no_init_vector<char> result(ZSTD_compressBound(std::size(input))); | ||
const auto ret | ||
= ZSTD_compress(result.data(), result.size(), input.data(), std::size(input), 1); | ||
if (ret != ZSTD_isError(ret)) | ||
{ | ||
result.resize(ret); | ||
result.shrink_to_fit(); | ||
return result; | ||
} | ||
else | ||
return {}; | ||
} | ||
} | ||
|
||
template <typename T> | ||
std::size_t inflate(const T& input, char* output, const std::size_t output_size) | ||
{ | ||
using namespace _internal; | ||
return impl_inflate(input, output, output_size); | ||
} | ||
|
||
template <typename T> | ||
no_init_vector<char> deflate(const T& input) | ||
{ | ||
using namespace _internal; | ||
return impl_deflate(input); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
[wrap-file] | ||
directory = zstd-1.5.6 | ||
source_url = https://github.com/facebook/zstd/releases/download/v1.5.6/zstd-1.5.6.tar.gz | ||
source_filename = zstd-1.5.6.tar.gz | ||
source_hash = 8c29e06cf42aacc1eafc4077ae2ec6c6fcb96a626157e0593d5e82a34fd403c1 | ||
patch_filename = zstd_1.5.6-2_patch.zip | ||
patch_url = https://wrapdb.mesonbuild.com/v2/zstd_1.5.6-2/get_patch | ||
patch_hash = 3e67f7d2edf3c56e6450d4c0f5f3d5fe94799e3608e3795502da03f7dd51b28c | ||
source_fallback_url = https://github.com/mesonbuild/wrapdb/releases/download/zstd_1.5.6-2/zstd-1.5.6.tar.gz | ||
wrapdb_version = 1.5.6-2 | ||
|
||
[provide] | ||
libzstd = libzstd_dep |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#if __has_include(<catch2/catch_all.hpp>) | ||
#include <catch2/catch_all.hpp> | ||
#include <catch2/catch_test_macros.hpp> | ||
#else | ||
#include <catch.hpp> | ||
#endif | ||
#include <cdfpp_config.h> | ||
#ifdef CDFPP_USE_ZSTD | ||
#include "cdfpp/cdf-io/zstd.hpp" | ||
#endif | ||
#include <cstdint> | ||
#include <numeric> | ||
|
||
#ifdef CDFPP_USE_ZSTD | ||
no_init_vector<char> build_ref() | ||
{ | ||
no_init_vector<char> ref(16000); | ||
std::iota(std::begin(ref), std::end(ref), 1); | ||
return ref; | ||
} | ||
TEST_CASE("IDEMPOTENCY check", "") | ||
{ | ||
const no_init_vector<char> ref = build_ref(); | ||
no_init_vector<char> w(std::size(ref)); | ||
auto w2 = cdf::io::zstd::deflate(ref); | ||
cdf::io::zstd::inflate(w2, w.data(), std::size(ref)); | ||
w2 = cdf::io::zstd::deflate(w); | ||
cdf::io::zstd::inflate(w2, w.data(), std::size(ref)); | ||
REQUIRE(ref == w); | ||
} | ||
#else | ||
TEST_CASE("Skip check", "") { } | ||
#endif |