proxygen
|
#include <Compression.h>
Public Member Functions | |
virtual | ~Codec () |
uint64_t | maxUncompressedLength () const |
CodecType | type () const |
bool | needsUncompressedLength () const |
std::unique_ptr< IOBuf > | compress (const folly::IOBuf *data) |
std::string | compress (StringPiece data) |
std::unique_ptr< IOBuf > | uncompress (const IOBuf *data, folly::Optional< uint64_t > uncompressedLength=folly::none) |
std::string | uncompress (StringPiece data, folly::Optional< uint64_t > uncompressedLength=folly::none) |
uint64_t | maxCompressedLength (uint64_t uncompressedLength) const |
folly::Optional< uint64_t > | getUncompressedLength (const folly::IOBuf *data, folly::Optional< uint64_t > uncompressedLength=folly::none) const |
virtual std::vector< std::string > | validPrefixes () const |
virtual bool | canUncompress (const folly::IOBuf *data, folly::Optional< uint64_t > uncompressedLength=folly::none) const |
Static Public Attributes | |
static constexpr uint64_t | UNLIMITED_UNCOMPRESSED_LENGTH = uint64_t(-1) |
Protected Member Functions | |
Codec (CodecType type, folly::Optional< int > level=folly::none, folly::StringPiece name={}, bool counters=true) | |
Private Member Functions | |
virtual uint64_t | doMaxUncompressedLength () const |
virtual bool | doNeedsUncompressedLength () const |
virtual std::unique_ptr< IOBuf > | doCompress (const folly::IOBuf *data)=0 |
virtual std::unique_ptr< IOBuf > | doUncompress (const folly::IOBuf *data, folly::Optional< uint64_t > uncompressedLength)=0 |
virtual std::string | doCompressString (StringPiece data) |
virtual std::string | doUncompressString (StringPiece data, folly::Optional< uint64_t > uncompressedLength) |
virtual uint64_t | doMaxCompressedLength (uint64_t uncompressedLength) const =0 |
virtual folly::Optional< uint64_t > | doGetUncompressedLength (const folly::IOBuf *data, folly::Optional< uint64_t > uncompressedLength) const |
Definition at line 131 of file Compression.h.
|
inlinevirtual |
Definition at line 133 of file Compression.h.
|
protected |
Definition at line 71 of file Compression.cpp.
References folly::BYTES_AFTER_COMPRESSION, folly::BYTES_AFTER_DECOMPRESSION, folly::BYTES_BEFORE_COMPRESSION, folly::BYTES_BEFORE_DECOMPRESSION, bytesAfterCompression_, bytesAfterDecompression_, bytesBeforeCompression_, bytesBeforeDecompression_, folly::COMPRESSION_MILLISECONDS, compressionMilliseconds_, folly::COMPRESSIONS, compressions_, counter, counter_, folly::DECOMPRESSION_MILLISECONDS, decompressionMilliseconds_, folly::DECOMPRESSIONS, decompressions_, name, folly::SUM, timer_, type(), and uint32_t.
Referenced by folly::io::StreamCodec::doUncompress().
|
virtual |
Returns true if the codec thinks it can uncompress the data. If a codec doesn't have magic bytes at the beginning, like LZ4 and Snappy, it can always return false. default: Returns false.
Definition at line 263 of file Compression.cpp.
Referenced by folly::io::StreamCodec::doUncompress().
std::unique_ptr< IOBuf > folly::io::Codec::compress | ( | const folly::IOBuf * | data | ) |
Compress data, returning an IOBuf (which may share storage with data). Throws std::invalid_argument if data is larger than maxUncompressedLength().
Definition at line 143 of file Compression.cpp.
References bytesAfterCompression_, bytesBeforeCompression_, compressionMilliseconds_, compressions_, folly::IOBuf::computeChainDataLength(), doCompress(), maxUncompressedLength(), folly::Random::oneIn(), and uint64_t.
std::string folly::io::Codec::compress | ( | StringPiece | 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.
Definition at line 163 of file Compression.cpp.
References bytesAfterCompression_, bytesBeforeCompression_, compressionMilliseconds_, compressions_, doCompressString(), maxUncompressedLength(), folly::Random::oneIn(), folly::Range< Iter >::size(), and uint64_t.
|
privatepure virtual |
Implemented in folly::io::StreamCodec.
Referenced by compress(), doCompressString(), and folly::io::StreamCodec::doUncompress().
|
privatevirtual |
Definition at line 267 of file Compression.cpp.
References doCompress(), gmock_output_test::output, folly::range(), string, and folly::IOBuf::WRAP_BUFFER.
Referenced by compress().
|
privatevirtual |
Definition at line 308 of file Compression.cpp.
Referenced by getUncompressedLength().
|
privatepure virtual |
Referenced by folly::io::StreamCodec::doUncompress(), and maxCompressedLength().
|
privatevirtual |
Definition at line 255 of file Compression.cpp.
References UNLIMITED_UNCOMPRESSED_LENGTH.
Referenced by folly::io::StreamCodec::doUncompress(), and maxUncompressedLength().
|
privatevirtual |
Definition at line 251 of file Compression.cpp.
Referenced by folly::io::StreamCodec::doUncompress(), and needsUncompressedLength().
|
privatepure virtual |
Implemented in folly::io::StreamCodec.
Referenced by folly::io::StreamCodec::doUncompress(), doUncompressString(), and uncompress().
|
privatevirtual |
Definition at line 278 of file Compression.cpp.
References doUncompress(), gmock_output_test::output, folly::range(), string, and folly::IOBuf::WRAP_BUFFER.
Referenced by uncompress().
Optional< uint64_t > folly::io::Codec::getUncompressedLength | ( | const folly::IOBuf * | data, |
folly::Optional< uint64_t > | uncompressedLength = folly::none |
||
) | const |
Extracts the uncompressed length from the compressed data if possible. If the codec doesn't store the uncompressed length, or the data is corrupted it returns the given uncompressedLength. If the uncompressed length is stored in the compressed data and uncompressedLength is not none and they do not match a std::runtime_error is thrown.
Definition at line 295 of file Compression.cpp.
References folly::IOBuf::computeChainDataLength(), doGetUncompressedLength(), and folly::Optional< Value >::value_or().
Referenced by folly::io::StreamCodec::doUncompress().
Returns a bound on the maximum compressed length when compressing data with the given uncompressed length.
Definition at line 291 of file Compression.cpp.
References doMaxCompressedLength().
Referenced by folly::io::StreamCodec::doCompress(), and folly::io::StreamCodec::doUncompress().
uint64_t folly::io::Codec::maxUncompressedLength | ( | ) | const |
Return the maximum length of data that may be compressed with this codec. NO_COMPRESSION and ZLIB support arbitrary lengths; LZ4 supports up to 1.9GiB; SNAPPY supports up to 4GiB. May return UNLIMITED_UNCOMPRESSED_LENGTH if unlimited.
Definition at line 247 of file Compression.cpp.
References doMaxUncompressedLength().
Referenced by compress(), folly::io::StreamCodec::doUncompress(), and uncompress().
bool folly::io::Codec::needsUncompressedLength | ( | ) | const |
Does this codec need the exact uncompressed length on decompression?
Definition at line 243 of file Compression.cpp.
References doNeedsUncompressedLength().
Referenced by uncompress().
|
inline |
Return the codec's type.
Definition at line 147 of file Compression.h.
References folly::data(), name, folly::none, string, type, type_, and uint64_t.
Referenced by Codec(), folly::io::StreamCodec::doUncompress(), folly::io::getCodec(), and folly::io::getStreamCodec().
std::unique_ptr< IOBuf > folly::io::Codec::uncompress | ( | const IOBuf * | data, |
folly::Optional< uint64_t > | uncompressedLength = folly::none |
||
) |
Uncompress data. Throws std::runtime_error on decompression error.
Some codecs (LZ4) require the exact uncompressed length; this is indicated by needsUncompressedLength().
For other codes (zlib), knowing the exact uncompressed length ahead of time might be faster.
Regardless of the behavior of the underlying compressor, uncompressing an empty IOBuf chain will return an empty IOBuf chain.
Definition at line 180 of file Compression.cpp.
References bytesAfterDecompression_, bytesBeforeDecompression_, folly::IOBuf::computeChainDataLength(), folly::IOBuf::create(), decompressionMilliseconds_, decompressions_, doUncompress(), folly::IOBuf::empty(), maxUncompressedLength(), needsUncompressedLength(), folly::Random::oneIn(), and folly::Optional< Value >::value_or().
std::string folly::io::Codec::uncompress | ( | StringPiece | data, |
folly::Optional< uint64_t > | uncompressedLength = folly::none |
||
) |
Uncompresses data. May involve additional copies compared to the overload that takes and returns IOBufs. Has the same error semantics as the IOBuf version.
Definition at line 213 of file Compression.cpp.
References bytesAfterDecompression_, bytesBeforeDecompression_, decompressionMilliseconds_, decompressions_, doUncompressString(), folly::Range< Iter >::empty(), maxUncompressedLength(), needsUncompressedLength(), folly::Random::oneIn(), folly::Range< Iter >::size(), and folly::Optional< Value >::value_or().
|
virtual |
Returns a superset of the set of prefixes for which canUncompress() will return true. A superset is allowed for optimizations in canUncompress() based on other knowledge such as length. None of the prefixes may be empty. default: No prefixes.
Definition at line 259 of file Compression.cpp.
Referenced by folly::io::StreamCodec::doUncompress().
|
private |
Definition at line 265 of file Compression.h.
Referenced by Codec(), and compress().
|
private |
Definition at line 267 of file Compression.h.
Referenced by Codec(), and uncompress().
|
private |
Definition at line 264 of file Compression.h.
Referenced by Codec(), and compress().
|
private |
Definition at line 266 of file Compression.h.
Referenced by Codec(), and uncompress().
|
private |
Definition at line 270 of file Compression.h.
Referenced by Codec(), and compress().
|
private |
Definition at line 268 of file Compression.h.
Referenced by Codec(), and compress().
|
private |
Definition at line 271 of file Compression.h.
Referenced by Codec(), and uncompress().
|
private |
Definition at line 269 of file Compression.h.
Referenced by Codec(), and uncompress().
|
private |
Definition at line 263 of file Compression.h.
Definition at line 135 of file Compression.h.
Referenced by doMaxUncompressedLength().