]>
git.proxmox.com Git - ceph.git/blob - 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
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
19 #include <boost/optional.hpp>
20 #include "include/memory.h"
21 #include "include/buffer.h"
24 typedef shared_ptr
<Compressor
> CompressorRef
;
28 enum CompressionAlgorithm
{
33 COMP_ALG_LAST
//the last value for range checks
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
43 static const char * get_comp_alg_name(int a
);
44 static boost::optional
<CompressionAlgorithm
> get_comp_alg_type(const std::string
&s
);
46 static const char *get_comp_mode_name(int m
);
47 static boost::optional
<CompressionMode
> get_comp_mode_type(const std::string
&s
);
49 Compressor(CompressionAlgorithm a
, const char* t
) : alg(a
), type(t
) {
51 virtual ~Compressor() {}
52 const std::string
& get_type_name() const {
55 CompressionAlgorithm
get_type() const {
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;
64 static CompressorRef
create(CephContext
*cct
, const std::string
&type
);
65 static CompressorRef
create(CephContext
*cct
, int alg
);
68 CompressionAlgorithm alg
;