1#pragma once
2
3#include <Common/PODArray.h>
4#include <Compression/LZ4_decompress_faster.h>
5#include <Compression/ICompressionCodec.h>
6
7
8namespace DB
9{
10
11class ReadBuffer;
12
13/** Basic functionality for implementation of
14 * CompressedReadBuffer, CompressedReadBufferFromFile and CachedCompressedReadBuffer.
15 */
16class CompressedReadBufferBase
17{
18protected:
19 ReadBuffer * compressed_in;
20
21 /// If 'compressed_in' buffer has whole compressed block - then use it. Otherwise copy parts of data to 'own_compressed_buffer'.
22 PODArray<char> own_compressed_buffer;
23 /// Points to memory, holding compressed block.
24 char * compressed_buffer = nullptr;
25
26 /// Don't checksum on decompressing.
27 bool disable_checksum = false;
28
29 /// Read compressed data into compressed_buffer. Get size of decompressed data from block header. Checksum if need.
30 /// Returns number of compressed bytes read.
31 size_t readCompressedData(size_t & size_decompressed, size_t & size_compressed_without_checksum);
32
33 void decompress(char * to, size_t size_decompressed, size_t size_compressed_without_checksum);
34
35public:
36 /// 'compressed_in' could be initialized lazily, but before first call of 'readCompressedData'.
37 CompressedReadBufferBase(ReadBuffer * in = nullptr);
38 ~CompressedReadBufferBase();
39
40 /** Disable checksums.
41 * For example, may be used when
42 * compressed data is generated by client, that cannot calculate checksums, and fill checksums with zeros instead.
43 */
44 void disableChecksumming()
45 {
46 disable_checksum = true;
47 }
48
49public:
50 CompressionCodecPtr codec;
51};
52
53}
54