0.9.8.10
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
BlockCompressionCodec.h
Go to the documentation of this file.
1 /* -*- c++ -*-
2  * Copyright (C) 2007-2015 Hypertable, Inc.
3  *
4  * This file is part of Hypertable.
5  *
6  * Hypertable is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; version 3 of the
9  * License, or any later version.
10  *
11  * Hypertable is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
19  * 02110-1301, USA.
20  */
21 
26 
27 #ifndef Hypertable_Lib_BlockCompressionCodec_h
28 #define Hypertable_Lib_BlockCompressionCodec_h
29 
30 #include <Common/Error.h>
31 #include <Common/String.h>
32 
34 
35 #include <cassert>
36 #include <memory>
37 #include <vector>
38 
39 namespace Hypertable {
40 
41  class DynamicBuffer;
42 
45 
48  public:
49 
51  enum Type {
52  UNKNOWN=-1,
53  NONE=0,
54  BMZ=1,
55  ZLIB=2,
56  LZO=3,
57  QUICKLZ=4,
58  SNAPPY=5,
60  };
61 
63  typedef std::vector<String> Args;
64 
68  static const char *get_compressor_name(uint16_t algo);
69 
71  virtual ~BlockCompressionCodec() { }
72 
78  virtual void deflate(const DynamicBuffer &input, DynamicBuffer &output,
79  BlockHeader &header, size_t reserve=0) = 0;
80 
85  virtual void inflate(const DynamicBuffer &input, DynamicBuffer &output,
86  BlockHeader &header) = 0;
87 
93  virtual void set_args(const Args &args) {
94  for (const auto &arg : args)
95  HT_THROWF(Error::BLOCK_COMPRESSOR_INVALID_ARG, "Unrecognized argument "
96  "to %s codec: '%s'", get_compressor_name(get_type()),
97  arg.c_str());
98  }
99 
104  virtual int get_type() = 0;
105 
106  };
107 
109  typedef std::shared_ptr<BlockCompressionCodec> BlockCompressionCodecPtr;
110 
112 
113 }
114 
115 #endif // Hypertable_Lib_BlockCompressionCodec_h
std::shared_ptr< BlockCompressionCodec > BlockCompressionCodecPtr
Smart pointer to BlockCompressionCodec.
virtual void set_args(const Args &args)
Sets arguments to control compression behavior.
Type
Enumeration for compression type.
Declarations for BlockHeader.
A dynamic, resizable and reference counted memory buffer.
Definition: DynamicBuffer.h:42
std::vector< String > Args
Compression codec argument vector.
Bentley-McIlroy large common substring compression.
virtual int get_type()=0
Returns compression type enum.
Hypertable definitions
static const char * get_compressor_name(uint16_t algo)
Returns string mnemonic for compression type.
#define HT_THROWF(_code_, _fmt_,...)
Definition: Error.h:490
virtual void deflate(const DynamicBuffer &input, DynamicBuffer &output, BlockHeader &header, size_t reserve=0)=0
Compresses a buffer.
A String class based on std::string.
Base class for block headers.
Definition: BlockHeader.h:48
virtual void inflate(const DynamicBuffer &input, DynamicBuffer &output, BlockHeader &header)=0
Decompresses a buffer.
Error codes, Exception handling, error logging.
Abstract base class for block compression codecs.
virtual ~BlockCompressionCodec()
Destructor.