blob: 2f3946af700caa58136ba66c61c125686a61a078 (
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
|
#include <span>
#include <vector>
#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
|