#pragma once #include #include #include #include "config.h" #if USE_BROTLI # include namespace DB { class BrotliWriteBuffer : public WriteBufferWithOwnMemoryDecorator { public: template BrotliWriteBuffer( WriteBufferT && out_, int compression_level, size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE, char * existing_memory = nullptr, size_t alignment = 0) : WriteBufferWithOwnMemoryDecorator(std::move(out_), buf_size, existing_memory, alignment) , brotli(std::make_unique()) , in_available(0) , in_data(nullptr) , out_capacity(0) , out_data(nullptr) { BrotliEncoderSetParameter(brotli->state, BROTLI_PARAM_QUALITY, static_cast(compression_level)); // Set LZ77 window size. According to brotli sources default value is 24 (c/tools/brotli.c:81) BrotliEncoderSetParameter(brotli->state, BROTLI_PARAM_LGWIN, 24); } ~BrotliWriteBuffer() override; private: void nextImpl() override; void finalizeBefore() override; class BrotliStateWrapper { public: BrotliStateWrapper(); ~BrotliStateWrapper(); BrotliEncoderState * state; }; std::unique_ptr brotli; size_t in_available; const uint8_t * in_data; size_t out_capacity; uint8_t * out_data; }; } #endif