Joedb 9.5.0
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
Brotli_Codec.cpp
Go to the documentation of this file.
3
4#include <brotli/encode.h>
5
6namespace joedb
7{
8 ////////////////////////////////////////////////////////////////////////////
9 std::string Brotli_Codec::encode(const char *decoded, size_t decoded_size)
10 ////////////////////////////////////////////////////////////////////////////
11 {
12 std::string encoded(BrotliEncoderMaxCompressedSize(decoded_size), 0);
13
14 size_t encoded_size = encoded.size();
15
16 const auto result = BrotliEncoderCompress
17 (
18 BROTLI_DEFAULT_QUALITY,
19 BROTLI_DEFAULT_WINDOW,
20 BROTLI_DEFAULT_MODE,
21 decoded_size,
22 (const uint8_t *)decoded,
23 &encoded_size,
24 (uint8_t *)encoded.data()
25 );
26
27 if (result != BROTLI_TRUE)
28 throw Exception("Brotli compression failed");
29
30 encoded.resize(encoded_size);
31
32 return encoded;
33 }
34}
std::string encode(const char *decoded, size_t decoded_size) override
Definition Blob.h:7