qb
2.0.0.0
C++17 Actor Framework
|
Data compression utilities for the QB IO library. More...
#include <functional>
#include <limits>
#include <stdexcept>
#include <string>
#include <zlib.h>
#include "qb/system/allocator/pipe.h"
Go to the source code of this file.
Classes | |
struct | qb::compression::operation_result |
Result of a compression/decompression operation. More... | |
class | qb::compression::compress_provider |
Abstract interface for compression algorithm providers. More... | |
class | qb::compression::decompress_provider |
Abstract interface for decompression algorithm providers. More... | |
class | qb::compression::compress_factory |
Factory interface for creating compression providers. More... | |
class | qb::compression::decompress_factory |
Factory interface for creating decompression providers. More... | |
struct | qb::compression::deflate::to_compress |
Structure for passing compression parameters for deflate. More... | |
struct | qb::compression::deflate::to_uncompress |
Structure for passing decompression parameters for deflate. More... | |
struct | qb::compression::gzip::to_compress |
Structure for passing gzip compression parameters. More... | |
struct | qb::compression::gzip::to_uncompress |
Structure for passing gzip decompression parameters. More... |
Namespaces | |
namespace | builtin |
Namespace containing built-in compression implementations. | |
namespace | algorithm |
Namespace containing algorithm constants and utilities. | |
namespace | deflate |
Namespace containing deflate compression utilities. | |
namespace | gzip |
Namespace containing gzip compression utilities. | |
namespace | qb::gzip |
Namespace alias for gzip compression utilities. | |
namespace | qb::deflate |
Namespace alias for deflate compression utilities. |
Enumerations | |
enum | qb::compression::operation_hint { qb::compression::is_last , qb::compression::has_more } |
Hints for compression/decompression operations. More... |
Functions | |
bool | qb::compression::builtin::supported () |
Check if compression support is available. | |
bool | qb::compression::builtin::algorithm::supported (const std::string &algorithm) |
Check if a specific compression algorithm is supported. | |
std::unique_ptr< compress_provider > | qb::compression::builtin::make_compressor (const std::string &algorithm) |
Create a compressor for the specified algorithm. | |
std::unique_ptr< decompress_provider > | qb::compression::builtin::make_decompressor (const std::string &algorithm) |
Create a decompressor for the specified algorithm. | |
const std::vector< std::shared_ptr< compress_factory > > | qb::compression::builtin::get_compress_factories () |
Get all available compression factories. | |
std::shared_ptr< compress_factory > | qb::compression::builtin::get_compress_factory (const std::string &algorithm) |
Get a specific compression factory by algorithm name. | |
const std::vector< std::shared_ptr< decompress_factory > > | qb::compression::builtin::get_decompress_factories () |
Get all available decompression factories. | |
std::shared_ptr< decompress_factory > | qb::compression::builtin::get_decompress_factory (const std::string &algorithm) |
Get a specific decompression factory by algorithm name. | |
std::unique_ptr< compress_provider > | qb::compression::builtin::make_gzip_compressor (int compressionLevel, int method, int strategy, int memLevel) |
Create a gzip compressor with custom parameters. | |
std::unique_ptr< compress_provider > | qb::compression::builtin::make_deflate_compressor (int compressionLevel, int method, int strategy, int memLevel) |
Create a deflate compressor with custom parameters. | |
std::shared_ptr< compress_factory > | qb::compression::make_compress_factory (const std::string &algorithm, std::function< std::unique_ptr< compress_provider >()> make_compressor) |
Create a custom compression factory. | |
std::shared_ptr< decompress_factory > | qb::compression::make_decompress_factory (const std::string &algorithm, uint16_t weight, std::function< std::unique_ptr< decompress_provider >()> make_decompressor) |
Create a custom decompression factory. | |
template<typename Output> | |
size_t | qb::compression::compress (Output &output, const char *data, std::size_t size, int level, int window_bits) |
Compress data using a generic output container. | |
template<> | |
size_t | qb::compression::compress (qb::allocator::pipe< char > &output, const char *data, std::size_t size, int level, int window_bits) |
Specialization of compress for pipe allocator. | |
template<typename Output> | |
std::size_t | qb::compression::uncompress (Output &output, const char *data, std::size_t size, std::size_t max, int window_bits) |
Uncompress data using a generic output container. | |
template<> | |
size_t | qb::compression::uncompress (qb::allocator::pipe< char > &output, const char *data, std::size_t size, std::size_t max, int window_bits) |
Specialization of uncompress for pipe allocator. | |
template<typename Output> | |
size_t | qb::compression::deflate::compress (Output &output, const char *data, std::size_t size, int level=Z_DEFAULT_COMPRESSION) |
Compress data using deflate algorithm with a generic output container. | |
template<> | |
size_t | qb::compression::deflate::compress (qb::allocator::pipe< char > &output, const char *data, std::size_t size, int level) |
Specialization of deflate compress for pipe allocator. | |
template<typename Output> | |
Output & | qb::compression::deflate::compress (Output &output, to_compress &info) |
Compress data using the parameters in a to_compress structure. | |
std::string | qb::compression::deflate::compress (const char *data, std::size_t size, int level=Z_DEFAULT_COMPRESSION) |
Compress data to a string. | |
template<typename Output> | |
std::size_t | qb::compression::deflate::uncompress (Output &output, const char *data, std::size_t size, std::size_t max=0) |
Uncompress data using deflate algorithm with a generic output container. | |
template<> | |
size_t | qb::compression::deflate::uncompress (qb::allocator::pipe< char > &output, const char *data, std::size_t size, std::size_t level) |
Specialization of deflate uncompress for pipe allocator. | |
template<typename Output> | |
Output & | qb::compression::deflate::uncompress (Output &output, to_uncompress &info) |
Uncompress data using the parameters in a to_uncompress structure. | |
std::string | qb::compression::deflate::uncompress (const char *data, std::size_t size) |
Uncompress data to a string. | |
bool | qb::compression::gzip::is_compressed (const char *data, std::size_t size) |
Check if data is compressed using gzip or zlib format. | |
template<typename Output> | |
size_t | qb::compression::gzip::compress (Output &output, const char *data, std::size_t size, int level=Z_DEFAULT_COMPRESSION) |
Compress data using gzip algorithm with a generic output container. | |
template<> | |
size_t | qb::compression::gzip::compress (qb::allocator::pipe< char > &output, const char *data, std::size_t size, int level) |
Specialization of gzip compress for pipe allocator. | |
template<typename Output> | |
Output & | qb::compression::gzip::compress (Output &output, to_compress &info) |
Compress data using the parameters in a to_compress structure. | |
std::string | qb::compression::gzip::compress (const char *data, std::size_t size, int level=Z_DEFAULT_COMPRESSION) |
Compress data to a string using gzip. | |
template<typename Output> | |
std::size_t | qb::compression::gzip::uncompress (Output &output, const char *data, std::size_t size, std::size_t max=0) |
Uncompress data using gzip algorithm with a generic output container. | |
template<> | |
size_t | qb::compression::gzip::uncompress (qb::allocator::pipe< char > &output, const char *data, std::size_t size, std::size_t level) |
Specialization of gzip uncompress for pipe allocator. | |
template<typename Output> | |
Output & | qb::compression::gzip::uncompress (Output &output, to_uncompress &info) |
Uncompress data using the parameters in a to_uncompress structure. | |
std::string | qb::compression::gzip::uncompress (const char *data, std::size_t size) |
Uncompress gzip data to a string. |
Data compression utilities for the QB IO library.
This file provides data compression and decompression functionality using the zlib library. It includes support for both deflate and gzip algorithms, with comprehensive interfaces for encoding and decoding data streams.
The implementation includes templated functions for flexible buffer management, provider classes for algorithm abstraction, and utility functions for common compression operations.
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
bool qb::compression::builtin::supported | ( | ) |
Check if compression support is available.
bool qb::compression::builtin::algorithm::supported | ( | const std::string & | algorithm | ) |
Check if a specific compression algorithm is supported.
algorithm | Name of the algorithm to check |
std::unique_ptr< compress_provider > qb::compression::builtin::make_compressor | ( | const std::string & | algorithm | ) |
Create a compressor for the specified algorithm.
algorithm | Name of the compression algorithm |
std::unique_ptr< decompress_provider > qb::compression::builtin::make_decompressor | ( | const std::string & | algorithm | ) |
Create a decompressor for the specified algorithm.
algorithm | Name of the decompression algorithm |
const std::vector< std::shared_ptr< compress_factory > > qb::compression::builtin::get_compress_factories | ( | ) |
Get all available compression factories.
std::shared_ptr< compress_factory > qb::compression::builtin::get_compress_factory | ( | const std::string & | algorithm | ) |
Get a specific compression factory by algorithm name.
algorithm | Name of the compression algorithm |
const std::vector< std::shared_ptr< decompress_factory > > qb::compression::builtin::get_decompress_factories | ( | ) |
Get all available decompression factories.
std::shared_ptr< decompress_factory > qb::compression::builtin::get_decompress_factory | ( | const std::string & | algorithm | ) |
Get a specific decompression factory by algorithm name.
algorithm | Name of the decompression algorithm |
std::unique_ptr< compress_provider > qb::compression::builtin::make_gzip_compressor | ( | int | compressionLevel, |
int | method, | ||
int | strategy, | ||
int | memLevel ) |
Create a gzip compressor with custom parameters.
compressionLevel | Compression level (1-9, where 9 is max compression) |
method | Compression method (usually Z_DEFLATED) |
strategy | Compression strategy (e.g., Z_DEFAULT_STRATEGY) |
memLevel | Memory usage level (1-9, where 9 uses most memory) |
std::unique_ptr< compress_provider > qb::compression::builtin::make_deflate_compressor | ( | int | compressionLevel, |
int | method, | ||
int | strategy, | ||
int | memLevel ) |
Create a deflate compressor with custom parameters.
compressionLevel | Compression level (1-9, where 9 is max compression) |
method | Compression method (usually Z_DEFLATED) |
strategy | Compression strategy (e.g., Z_DEFAULT_STRATEGY) |
memLevel | Memory usage level (1-9, where 9 uses most memory) |
std::shared_ptr< compress_factory > qb::compression::make_compress_factory | ( | const std::string & | algorithm, |
std::function< std::unique_ptr< compress_provider >()> | make_compressor ) |
Create a custom compression factory.
algorithm | Name of the compression algorithm |
make_compressor | Function that creates compressor instances |
std::shared_ptr< decompress_factory > qb::compression::make_decompress_factory | ( | const std::string & | algorithm, |
uint16_t | weight, | ||
std::function< std::unique_ptr< decompress_provider >()> | make_decompressor ) |
Create a custom decompression factory.
algorithm | Name of the decompression algorithm |
weight | Priority weight for the algorithm |
make_decompressor | Function that creates decompressor instances |
size_t qb::compression::compress | ( | Output & | output, |
const char * | data, | ||
std::size_t | size, | ||
int | level, | ||
int | window_bits ) |
Compress data using a generic output container.
This template function compresses the provided data using the zlib library and stores the result in an output container that supports resize() and size() operations.
Output | Type of the output container |
output | Container for the compressed data (will be resized as needed) |
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
window_bits | Window size bits with encoding format flag |
std::runtime_error | If initialization fails or input is too large |
size_t qb::compression::compress | ( | qb::allocator::pipe< char > & | output, |
const char * | data, | ||
std::size_t | size, | ||
int | level, | ||
int | window_bits ) |
Specialization of compress for pipe allocator.
output | Pipe allocator for the compressed data |
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
window_bits | Window size bits with encoding format flag |
std::size_t qb::compression::uncompress | ( | Output & | output, |
const char * | data, | ||
std::size_t | size, | ||
std::size_t | max, | ||
int | window_bits ) |
Uncompress data using a generic output container.
This template function uncompresses the provided data using the zlib library and stores the result in an output container that supports resize() and size() operations.
Output | Type of the output container |
output | Container for the uncompressed data (will be resized as needed) |
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |
max | Maximum allowed output size (0 for unlimited) |
window_bits | Window size bits with encoding format flag |
std::runtime_error | If initialization fails, input is too large, or max size exceeded |
size_t qb::compression::uncompress | ( | qb::allocator::pipe< char > & | output, |
const char * | data, | ||
std::size_t | size, | ||
std::size_t | max, | ||
int | window_bits ) |
Specialization of uncompress for pipe allocator.
output | Pipe allocator for the uncompressed data |
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |
max | Maximum allowed output size (0 for unlimited) |
window_bits | Window size bits with encoding format flag |
size_t qb::compression::deflate::compress | ( | Output & | output, |
const char * | data, | ||
std::size_t | size, | ||
int | level = Z_DEFAULT_COMPRESSION ) |
Compress data using deflate algorithm with a generic output container.
Output | Type of the output container |
output | Container for the compressed data (will be resized as needed) |
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
size_t qb::compression::deflate::compress | ( | qb::allocator::pipe< char > & | output, |
const char * | data, | ||
std::size_t | size, | ||
int | level ) |
Specialization of deflate compress for pipe allocator.
output | Pipe allocator for the compressed data |
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
Output & qb::compression::deflate::compress | ( | Output & | output, |
to_compress & | info ) |
Compress data using the parameters in a to_compress structure.
Output | Type of the output container |
output | Container for the compressed data |
info | Structure containing compression parameters and results |
std::string qb::compression::deflate::compress | ( | const char * | data, |
std::size_t | size, | ||
int | level = Z_DEFAULT_COMPRESSION ) |
Compress data to a string.
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
std::size_t qb::compression::deflate::uncompress | ( | Output & | output, |
const char * | data, | ||
std::size_t | size, | ||
std::size_t | max = 0 ) |
Uncompress data using deflate algorithm with a generic output container.
Output | Type of the output container |
output | Container for the uncompressed data |
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |
max | Maximum allowed output size (0 for unlimited) |
size_t qb::compression::deflate::uncompress | ( | qb::allocator::pipe< char > & | output, |
const char * | data, | ||
std::size_t | size, | ||
std::size_t | level ) |
Specialization of deflate uncompress for pipe allocator.
output | Pipe allocator for the uncompressed data |
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |
level | Maximum allowed output size (0 for unlimited) |
Output & qb::compression::deflate::uncompress | ( | Output & | output, |
to_uncompress & | info ) |
Uncompress data using the parameters in a to_uncompress structure.
Output | Type of the output container |
output | Container for the uncompressed data |
info | Structure containing decompression parameters and results |
std::string qb::compression::deflate::uncompress | ( | const char * | data, |
std::size_t | size ) |
Uncompress data to a string.
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |
size_t qb::compression::gzip::compress | ( | Output & | output, |
const char * | data, | ||
std::size_t | size, | ||
int | level = Z_DEFAULT_COMPRESSION ) |
Compress data using gzip algorithm with a generic output container.
Output | Type of the output container |
output | Container for the compressed data (will be resized as needed) |
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
size_t qb::compression::gzip::compress | ( | qb::allocator::pipe< char > & | output, |
const char * | data, | ||
std::size_t | size, | ||
int | level ) |
Specialization of gzip compress for pipe allocator.
output | Pipe allocator for the compressed data |
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
Output & qb::compression::gzip::compress | ( | Output & | output, |
to_compress & | info ) |
Compress data using the parameters in a to_compress structure.
Output | Type of the output container |
output | Container for the compressed data |
info | Structure containing compression parameters and results |
std::string qb::compression::gzip::compress | ( | const char * | data, |
std::size_t | size, | ||
int | level = Z_DEFAULT_COMPRESSION ) |
Compress data to a string using gzip.
data | Pointer to the data to compress |
size | Size of the data in bytes |
level | Compression level (1-9, where 9 is max compression) |
std::size_t qb::compression::gzip::uncompress | ( | Output & | output, |
const char * | data, | ||
std::size_t | size, | ||
std::size_t | max = 0 ) |
Uncompress data using gzip algorithm with a generic output container.
Output | Type of the output container |
output | Container for the uncompressed data |
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |
max | Maximum allowed output size (0 for unlimited) |
size_t qb::compression::gzip::uncompress | ( | qb::allocator::pipe< char > & | output, |
const char * | data, | ||
std::size_t | size, | ||
std::size_t | level ) |
Specialization of gzip uncompress for pipe allocator.
output | Pipe allocator for the uncompressed data |
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |
level | Maximum allowed output size (0 for unlimited) |
Output & qb::compression::gzip::uncompress | ( | Output & | output, |
to_uncompress & | info ) |
Uncompress data using the parameters in a to_uncompress structure.
Output | Type of the output container |
output | Container for the uncompressed data |
info | Structure containing decompression parameters and results |
std::string qb::compression::gzip::uncompress | ( | const char * | data, |
std::size_t | size ) |
Uncompress gzip data to a string.
data | Pointer to the compressed data |
size | Size of the compressed data in bytes |