1 // -*- mode:C++; tab-width:8; c-basic-offset:2; indent-tabs-mode:t -*-
2 // vim: ts=8 sw=2 smarttab
4 * Ceph - scalable distributed file system
6 * Copyright (C) 2015 Haomai Wang <haomaiwang@gmail.com>
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.
15 #ifndef CEPH_COMPRESSOR_H
16 #define CEPH_COMPRESSOR_H
21 #include <boost/optional.hpp>
22 #include "include/assert.h" // boost clobbers this
23 #include "include/buffer.h"
24 #include "include/int_types.h"
27 typedef std::shared_ptr<Compressor> CompressorRef;
32 enum CompressionAlgorithm {
40 COMP_ALG_LAST //the last value for range checks
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
50 static const char * get_comp_alg_name(int a);
51 static boost::optional<CompressionAlgorithm> get_comp_alg_type(const std::string &s);
53 static const char *get_comp_mode_name(int m);
54 static boost::optional<CompressionMode> get_comp_mode_type(const std::string &s);
56 Compressor(CompressionAlgorithm a, const char* t) : alg(a), type(t) {
58 virtual ~Compressor() {}
59 const std::string& get_type_name() const {
62 CompressionAlgorithm get_type() const {
65 virtual int compress(const ceph::bufferlist &in, ceph::bufferlist &out) = 0;
66 virtual int decompress(const ceph::bufferlist &in, ceph::bufferlist &out) = 0;
67 // this is a bit weird but we need non-const iterator to be in
68 // alignment with decode methods
69 virtual int decompress(ceph::bufferlist::iterator &p, size_t compressed_len, ceph::bufferlist &out) = 0;
71 static CompressorRef create(CephContext *cct, const std::string &type);
72 static CompressorRef create(CephContext *cct, int alg);
75 CompressionAlgorithm alg;