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"
37class LZ4DeflateService
55 int dest_capacity = LZ4_compressBound(input_size);
59 compressed_values.
resize(dest_capacity);
62 char* dest =
reinterpret_cast<char*
>(compressed_values.
data());
64 const char* source =
reinterpret_cast<const char*
>(values.
data());
65 unsigned int source_len = (
unsigned int)input_size;
68 info() <<
"CHECK COMPRESS dest=" << (
void*)dest
69 <<
" dest_len=" << dest_len
70 <<
" source=" << (
void*)source
71 <<
" source_len=" << source_len;
74 int r = LZ4_compress_default(source, dest, source_len, dest_capacity);
77 throw IOException(A_FUNCINFO, String::format(
"io error during compression r={0}", r));
79 Real ratio = (dest_len * 100.0) / source_len;
80 info() <<
"LZ4 compress r=" << r <<
" source_len=" << source_len
81 <<
" dest_len=" << dest_len <<
" ratio=" << ratio;
82 compressed_values.
resize(dest_len);
87 char* dest =
reinterpret_cast<char*
>(values.
data());
88 int dest_len = values.
size();
90 const char* source =
reinterpret_cast<const char*
>(compressed_values.
data());
91 int source_len = compressed_values.
size();
93 int r = LZ4_decompress_safe(source, dest, source_len, dest_len);
94 info() <<
"LZ4 decompress r=" << r <<
" source_len=" << source_len <<
" dest_len=" << dest_len;
96 throw IOException(A_FUNCINFO, String::format(
"io error during decompression r={0}", r));
106class LZ4DataCompressor
128 int input_size = _toInt(values.
size());
130 if (input_size > LZ4_MAX_INPUT_SIZE)
133 int dest_capacity = LZ4_compressBound(input_size);
134 compressed_values.
resize(dest_capacity);
136 char* dest =
reinterpret_cast<char*
>(compressed_values.
data());
137 const char* source =
reinterpret_cast<const char*
>(values.
data());
139 int r = LZ4_compress_default(source, dest, input_size, dest_capacity);
143 if (input_size > 0) {
144 Real ratio = (dest_len * 100.0) / input_size;
145 info(5) <<
"LZ4 compress r=" << r <<
" source_len=" << input_size
146 <<
" dest_len=" << dest_len <<
" ratio=" << ratio;
148 compressed_values.
resize(dest_len);
153 char* dest =
reinterpret_cast<char*
>(values.
data());
154 int dest_len = _toInt(values.
size());
156 const char* source =
reinterpret_cast<const char*
>(compressed_values.
data());
157 int source_len = _toInt(compressed_values.
size());
159 int r = LZ4_decompress_safe(source, dest, source_len, dest_len);
160 info(5) <<
"LZ4 decompress r=" << r <<
" source_len=" << source_len <<
" dest_len=" << dest_len;
171 int _toInt(
Int64 vsize)
174 Int64 max_int_size = std::numeric_limits<int>::max();
175 if (vsize > max_int_size)
177 return static_cast<int>(vsize);
#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.
constexpr const_pointer data() const noexcept
Pointer to the start of the view.
constexpr Integer size() const noexcept
Returns the size of the array.
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.
constexpr const_pointer data() const noexcept
Pointer to the allocated memory.
constexpr Integer size() const noexcept
Number of elements in the array.
Interface of a service for compressing/decompressing data.
Interface of a service allowing compression/decompression of data.
Exception when an input/output error is detected.
virtual String localName() const =0
Local part of the service name.
Compression service using the 'LZ4' library.
void compress(Span< const std::byte > values, Array< std::byte > &compressed_values) override
Compresses the data values and stores it in compressed_values.
void build() override
Build-level construction of the service.
void decompress(Span< const std::byte > compressed_values, Span< std::byte > values) override
Decompresses the data compressed_values and stores it in values.
Int64 minCompressSize() const override
Minimum array size below which compression is not useful.
String name() const override
Algorithm name.
Compression service using the 'LZ4' library.
void decompress(ByteConstArrayView compressed_values, ByteArrayView values) override
Decompresses the data compressed_values and stores it in values.
void build() override
Build-level construction of the service.
void compress(ByteConstArrayView values, ByteArray &compressed_values) override
Compresses the data values and stores it in compressed_values.
Structure containing the information to create a service.
IServiceInfo * serviceInfo() const
Access to the associated IServiceInfo.
Service creation properties.
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.
#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 --
ArrayView< Byte > ByteArrayView
C equivalent of a 1D array of characters.
std::int64_t Int64
Signed integer type of 64 bits.
Int32 Integer
Type representing an integer.
Array< Byte > ByteArray
Dynamic one-dimensional array of characters.
@ 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.
ConstArrayView< Byte > ByteConstArrayView
C equivalent of a 1D array of characters.