summaryrefslogtreecommitdiff
path: root/snappy.h
diff options
context:
space:
mode:
authorMatt Callanan <mpcallanan@google.com>2022-09-26 10:23:33 -0700
committerVictor Costan <costan@google.com>2022-09-29 09:32:28 -0700
commit9758c9dfd744f252bf3351c1a212e05c9f7fc857 (patch)
tree3dc9b0855cbae727ec38424c42a47a46c90b9a2b /snappy.h
parentaf720f9a3b2c831f173b6074961737516f2d3a46 (diff)
downloadsnappy-git-9758c9dfd744f252bf3351c1a212e05c9f7fc857.tar.gz
Add `snappy::CompressFromIOVec`.
This reads from an `iovec` array rather than from a `char` array as in `snappy::Compress`. PiperOrigin-RevId: 476930623
Diffstat (limited to 'snappy.h')
-rw-r--r--snappy.h17
1 files changed, 15 insertions, 2 deletions
diff --git a/snappy.h b/snappy.h
index e4fdad3..e12b658 100644
--- a/snappy.h
+++ b/snappy.h
@@ -71,14 +71,21 @@ 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);
- // Decompresses "compressed[0,compressed_length-1]" to "*uncompressed".
+ // 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);
+
+ // Decompresses "compressed[0..compressed_length-1]" to "*uncompressed".
// Original contents of "*uncompressed" are lost.
//
// REQUIRES: "compressed[]" is not an alias of "*uncompressed".
@@ -124,6 +131,12 @@ namespace snappy {
char* compressed,
size_t* compressed_length);
+ // 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);
+
// Given data in "compressed[0..compressed_length-1]" generated by
// calling the Snappy::Compress routine, this routine
// stores the uncompressed data to