2018-10-11 02:57:48 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
#include <Core/Field.h>
|
|
|
|
#include <IO/ReadBuffer.h>
|
|
|
|
#include <IO/WriteBuffer.h>
|
|
|
|
#include <IO/BufferWithOwnMemory.h>
|
|
|
|
#include <Common/PODArray.h>
|
|
|
|
#include <DataTypes/IDataType.h>
|
|
|
|
#include <boost/noncopyable.hpp>
|
|
|
|
#include <IO/UncompressedCache.h>
|
|
|
|
#include <IO/LZ4_decompress_faster.h>
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
class ICompressionCodec;
|
|
|
|
|
|
|
|
using CompressionCodecPtr = std::shared_ptr<ICompressionCodec>;
|
|
|
|
using Codecs = std::vector<CompressionCodecPtr>;
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class ICompressionCodec : private boost::noncopyable
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
virtual ~ICompressionCodec() = default;
|
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
virtual UInt8 getMethodByte() const = 0;
|
|
|
|
|
|
|
|
virtual String getCodecDesc() const = 0;
|
|
|
|
|
|
|
|
virtual UInt32 compress(char * source, UInt32 source_size, char * dest) const;
|
|
|
|
|
|
|
|
virtual UInt32 decompress(char * source, UInt32 source_size, char * dest) const;
|
|
|
|
|
|
|
|
virtual UInt32 getCompressedReserveSize(UInt32 uncompressed_size) const { return getHeaderSize() + getCompressedDataSize(uncompressed_size); }
|
|
|
|
|
2018-12-20 10:27:38 +00:00
|
|
|
virtual UInt32 getAdditionalSizeAtTheEndOfBuffer() const { return 0; }
|
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
static UInt8 getHeaderSize() { return 1 + 8; }
|
|
|
|
|
|
|
|
static UInt32 readCompressedBlockSize(const char * source);
|
2018-10-11 02:57:48 +00:00
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
static UInt32 readDecompressedBlockSize(const char * source);
|
2018-10-11 02:57:48 +00:00
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
static UInt8 readMethod(const char * source);
|
2018-10-11 02:57:48 +00:00
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
protected:
|
2018-10-11 02:57:48 +00:00
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
virtual UInt32 getCompressedDataSize(UInt32 uncompressed_size) const { return uncompressed_size; }
|
2018-10-11 02:57:48 +00:00
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
virtual UInt32 doCompressData(const char * source, UInt32 source_size, char * dest) const = 0;
|
2018-10-11 02:57:48 +00:00
|
|
|
|
2018-12-19 17:20:18 +00:00
|
|
|
virtual void doDecompressData(const char * source, UInt32 source_size, char * dest, UInt32 uncompressed_size) const = 0;
|
2018-10-11 02:57:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}
|