Network System 0.1.1
High-performance modular networking library for scalable client-server applications
Loading...
Searching...
No Matches
compression_pipeline.h
Go to the documentation of this file.
1// BSD 3-Clause License
2// Copyright (c) 2024, 🍀☀🌕🌥 🌊
3// See the LICENSE file in the project root for full license information.
4
5#pragma once
6
8
9#include <cstdint>
10#include <functional>
11#include <memory>
12#include <span>
13#include <vector>
14
16{
17
23 {
24 none,
25 lz4,
26 gzip,
27 deflate
28 };
29
64 {
65 public:
71 explicit compression_pipeline(
73 size_t compression_threshold = 256);
74
79
88 auto compress(std::span<const uint8_t> input)
89 -> Result<std::vector<uint8_t>>;
90
96 auto compress(const std::vector<uint8_t>& input)
97 -> Result<std::vector<uint8_t>>;
98
104 auto decompress(std::span<const uint8_t> input)
105 -> Result<std::vector<uint8_t>>;
106
112 auto decompress(const std::vector<uint8_t>& input)
113 -> Result<std::vector<uint8_t>>;
114
119 auto set_compression_threshold(size_t bytes) -> void;
120
125 auto get_compression_threshold() const -> size_t;
126
131 auto get_algorithm() const -> compression_algorithm;
132
133 private:
134 class impl;
135 std::unique_ptr<impl> pimpl_;
136 };
137
143 auto make_compress_function(std::shared_ptr<compression_pipeline> pipeline)
144 -> std::function<std::vector<uint8_t>(const std::vector<uint8_t>&)>;
145
151 auto make_decompress_function(std::shared_ptr<compression_pipeline> pipeline)
152 -> std::function<std::vector<uint8_t>(const std::vector<uint8_t>&)>;
153
154} // namespace kcenon::network::utils
Message compression and decompression pipeline.
auto compress(std::span< const uint8_t > input) -> Result< std::vector< uint8_t > >
Compresses input data.
auto set_compression_threshold(size_t bytes) -> void
Sets compression threshold.
auto get_compression_threshold() const -> size_t
Gets current compression threshold.
auto decompress(std::span< const uint8_t > input) -> Result< std::vector< uint8_t > >
Decompresses input data.
compression_pipeline(compression_algorithm algo=compression_algorithm::lz4, size_t compression_threshold=256)
Constructs a compression pipeline.
auto get_algorithm() const -> compression_algorithm
Gets current algorithm.
Utility components for network_system.
auto make_compress_function(std::shared_ptr< compression_pipeline > pipeline) -> std::function< std::vector< uint8_t >(const std::vector< uint8_t > &)>
Creates a compression function for pipeline integration.
compression_algorithm
Supported compression algorithms.
auto make_decompress_function(std::shared_ptr< compression_pipeline > pipeline) -> std::function< std::vector< uint8_t >(const std::vector< uint8_t > &)>
Creates a decompression function for pipeline integration.
Network-specific error and result type definitions.