/src/bmcweb/http/zstd_compressor.hpp
Line | Count | Source |
1 | | // SPDX-License-Identifier: Apache-2.0 |
2 | | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
3 | | |
4 | | #pragma once |
5 | | |
6 | | #ifdef HAVE_ZSTD |
7 | | #include <zstd.h> |
8 | | #endif |
9 | | |
10 | | #include <boost/beast/core/flat_buffer.hpp> |
11 | | |
12 | | #include <optional> |
13 | | #include <span> |
14 | | |
15 | | namespace bmcweb |
16 | | { |
17 | | class ZstdCompressor |
18 | | { |
19 | | boost::beast::flat_buffer compressionBuf; |
20 | | |
21 | | #ifdef HAVE_ZSTD |
22 | | ZSTD_CCtx* cctx = nullptr; |
23 | | #endif |
24 | | |
25 | | public: |
26 | | ZstdCompressor(const ZstdCompressor&) = delete; |
27 | | ZstdCompressor(ZstdCompressor&&) = delete; |
28 | | ZstdCompressor& operator=(const ZstdCompressor&) = delete; |
29 | | ZstdCompressor& operator=(ZstdCompressor&&) = delete; |
30 | | |
31 | 0 | ZstdCompressor() = default; |
32 | | |
33 | | // must be called before compress. |
34 | | bool init(size_t sourceSize); |
35 | | std::optional<std::span<const uint8_t>> compress( |
36 | | std::span<const uint8_t> buffIn, bool more); |
37 | | ~ZstdCompressor(); |
38 | | }; |
39 | | } // namespace bmcweb |