]>
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
20 #include <string_view>
21 #include <boost/optional.hpp>
22 #include "include/ceph_assert.h" // boost clobbers this
23 #include "include/common_fwd.h"
24 #include "include/buffer.h"
25 #include "include/int_types.h"
31 typedef std::shared_ptr
<Compressor
> CompressorRef
;
35 enum CompressionAlgorithm
{
46 COMP_ALG_LAST
//the last value for range checks
49 using pair_type
= std::pair
<const char*, CompressionAlgorithm
>;
50 static constexpr std::initializer_list
<pair_type
> compression_algorithms
{
51 { "none", COMP_ALG_NONE
},
52 { "snappy", COMP_ALG_SNAPPY
},
53 { "zlib", COMP_ALG_ZLIB
},
54 { "zstd", COMP_ALG_ZSTD
},
56 { "lz4", COMP_ALG_LZ4
},
59 { "brotli", COMP_ALG_BROTLI
},
63 // compression options
64 enum CompressionMode
{
65 COMP_NONE
, ///< compress never
66 COMP_PASSIVE
, ///< compress if hinted COMPRESSIBLE
67 COMP_AGGRESSIVE
, ///< compress unless hinted INCOMPRESSIBLE
68 COMP_FORCE
///< compress always
76 static const char* get_comp_alg_name(int a
);
77 static boost::optional
<CompressionAlgorithm
> get_comp_alg_type(const std::string
&s
);
79 static const char *get_comp_mode_name(int m
);
80 static boost::optional
<CompressionMode
> get_comp_mode_type(const std::string
&s
);
82 Compressor(CompressionAlgorithm a
, const char* t
) : alg(a
), type(t
) {
84 virtual ~Compressor() {}
85 const std::string
& get_type_name() const {
88 CompressionAlgorithm
get_type() const {
91 virtual int compress(const ceph::bufferlist
&in
, ceph::bufferlist
&out
) = 0;
92 virtual int decompress(const ceph::bufferlist
&in
, ceph::bufferlist
&out
) = 0;
93 // this is a bit weird but we need non-const iterator to be in
94 // alignment with decode methods
95 virtual int decompress(ceph::bufferlist::const_iterator
&p
, size_t compressed_len
, ceph::bufferlist
&out
) = 0;
97 static CompressorRef
create(CephContext
*cct
, const std::string
&type
);
98 static CompressorRef
create(CephContext
*cct
, int alg
);
101 CompressionAlgorithm alg
;