]> git.proxmox.com Git - ceph.git/blob - ceph/src/compressor/Compressor.h
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / compressor / Compressor.h
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
18 #include <string>
19 #include <boost/optional.hpp>
20 #include "include/memory.h"
21 #include "include/buffer.h"
22
23 class Compressor;
24 typedef shared_ptr<Compressor> CompressorRef;
25
26 class Compressor {
27 public:
28 enum CompressionAlgorithm {
29 COMP_ALG_NONE = 0,
30 COMP_ALG_SNAPPY = 1,
31 COMP_ALG_ZLIB = 2,
32 COMP_ALG_ZSTD = 3,
33 COMP_ALG_LAST //the last value for range checks
34 };
35 // compression options
36 enum CompressionMode {
37 COMP_NONE, ///< compress never
38 COMP_PASSIVE, ///< compress if hinted COMPRESSIBLE
39 COMP_AGGRESSIVE, ///< compress unless hinted INCOMPRESSIBLE
40 COMP_FORCE ///< compress always
41 };
42
43 static const char * get_comp_alg_name(int a);
44 static boost::optional<CompressionAlgorithm> get_comp_alg_type(const std::string &s);
45
46 static const char *get_comp_mode_name(int m);
47 static boost::optional<CompressionMode> get_comp_mode_type(const std::string &s);
48
49 Compressor(CompressionAlgorithm a, const char* t) : alg(a), type(t) {
50 }
51 virtual ~Compressor() {}
52 const std::string& get_type_name() const {
53 return type;
54 }
55 CompressionAlgorithm get_type() const {
56 return alg;
57 }
58 virtual int compress(const bufferlist &in, bufferlist &out) = 0;
59 virtual int decompress(const bufferlist &in, bufferlist &out) = 0;
60 // this is a bit weird but we need non-const iterator to be in
61 // alignment with decode methods
62 virtual int decompress(bufferlist::iterator &p, size_t compressed_len, bufferlist &out) = 0;
63
64 static CompressorRef create(CephContext *cct, const std::string &type);
65 static CompressorRef create(CephContext *cct, int alg);
66
67 protected:
68 CompressionAlgorithm alg;
69 std::string type;
70
71 };
72
73 #endif