X-Git-Url: http://plrg.eecs.uci.edu/git/?p=folly.git;a=blobdiff_plain;f=folly%2Fio%2FCompression.h;h=05ce06d1f66662e102945914ab9351f6f255aa9a;hp=78161f315fafa4a129d0ed4e323345433121c8d2;hb=a5093cb5789077f87204ddf9b0c7c9f261ea9e6c;hpb=a1abbb7abcb259acbd94d0d0929b79607a8ce806 diff --git a/folly/io/Compression.h b/folly/io/Compression.h index 78161f31..05ce06d1 100644 --- a/folly/io/Compression.h +++ b/folly/io/Compression.h @@ -20,6 +20,7 @@ #include #include +#include #include /** @@ -119,6 +120,13 @@ class Codec { */ std::unique_ptr compress(const folly::IOBuf* data); + /** + * Compresses data. May involve additional copies compared to the overload + * that takes and returns IOBufs. Has the same error semantics as the IOBuf + * version. + */ + std::string compress(StringPiece data); + /** * Uncompress data. Throws std::runtime_error on decompression error. * @@ -138,6 +146,15 @@ class Codec { const IOBuf* data, uint64_t uncompressedLength = UNKNOWN_UNCOMPRESSED_LENGTH); + /** + * Uncompresses data. May involve additional copies compared to the overload + * that takes and returns IOBufs. Has the same error semantics as the IOBuf + * version. + */ + std::string uncompress( + StringPiece data, + uint64_t uncompressedLength = UNKNOWN_UNCOMPRESSED_LENGTH); + protected: explicit Codec(CodecType type); @@ -149,6 +166,14 @@ class Codec { virtual std::unique_ptr doCompress(const folly::IOBuf* data) = 0; virtual std::unique_ptr doUncompress(const folly::IOBuf* data, uint64_t uncompressedLength) = 0; + // default: an implementation is provided by default to wrap the strings into + // IOBufs and delegate to the IOBuf methods. This incurs a copy of the output + // from IOBuf to string. Implementers, at their discretion, can override + // these methods to avoid the copy. + virtual std::string doCompressString(StringPiece data); + virtual std::string doUncompressString( + StringPiece data, + uint64_t uncompressedLength); CodecType type_; };