]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*- |
2 | // vim: ts=8 sw=2 smarttab | |
3 | /* | |
4 | * Ceph - scalable distributed file system | |
5 | * | |
6 | * Copyright (C) 2015 Haomai Wang <haomaiwang@gmail.com> | |
7 | * | |
8 | * This is free software; you can redistribute it and/or | |
9 | * modify it under the terms of the GNU Lesser General Public | |
10 | * License version 2.1, as published by the Free Software | |
11 | * Foundation. See file COPYING. | |
12 | * | |
13 | */ | |
14 | ||
15 | #ifndef CEPH_COMPRESSOR_H | |
16 | #define CEPH_COMPRESSOR_H | |
17 | ||
31f18b77 FG |
18 | |
19 | #include <memory> | |
7c673cae FG |
20 | #include <string> |
21 | #include <boost/optional.hpp> | |
31f18b77 | 22 | #include "include/assert.h" // boost clobbers this |
7c673cae | 23 | #include "include/buffer.h" |
31f18b77 | 24 | #include "include/int_types.h" |
7c673cae FG |
25 | |
26 | class Compressor; | |
31f18b77 FG |
27 | typedef std::shared_ptr<Compressor> CompressorRef; |
28 | class CephContext; | |
7c673cae FG |
29 | |
30 | class Compressor { | |
31 | public: | |
32 | enum CompressionAlgorithm { | |
33 | COMP_ALG_NONE = 0, | |
34 | COMP_ALG_SNAPPY = 1, | |
35 | COMP_ALG_ZLIB = 2, | |
36 | COMP_ALG_ZSTD = 3, | |
b5b8bbf5 | 37 | #ifdef HAVE_LZ4 |
31f18b77 | 38 | COMP_ALG_LZ4 = 4, |
b5b8bbf5 | 39 | #endif |
7c673cae FG |
40 | COMP_ALG_LAST //the last value for range checks |
41 | }; | |
42 | // compression options | |
43 | enum CompressionMode { | |
44 | COMP_NONE, ///< compress never | |
45 | COMP_PASSIVE, ///< compress if hinted COMPRESSIBLE | |
46 | COMP_AGGRESSIVE, ///< compress unless hinted INCOMPRESSIBLE | |
47 | COMP_FORCE ///< compress always | |
48 | }; | |
49 | ||
50 | static const char * get_comp_alg_name(int a); | |
51 | static boost::optional<CompressionAlgorithm> get_comp_alg_type(const std::string &s); | |
52 | ||
53 | static const char *get_comp_mode_name(int m); | |
54 | static boost::optional<CompressionMode> get_comp_mode_type(const std::string &s); | |
55 | ||
56 | Compressor(CompressionAlgorithm a, const char* t) : alg(a), type(t) { | |
57 | } | |
58 | virtual ~Compressor() {} | |
59 | const std::string& get_type_name() const { | |
60 | return type; | |
61 | } | |
62 | CompressionAlgorithm get_type() const { | |
63 | return alg; | |
64 | } | |
31f18b77 FG |
65 | virtual int compress(const ceph::bufferlist &in, ceph::bufferlist &out) = 0; |
66 | virtual int decompress(const ceph::bufferlist &in, ceph::bufferlist &out) = 0; | |
7c673cae FG |
67 | // this is a bit weird but we need non-const iterator to be in |
68 | // alignment with decode methods | |
31f18b77 | 69 | virtual int decompress(ceph::bufferlist::iterator &p, size_t compressed_len, ceph::bufferlist &out) = 0; |
7c673cae FG |
70 | |
71 | static CompressorRef create(CephContext *cct, const std::string &type); | |
72 | static CompressorRef create(CephContext *cct, int alg); | |
73 | ||
74 | protected: | |
75 | CompressionAlgorithm alg; | |
76 | std::string type; | |
77 | ||
78 | }; | |
79 | ||
80 | #endif |