aboutsummaryrefslogtreecommitdiff
path: root/lib/compressionctx.h
blob: a07686f5bb66939b1af2d2a207e0f5a89df53e2c (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
40
41
42
#include <span>
#include <vector>
#include <cstdint>
#include <memory>

#pragma once

namespace embed
{

enum Compression {
    None,
    Zstd
};

class CompressionCtx
{
public:
    virtual ~CompressionCtx() = default;
    [[nodiscard]] virtual std::vector<uint8_t> decompress(const std::span<const uint8_t> &entry) const = 0;
};

class ZstdCompressionCtx final : public CompressionCtx
{
public:
    ZstdCompressionCtx(const std::span<const uint8_t> &dictionary);
    ~ZstdCompressionCtx();
    [[nodiscard]] std::vector<uint8_t> decompress(const std::span<const uint8_t> &entry) const override;
};

std::unique_ptr<CompressionCtx> make_compression_ctx(const Compression algo, const std::span<const uint8_t> &dict)
{
    switch(algo)
    {
        case None:
            return nullptr;
        case Zstd:
            return std::make_unique<ZstdCompressionCtx>(dict);
    }
}

} // namespace embed