summaryrefslogtreecommitdiffstats
path: root/other-licenses/snappy/src/snappy.h
diff options
context:
space:
mode:
Diffstat (limited to 'other-licenses/snappy/src/snappy.h')
-rw-r--r--other-licenses/snappy/src/snappy.h56
1 files changed, 46 insertions, 10 deletions
diff --git a/other-licenses/snappy/src/snappy.h b/other-licenses/snappy/src/snappy.h
index e4fdad3354..9e0572dcc8 100644
--- a/other-licenses/snappy/src/snappy.h
+++ b/other-licenses/snappy/src/snappy.h
@@ -50,13 +50,36 @@ namespace snappy {
class Source;
class Sink;
+ struct CompressionOptions {
+ // Compression level.
+ // Level 1 is the fastest
+ // Level 2 is a little slower but provides better compression. Level 2 is
+ // **EXPERIMENTAL** for the time being. It might happen that we decide to
+ // fall back to level 1 in the future.
+ // Levels 3+ are currently not supported. We plan to support levels up to
+ // 9 in the future.
+ // If you played with other compression algorithms, level 1 is equivalent to
+ // fast mode (level 1) of LZ4, level 2 is equivalent to LZ4's level 2 mode
+ // and compresses somewhere around zstd:-3 and zstd:-2 but generally with
+ // faster decompression speeds than snappy:1 and zstd:-3.
+ int level = DefaultCompressionLevel();
+
+ constexpr CompressionOptions() = default;
+ constexpr explicit CompressionOptions(int compression_level)
+ : level(compression_level) {}
+ static constexpr int MinCompressionLevel() { return 1; }
+ static constexpr int MaxCompressionLevel() { return 2; }
+ static constexpr int DefaultCompressionLevel() { return 1; }
+ };
+
// ------------------------------------------------------------------------
// Generic compression/decompression routines.
// ------------------------------------------------------------------------
- // Compress the bytes read from "*source" and append to "*sink". Return the
+ // Compress the bytes read from "*reader" and append to "*writer". Return the
// number of bytes written.
- size_t Compress(Source* source, Sink* sink);
+ size_t Compress(Source* reader, Sink* writer,
+ CompressionOptions options = {});
// Find the uncompressed length of the given stream, as given by the header.
// Note that the true length could deviate from this; the stream could e.g.
@@ -71,14 +94,22 @@ namespace snappy {
// Higher-level string based routines (should be sufficient for most users)
// ------------------------------------------------------------------------
- // Sets "*compressed" to the compressed version of "input[0,input_length-1]".
+ // Sets "*compressed" to the compressed version of "input[0..input_length-1]".
// Original contents of *compressed are lost.
//
// REQUIRES: "input[]" is not an alias of "*compressed".
size_t Compress(const char* input, size_t input_length,
- std::string* compressed);
+ std::string* compressed, CompressionOptions options = {});
+
+ // Same as `Compress` above but taking an `iovec` array as input. Note that
+ // this function preprocesses the inputs to compute the sum of
+ // `iov[0..iov_cnt-1].iov_len` before reading. To avoid this, use
+ // `RawCompressFromIOVec` below.
+ size_t CompressFromIOVec(const struct iovec* iov, size_t iov_cnt,
+ std::string* compressed,
+ CompressionOptions options = {});
- // Decompresses "compressed[0,compressed_length-1]" to "*uncompressed".
+ // Decompresses "compressed[0..compressed_length-1]" to "*uncompressed".
// Original contents of "*uncompressed" are lost.
//
// REQUIRES: "compressed[]" is not an alias of "*uncompressed".
@@ -119,10 +150,15 @@ namespace snappy {
// RawCompress(input, input_length, output, &output_length);
// ... Process(output, output_length) ...
// delete [] output;
- void RawCompress(const char* input,
- size_t input_length,
- char* compressed,
- size_t* compressed_length);
+ void RawCompress(const char* input, size_t input_length, char* compressed,
+ size_t* compressed_length, CompressionOptions options = {});
+
+ // Same as `RawCompress` above but taking an `iovec` array as input. Note that
+ // `uncompressed_length` is the total number of bytes to be read from the
+ // elements of `iov` (_not_ the number of elements in `iov`).
+ void RawCompressFromIOVec(const struct iovec* iov, size_t uncompressed_length,
+ char* compressed, size_t* compressed_length,
+ CompressionOptions options = {});
// Given data in "compressed[0..compressed_length-1]" generated by
// calling the Snappy::Compress routine, this routine
@@ -202,7 +238,7 @@ namespace snappy {
static constexpr int kMinHashTableBits = 8;
static constexpr size_t kMinHashTableSize = 1 << kMinHashTableBits;
- static constexpr int kMaxHashTableBits = 14;
+ static constexpr int kMaxHashTableBits = 15;
static constexpr size_t kMaxHashTableSize = 1 << kMaxHashTableBits;
} // end namespace snappy