ClickHouse/dbms/include/DB/IO/CompressedWriteBuffer.h

68 lines
1.3 KiB
C++
Raw Normal View History

2012-01-05 10:22:02 +00:00
#pragma once
2010-06-04 18:25:25 +00:00
#include <memory>
2016-02-03 21:16:19 +00:00
#ifdef USE_QUICKLZ
2016-10-25 06:49:24 +00:00
struct qlz_state_compress;
2016-02-03 21:16:19 +00:00
#endif
2013-12-09 00:23:17 +00:00
#include <DB/Common/PODArray.h>
2010-06-04 18:25:25 +00:00
#include <DB/IO/WriteBuffer.h>
#include <DB/IO/BufferWithOwnMemory.h>
2011-06-17 21:19:39 +00:00
#include <DB/IO/CompressedStream.h>
2010-06-04 18:25:25 +00:00
namespace DB
{
class CompressedWriteBuffer : public BufferWithOwnMemory<WriteBuffer>
2010-06-04 18:25:25 +00:00
{
private:
WriteBuffer & out;
CompressionMethod method;
2010-06-04 18:25:25 +00:00
2013-12-09 00:23:17 +00:00
PODArray<char> compressed_buffer;
2016-03-07 04:31:10 +00:00
2016-02-03 21:16:19 +00:00
#ifdef USE_QUICKLZ
std::unique_ptr<qlz_state_compress> qlz_state;
#else
2016-10-25 06:49:24 +00:00
/// ABI compatibility for USE_QUICKLZ
2016-02-24 07:53:04 +00:00
void * fixed_size_padding = nullptr;
2016-03-07 04:31:10 +00:00
/// Отменяет warning unused-private-field.
void * fixed_size_padding_used() const { return fixed_size_padding; }
2016-02-03 21:16:19 +00:00
#endif
2011-06-17 21:19:39 +00:00
2016-10-25 06:49:24 +00:00
void nextImpl() override;
2011-05-05 19:10:17 +00:00
2011-06-26 21:30:59 +00:00
public:
CompressedWriteBuffer(
WriteBuffer & out_,
CompressionMethod method_ = CompressionMethod::LZ4,
2016-10-25 06:49:24 +00:00
size_t buf_size = DBMS_DEFAULT_BUFFER_SIZE);
2011-06-26 21:30:59 +00:00
/// Объём сжатых данных
2011-05-05 19:10:17 +00:00
size_t getCompressedBytes()
{
nextIfAtEnd();
return out.count();
2011-05-05 19:10:17 +00:00
}
/// Сколько несжатых байт было записано в буфер
2011-05-05 19:10:17 +00:00
size_t getUncompressedBytes()
{
return count();
}
/// Сколько байт находится в буфере (ещё не сжато)
size_t getRemainingBytes()
2011-05-05 19:10:17 +00:00
{
nextIfAtEnd();
return offset();
2010-06-04 18:25:25 +00:00
}
2016-10-25 06:49:24 +00:00
~CompressedWriteBuffer() override;
2010-06-04 18:25:25 +00:00
};
}