36 #include <ThirdParty/lzo/minilzo.h>
41 const uint8_t fence_marker[4] = { 0x11, 0x11, 0x11, 0x11 };
46 : m_workmem(new uint8_t [LZO1X_1_MEM_COMPRESS + 4]) {
47 if (lzo_init() != LZO_E_OK)
49 "Problem initializing lzo library");
50 memcpy(&
m_workmem[LZO1X_1_MEM_COMPRESS], fence_marker, 4);
66 uint32_t avail_out = (input.
fill() + input.
fill() / 16 + 64 + 3 + 4);
68 lzo_uint out_len = avail_out;
69 uint8_t *fence_ptr = 0;
75 memcpy(fence_ptr, fence_marker, 4);
79 assert(ret == LZO_E_OK);
83 if (out_len >= input.
fill()) {
101 HT_ASSERT(!memcmp(fence_ptr, fence_marker, 4));
113 const uint8_t *msg_ptr = input.
base;
114 size_t remaining = input.
fill();
117 header.
decode(&msg_ptr, &remaining);
120 HT_ERRORF(
"Block decompression error, header zlength = %d, actual = %d",
127 HT_ERRORF(
"Compressed block checksum mismatch header=%u, computed=%u",
142 HT_ERRORF(
"Lzo decompression error, rval = %d", ret);
BlockCompressionCodecLzo(const Args &args)
Constructor.
std::unique_ptr< uint8_t[]> m_workmem
Working memory buffer used by deflate() and inflate()
virtual void set_args(const Args &args)
Sets arguments to control compression behavior.
uint8_t * ptr
Pointer to the end of the used part of the buffer.
A dynamic, resizable and reference counted memory buffer.
std::vector< String > Args
Compression codec argument vector.
uint32_t fletcher32(const void *data8, size_t len8)
Compute fletcher32 checksum for arbitary data.
A dynamic, resizable memory buffer.
Logging routines and macros.
Compatibility Macros for C/C++.
virtual ~BlockCompressionCodecLzo()
Destructor.
Implementation of checksum routines.
void clear()
Clears the buffer.
virtual void deflate(const DynamicBuffer &input, DynamicBuffer &output, BlockHeader &header, size_t reserve=0)
Compresses a buffer using the LZO algorithm.
uint8_t * base
Pointer to the allocated memory buffer.
virtual void inflate(const DynamicBuffer &input, DynamicBuffer &output, BlockHeader &header)
Decompresses a buffer compressed with the LZO algorithm.
size_t fill() const
Returns the size of the used portion.
#define HT_ERRORF(msg,...)
Declarations for BlockCompressionCodecLzo.
Error codes, Exception handling, error logging.
#define HT_THROW(_code_, _msg_)
void reserve(size_t len, bool nocopy=false)
Reserve space for additional data Will grow the space to exactly what's needed.