14#include "arcane/utils/IOException.h"
15#include "arcane/utils/Array.h"
16#include "arcane/utils/TraceInfo.h"
17#include "arcane/utils/IDataCompressor.h"
19#include "arcane/core/FactoryService.h"
20#include "arcane/core/AbstractService.h"
21#include "arcane/core/IDeflateService.h"
25#include <zstd_errors.h>
39class ZstdDataCompressor
58 size_t input_size = values.
size();
59 size_t dest_capacity = ZSTD_compressBound(input_size);
60 compressed_values.
resize(dest_capacity);
62 void* dest = compressed_values.
data();
63 const void* source = values.
data();
64 int compression_level = 1;
65 size_t r = ZSTD_compress(dest, dest_capacity, source, input_size, compression_level);
66 if (ZSTD_isError(r)) {
67 ZSTD_ErrorCode err_code = ZSTD_getErrorCode(r);
68 ARCANE_THROW(
IOException,
"IO error during compression r={0} msg={1}", err_code, ZSTD_getErrorString(err_code));
72 Real ratio = (
static_cast<double>(dest_len) * 100.0) /
static_cast<double>(input_size);
73 info(5) <<
"ZSTD compress r=" << r <<
" source_len=" << input_size
74 <<
" dest_len=" << dest_len <<
" ratio=" << ratio;
76 compressed_values.
resize(dest_len);
81 void* dest = values.
data();
82 size_t dest_len = values.
size();
84 const void* source = compressed_values.
data();
85 size_t source_len = compressed_values.
size();
87 size_t r = ZSTD_decompress(dest, dest_len, source, source_len);
88 info(5) <<
"ZSTD decompress r=" << r <<
" source_len=" << source_len <<
" dest_len=" << dest_len;
89 if (ZSTD_isError(r)) {
90 ZSTD_ErrorCode err_code = ZSTD_getErrorCode(r);
91 ARCANE_THROW(
IOException,
"IO error during decompression r={0} msg={1}", err_code, ZSTD_getErrorString(err_code));
#define ARCANE_THROW(exception_class,...)
Macro for throwing an exception with formatting.
#define ARCANE_SERVICE_INTERFACE(ainterface)
Macro to declare an interface when registering a service.
AbstractService(const ServiceBuildInfo &)
Constructor from a ServiceBuildInfo.
Base class for 1D data vectors.
void resize(Int64 s)
Changes the number of elements in the array to s.
const T * data() const
Access to the root of the array without any protection.
Interface of a service for compressing/decompressing data.
Exception when an input/output error is detected.
virtual String localName() const =0
Local part of the service name.
Structure containing the information to create a service.
IServiceInfo * serviceInfo() const
Access to the associated IServiceInfo.
constexpr __host__ __device__ pointer data() const noexcept
Pointer to the start of the view.
constexpr __host__ __device__ SizeType size() const noexcept
Returns the size of the array.
View of an array of elements of type T.
Unicode character string.
TraceMessage info() const
Flow for an information message.
Int64 minCompressSize() const override
Minimum array size below which compression is not useful.
void build() override
Build-level construction of the service.
String name() const override
Algorithm name.
void decompress(Span< const std::byte > compressed_values, Span< std::byte > values) override
Decompresses the data compressed_values and stores it in values.
void compress(Span< const std::byte > values, Array< std::byte > &compressed_values) override
Compresses the data values and stores it in compressed_values.
#define ARCANE_REGISTER_SERVICE(aclass, a_service_property,...)
Macro for registering a service.
-- tab-width: 2; indent-tabs-mode: nil; coding: utf-8-with-signature --
std::int64_t Int64
Signed integer type of 64 bits.
@ ST_Application
The service is used at the application level.
@ ST_CaseOption
The service is used at the dataset level.
double Real
Type representing a real number.