summaryrefslogtreecommitdiff
path: root/http/zstd_compressor.hpp
blob: af307884d01a7b191b55a737c4a468b23adf6ece (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: Copyright OpenBMC Authors

#pragma once

#ifdef HAVE_ZSTD
#include <zstd.h>
#endif

#include <boost/beast/core/flat_buffer.hpp>

#include <optional>
#include <span>

namespace bmcweb
{
class ZstdCompressor
{
    boost::beast::flat_buffer compressionBuf;

#ifdef HAVE_ZSTD
    ZSTD_CCtx* cctx = nullptr;
#endif

  public:
    ZstdCompressor(const ZstdCompressor&) = delete;
    ZstdCompressor(ZstdCompressor&&) = delete;
    ZstdCompressor& operator=(const ZstdCompressor&) = delete;
    ZstdCompressor& operator=(ZstdCompressor&&) = delete;

    ZstdCompressor() = default;

    // must be called before compress.
    bool init(size_t sourceSize);
    std::optional<std::span<const uint8_t>> compress(
        std::span<const uint8_t> buffIn, bool more);
    ~ZstdCompressor();
};
} // namespace bmcweb