C++ Essence Library 0.1.0
A Utility Library for Modern C++ Programming
Loading...
Searching...
No Matches
compresser.hpp
1/*
2 * Copyright (c) 2024 The RefValue Project
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
5 * of this software and associated documentation files (the "Software"), to deal
6 * in the Software without restriction, including without limitation the rights
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 * copies of the Software, and to permit persons to whom the Software is
9 * furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20 * THE SOFTWARE.
21 */
22
23#pragma once
24
25#include "../abi/string.hpp"
26#include "../abi/vector.hpp"
27#include "../compat.hpp"
28#include "../range.hpp"
29#include "common_types.hpp"
30
31#include <cstddef>
32#include <cstdint>
33#include <memory>
34#include <span>
35
36namespace essence::io {
40 class compresser {
41 public:
46 ES_API(CPPESSENCE) explicit compresser(compression_mode mode);
47
48 ES_API(CPPESSENCE) compresser(compresser&&) noexcept;
49 ES_API(CPPESSENCE) ~compresser();
50 ES_API(CPPESSENCE) compresser& operator=(compresser&&) noexcept;
51
58 [[nodiscard]] ES_API(CPPESSENCE) abi::vector<std::byte> as_bytes(
59 std::span<const std::byte> buffer, std::int32_t level) const;
60
67 [[nodiscard]] ES_API(CPPESSENCE) abi::string
68 as_string(std::span<const std::byte> buffer, std::int32_t level) const;
69
75 [[nodiscard]] ES_API(CPPESSENCE) abi::vector<std::byte> inverse_as_bytes(
76 std::span<const std::byte> buffer) const;
77
83 [[nodiscard]] ES_API(CPPESSENCE) abi::string inverse_as_string(std::span<const std::byte> buffer) const;
84
91 template <byte_like_contiguous_range Range>
92 abi::vector<std::byte> as_bytes(Range&& range, std::int32_t level) const {
93 return as_bytes(as_const_byte_span(range), level);
94 }
95
102 template <byte_like_contiguous_range Range>
103 abi::string as_string(Range&& range, std::int32_t level) const {
104 return as_string(as_const_byte_span(range), level);
105 }
106
112 template <byte_like_contiguous_range Range>
113 abi::vector<std::byte> inverse_as_bytes(Range&& range) const {
114 return inverse_as_bytes(as_const_byte_span(range));
115 }
116
122 template <byte_like_contiguous_range Range>
123 abi::string inverse_as_string(Range&& range) const {
124 return inverse_as_string(as_const_byte_span(range));
125 }
126
127 private:
128 class impl;
129
130 std::unique_ptr<impl> impl_;
131 };
132} // namespace essence::io
A general compresser.
Definition compresser.hpp:40
ES_API(CPPESSENCE) abi ES_API(CPPESSENCE) abi ES_API(CPPESSENCE) abi ES_API(CPPESSENCE) abi abi::vector< std::byte > as_bytes(Range &&range, std::int32_t level) const
Compresses a byte buffer.
Definition compresser.hpp:92
abi::string as_string(Range &&range, std::int32_t level) const
Compresses a byte buffer as a string.
Definition compresser.hpp:103
ES_API(CPPESSENCE) explicit compresser(compression_mode mode)
Creates an instance.
abi::string inverse_as_string(Range &&range) const
Decompresses a byte buffer as a string.
Definition compresser.hpp:123
abi::vector< std::byte > inverse_as_bytes(Range &&range) const
Decompress a byte buffer.
Definition compresser.hpp:113