MADARA  3.4.1
LZ4BufferFilter.cpp
Go to the documentation of this file.
1 
2 #ifdef _USE_LZ4_
3 
4 #include <string.h>
5 #include "LZ4BufferFilter.h"
6 #include "lz4.h"
9 
11  char* source, int size, int max_size) const
12 {
13  char* source_copy = new char[buffer_size];
14  memcpy(source_copy, source, size);
15 
17  "LZ4BufferFilter::encode: calling LZ4_compress_default(%d,%d).\n", size,
18  max_size);
19 
20  int new_size =
21  LZ4_compress_default(source_copy, (char*)source, size, max_size);
22  delete[] source_copy;
23 
25  "LZ4BufferFilter::encode: new_size=%d.\n", new_size);
26 
27  // error codes are negative and appear to point to where in the buffer
28  // bad things happened
29  return new_size > 0 ? new_size : 0;
30 }
31 
33  char* source, int size, int max_size) const
34 {
35  char* source_copy = new char[buffer_size];
36  memcpy(source_copy, source, size);
37 
39  "LZ4BufferFilter::decode: calling LZ4_decompress_safe(%d,%d).\n", size,
40  max_size);
41 
42  int new_size =
43  LZ4_decompress_safe(source_copy, (char*)source, size, max_size);
44  delete[] source_copy;
45 
47  "LZ4BufferFilter::decode: new_size=%d.\n", new_size);
48 
49  // error codes are negative and appear to point to where in the buffer
50  // bad things happened
51  return new_size > 0 ? new_size : 0;
52 }
53 
55 {
56  return "lz4";
57 }
58 
60 {
61  return madara::utility::get_uint_version("1.0.0");
62 }
63 
64 #endif // _USE_SSL_
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
Definition: Logger.h:41
virtual int decode(char *source, int size, int max_size) const
Decodes the buffer in place using LZ4 decompression.
virtual uint32_t get_version(void)
Gets the version of the filter.
int buffer_size
the size of the decompress buffer (max size)
virtual int encode(char *source, int size, int max_size) const
Encodes the buffer in place using LZ4 compression.
virtual std::string get_id(void)
Gets the id of the filter.
constexpr string_t string
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
uint32_t get_uint_version(const std::string &str_version)
Converts a string version to a uint32.
Definition: Utility.cpp:30