2012-01-05 10:22:02 +00:00
|
|
|
#pragma once
|
2010-06-04 18:25:25 +00:00
|
|
|
|
2016-08-19 01:54:23 +00:00
|
|
|
#include <memory>
|
2011-06-24 20:18:09 +00:00
|
|
|
|
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>
|
2011-06-27 18:22:14 +00:00
|
|
|
#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
|
|
|
|
{
|
|
|
|
|
2011-06-27 18:22:14 +00:00
|
|
|
class CompressedWriteBuffer : public BufferWithOwnMemory<WriteBuffer>
|
2010-06-04 18:25:25 +00:00
|
|
|
{
|
|
|
|
private:
|
|
|
|
WriteBuffer & out;
|
2015-03-09 01:15:43 +00:00
|
|
|
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
|
2016-08-19 01:54:23 +00:00
|
|
|
std::unique_ptr<qlz_state_compress> qlz_state;
|
2016-02-21 21:57:46 +00:00
|
|
|
#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:
|
2012-01-31 19:52:51 +00:00
|
|
|
CompressedWriteBuffer(
|
|
|
|
WriteBuffer & out_,
|
2015-03-09 01:15:43 +00:00
|
|
|
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-06-24 21:08:26 +00:00
|
|
|
/// Объём сжатых данных
|
2011-05-05 19:10:17 +00:00
|
|
|
size_t getCompressedBytes()
|
|
|
|
{
|
|
|
|
nextIfAtEnd();
|
2011-06-30 15:21:35 +00:00
|
|
|
return out.count();
|
2011-05-05 19:10:17 +00:00
|
|
|
}
|
|
|
|
|
2011-05-11 17:27:08 +00:00
|
|
|
/// Сколько несжатых байт было записано в буфер
|
2011-05-05 19:10:17 +00:00
|
|
|
size_t getUncompressedBytes()
|
2011-05-11 17:27:08 +00:00
|
|
|
{
|
|
|
|
return count();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Сколько байт находится в буфере (ещё не сжато)
|
|
|
|
size_t getRemainingBytes()
|
2011-05-05 19:10:17 +00:00
|
|
|
{
|
|
|
|
nextIfAtEnd();
|
2011-06-30 15:21:35 +00:00
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
}
|