mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-09-20 00:30:49 +00:00
hide brotli from inerface
This commit is contained in:
parent
b6c8a892a8
commit
b01d735421
@ -89,9 +89,6 @@ set(dbms_sources)
|
||||
|
||||
include(../cmake/dbms_glob_sources.cmake)
|
||||
|
||||
# temp ugly hack
|
||||
include_directories(${BROTLI_INCLUDE_DIR})
|
||||
|
||||
add_headers_and_sources(clickhouse_common_io src/Common)
|
||||
add_headers_and_sources(clickhouse_common_io src/Common/HashTable)
|
||||
add_headers_and_sources(clickhouse_common_io src/IO)
|
||||
|
@ -1,12 +1,32 @@
|
||||
#include "BrotliReadBuffer.h"
|
||||
#include <brotli/decode.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
|
||||
class BrotliReadBuffer::BrotliStateWrapper
|
||||
{
|
||||
public:
|
||||
BrotliStateWrapper()
|
||||
: state(BrotliDecoderCreateInstance(nullptr, nullptr, nullptr))
|
||||
, result(BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT)
|
||||
{
|
||||
}
|
||||
|
||||
~BrotliStateWrapper()
|
||||
{
|
||||
BrotliDecoderDestroyInstance(state);
|
||||
}
|
||||
|
||||
public:
|
||||
BrotliDecoderState * state;
|
||||
BrotliDecoderResult result;
|
||||
};
|
||||
|
||||
BrotliReadBuffer::BrotliReadBuffer(ReadBuffer &in_, size_t buf_size, char *existing_memory, size_t alignment)
|
||||
: BufferWithOwnMemory<ReadBuffer>(buf_size, existing_memory, alignment)
|
||||
, in(in_)
|
||||
, bstate(BrotliDecoderCreateInstance(nullptr, nullptr, nullptr))
|
||||
, bresult(BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT)
|
||||
, brotli(new BrotliStateWrapper())
|
||||
, in_available(0)
|
||||
, in_data(nullptr)
|
||||
, out_capacity(0)
|
||||
@ -17,7 +37,6 @@ BrotliReadBuffer::BrotliReadBuffer(ReadBuffer &in_, size_t buf_size, char *exist
|
||||
|
||||
BrotliReadBuffer::~BrotliReadBuffer()
|
||||
{
|
||||
BrotliDecoderDestroyInstance(bstate);
|
||||
}
|
||||
|
||||
bool BrotliReadBuffer::nextImpl()
|
||||
@ -32,7 +51,7 @@ bool BrotliReadBuffer::nextImpl()
|
||||
in_data = reinterpret_cast<uint8_t *>(in.position());
|
||||
}
|
||||
|
||||
if (bresult == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT && (!in_available || in.eof()))
|
||||
if (brotli->result == BROTLI_DECODER_RESULT_NEEDS_MORE_INPUT && (!in_available || in.eof()))
|
||||
{
|
||||
throw Exception(std::string("brotli decode error"), ErrorCodes::CANNOT_READ_ALL_DATA);
|
||||
}
|
||||
@ -40,12 +59,12 @@ bool BrotliReadBuffer::nextImpl()
|
||||
out_capacity = internal_buffer.size();
|
||||
out_data = reinterpret_cast<uint8_t *>(internal_buffer.begin());
|
||||
|
||||
bresult = BrotliDecoderDecompressStream(bstate, &in_available, &in_data, &out_capacity, &out_data, nullptr);
|
||||
brotli->result = BrotliDecoderDecompressStream(brotli->state, &in_available, &in_data, &out_capacity, &out_data, nullptr);
|
||||
|
||||
in.position() = in.buffer().end() - in_available;
|
||||
working_buffer.resize(internal_buffer.size() - out_capacity);
|
||||
|
||||
if (bresult == BROTLI_DECODER_RESULT_SUCCESS)
|
||||
if (brotli->result == BROTLI_DECODER_RESULT_SUCCESS)
|
||||
{
|
||||
if (in.eof())
|
||||
{
|
||||
@ -58,7 +77,7 @@ bool BrotliReadBuffer::nextImpl()
|
||||
}
|
||||
}
|
||||
|
||||
if (bresult == BROTLI_DECODER_RESULT_ERROR)
|
||||
if (brotli->result == BROTLI_DECODER_RESULT_ERROR)
|
||||
{
|
||||
throw Exception(std::string("brotli decode error"), ErrorCodes::CANNOT_READ_ALL_DATA);
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
#include <IO/ReadBuffer.h>
|
||||
#include <IO/BufferWithOwnMemory.h>
|
||||
|
||||
#include <brotli/decode.h>
|
||||
|
||||
namespace DB
|
||||
{
|
||||
@ -24,8 +23,8 @@ private:
|
||||
|
||||
ReadBuffer ∈
|
||||
|
||||
BrotliDecoderState * bstate;
|
||||
BrotliDecoderResult bresult;
|
||||
class BrotliStateWrapper;
|
||||
std::unique_ptr<BrotliStateWrapper> brotli;
|
||||
|
||||
size_t in_available;
|
||||
const uint8_t * in_data;
|
||||
|
Loading…
Reference in New Issue
Block a user