proxygen
Zstd.h
Go to the documentation of this file.
1 /*
2  * Copyright 2018-present Facebook, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 
19 #include <memory.h>
20 
21 #include <folly/Memory.h>
22 #include <folly/Portability.h>
24 
25 #if FOLLY_HAVE_LIBZSTD
26 
27 #ifndef ZSTD_STATIC_LINKING_ONLY
28 #define ZSTD_STATIC_LINKING_ONLY
29 #endif
30 #include <zstd.h>
31 
32 namespace folly {
33 namespace io {
34 namespace zstd {
35 
39 class Options {
40  public:
41  /* Create an Options struct with the default options for the given `level`.
42  * NOTE: This is the zstd level, COMPRESSION_LEVEL_DEFAULT and such aren't
43  * supported, since zstd supports negative compression levels.
44  */
45  explicit Options(int level);
46 
52  void set(ZSTD_cParameter param, unsigned value);
53 
60  void setMaxWindowSize(size_t maxWindowSize) {
61  maxWindowSize_ = maxWindowSize;
62  }
63 
65  ZSTD_CCtx_params const* params() const {
66  return params_.get();
67  }
68 
70  int level() const {
71  return level_;
72  }
73 
75  size_t maxWindowSize() const {
76  return maxWindowSize_;
77  }
78 
79  private:
80  static void freeCCtxParams(ZSTD_CCtx_params* params);
81  std::unique_ptr<
82  ZSTD_CCtx_params,
84  params_;
85  size_t maxWindowSize_{0};
86  int level_;
87 };
88 
90 std::unique_ptr<Codec> getCodec(Options options);
92 std::unique_ptr<StreamCodec> getStreamCodec(Options options);
93 
94 } // namespace zstd
95 } // namespace io
96 } // namespace folly
97 
98 #endif
—— Concurrent Priority Queue Implementation ——
Definition: AtomicBitSet.h:29
constexpr Params params[]
std::unique_ptr< StreamCodec > getStreamCodec(CodecType type, int level)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
std::unique_ptr< Codec > getCodec(CodecType type, int level)