2014-01-15 14:53:20 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-02-03 21:16:19 +00:00
|
|
|
#ifdef USE_QUICKLZ
|
2016-10-25 06:49:24 +00:00
|
|
|
struct qlz_state_decompress;
|
2016-02-03 21:16:19 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-15 14:53:20 +00:00
|
|
|
#include <DB/Common/PODArray.h>
|
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
|
2014-01-15 14:53:20 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
class ReadBuffer;
|
2016-01-11 21:46:36 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/** Basic functionality for implementation of
|
|
|
|
* CompressedReadBuffer, CompressedReadBufferFromFile and CachedCompressedReadBuffer.
|
|
|
|
*/
|
2014-01-15 14:53:20 +00:00
|
|
|
class CompressedReadBufferBase
|
|
|
|
{
|
|
|
|
protected:
|
|
|
|
ReadBuffer * compressed_in;
|
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/// If 'compressed_in' buffer has whole compressed block - than use it. Otherwise copy parts of data to 'own_compressed_buffer'.
|
2016-10-25 06:49:24 +00:00
|
|
|
PODArray<char> own_compressed_buffer;
|
2016-10-24 02:02:37 +00:00
|
|
|
/// Points to memory, holding compressed block.
|
2014-04-08 07:31:51 +00:00
|
|
|
char * compressed_buffer = nullptr;
|
2014-01-15 14:53:20 +00:00
|
|
|
|
2016-02-03 21:16:19 +00:00
|
|
|
#ifdef USE_QUICKLZ
|
2016-06-09 04:37:21 +00:00
|
|
|
std::unique_ptr<qlz_state_decompress> qlz_state;
|
2016-02-21 13:57:03 +00:00
|
|
|
#else
|
2016-10-24 02:02:37 +00:00
|
|
|
void * fixed_size_padding = nullptr; /// ABI compatibility for USE_QUICKLZ
|
2016-02-03 21:16:19 +00:00
|
|
|
#endif
|
2014-01-15 14:53:20 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/// Don't checksum on decompressing.
|
2016-04-09 23:24:38 +00:00
|
|
|
bool disable_checksum = false;
|
|
|
|
|
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/// Read compressed data into compressed_buffer. Get size of decompressed data from block header. Checksum if need.
|
|
|
|
/// Returns number of compressed bytes read.
|
2016-10-25 06:49:24 +00:00
|
|
|
size_t readCompressedData(size_t & size_decompressed, size_t & size_compressed_without_checksum);
|
2014-10-05 21:59:23 +00:00
|
|
|
|
2016-10-25 06:49:24 +00:00
|
|
|
void decompress(char * to, size_t size_decompressed, size_t size_compressed_without_checksum);
|
2014-01-15 14:53:20 +00:00
|
|
|
|
|
|
|
public:
|
2016-10-24 02:02:37 +00:00
|
|
|
/// 'compressed_in' could be initialized lazily, but before first call of 'readCompressedData'.
|
2016-10-25 06:49:24 +00:00
|
|
|
CompressedReadBufferBase(ReadBuffer * in = nullptr);
|
|
|
|
~CompressedReadBufferBase();
|
2014-01-15 14:53:20 +00:00
|
|
|
|
2016-10-24 02:02:37 +00:00
|
|
|
/** Disable checksums.
|
|
|
|
* For example, may be used when
|
|
|
|
* compressed data is generated by client, that cannot calculate checksums, and fill checksums with zeros instead.
|
2016-04-09 23:24:38 +00:00
|
|
|
*/
|
|
|
|
void disableChecksumming()
|
|
|
|
{
|
|
|
|
disable_checksum = true;
|
|
|
|
}
|
2014-01-15 14:53:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|