23 #include <unordered_map> 26 #include <boost/noncopyable.hpp> 27 #include <glog/logging.h> 35 #if FOLLY_HAVE_LIBZSTD 44 namespace zlib = folly::io::zlib;
59 std::unique_ptr<uint8_t[]>
data_;
60 mutable std::unordered_map<uint64_t, uint64_t>
hashCache_;
67 CHECK_LE(size,
size_);
79 CHECK_LE(size,
size_);
85 for (
auto&
range : *buf) {
97 static constexpr
size_t numThreadsLog2 = 3;
98 static constexpr
size_t numThreads = size_t(1) << numThreadsLog2;
102 std::vector<std::thread>
threads;
103 threads.reserve(numThreads);
104 for (
size_t t = 0;
t < numThreads; ++
t) {
105 threads.emplace_back([
this, seed,
t, sizeLog2] {
106 std::mt19937
rng(seed +
t);
107 size_t countLog2 = sizeLog2 - numThreadsLog2;
108 size_t start = size_t(
t) << countLog2;
109 for (
size_t i = 0;
i < countLog2; ++
i) {
115 for (
auto&
t : threads) {
135 std::vector<CodecType> supported;
145 std::vector<CodecType> codecs;
150 codecs.push_back(
type);
158 std::vector<CodecType> codecs;
163 codecs.push_back(
type);
170 TEST(CompressionTestNeedsUncompressedLength, Simple) {
171 static const struct {
173 bool needsUncompressedLength;
188 for (
auto const&
test : expectations) {
192 test.needsUncompressedLength);
198 :
public testing::TestWithParam<std::tuple<int, int, CodecType>> {
201 auto tup = GetParam();
202 int lengthLog = std::get<0>(tup);
204 uncompressedLength_ = (lengthLog < 0) ? 0 : uint64_t(1) << std::get<0>(tup);
205 chunks_ = std::get<1>(tup);
209 void runSimpleIOBufTest(
const DataHolder& dh);
211 void runSimpleStringTest(
const DataHolder& dh);
214 std::unique_ptr<IOBuf>
split(std::unique_ptr<IOBuf>
data)
const;
223 const auto compressed =
split(
codec_->compress(original.get()));
225 compressed->computeChainDataLength(),
226 codec_->maxCompressedLength(uncompressedLength_));
227 if (!
codec_->needsUncompressedLength()) {
228 auto uncompressed =
codec_->uncompress(compressed.get());
229 EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength());
234 codec_->uncompress(compressed.get(), uncompressedLength_);
235 EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength());
242 reinterpret_cast<const char*>(dh.
data(uncompressedLength_).
data()),
243 uncompressedLength_);
244 const auto compressed =
codec_->compress(original);
246 compressed.length(),
codec_->maxCompressedLength(uncompressedLength_));
248 if (!
codec_->needsUncompressedLength()) {
249 auto uncompressed =
codec_->uncompress(compressed);
250 EXPECT_EQ(uncompressedLength_, uncompressed.length());
254 auto uncompressed =
codec_->uncompress(compressed, uncompressedLength_);
255 EXPECT_EQ(uncompressedLength_, uncompressed.length());
262 std::unique_ptr<IOBuf>
data)
const {
263 if (data->isChained()) {
267 const size_t size = data->computeChainDataLength();
269 std::multiset<size_t> splits;
270 for (
size_t i = 1;
i < chunks_; ++
i) {
277 for (
size_t split : splits) {
283 return result.
move();
306 testing::Values(-1, 0, 1, 12, 22, 25, 27),
307 testing::Values(1, 2, 3, 8, 65),
311 :
public testing::TestWithParam<std::tuple<int, CodecType>> {
314 auto tup = GetParam();
315 uncompressedLength_ =
uint64_t(1) << std::get<0>(tup);
327 for (; number > 0; ++pos, number >>= 1) {
334 auto compressed =
codec_->compress(original.get());
340 compressed->data(),
std::min(compressed->length(), breakPoint));
341 compressed->trimStart(breakPoint);
342 tinyBuf->prependChain(
std::move(compressed));
345 auto uncompressed =
codec_->uncompress(compressed.get());
347 EXPECT_EQ(uncompressedLength_, uncompressed->computeChainDataLength());
363 testing::Values(0, 1, 12, 22, 25, 27),
369 TEST(LZMATest, UncompressBadVarint) {
393 constexpr
uint64_t uncompressedLength = 42;
395 auto compressed =
codec_->compress(original.get());
397 if (!
codec_->needsUncompressedLength()) {
398 auto uncompressed =
codec_->uncompress(compressed.get());
399 EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
404 codec_->uncompress(compressed.get(), uncompressedLength);
405 EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
410 codec_->uncompress(compressed.get(), uncompressedLength + 1),
413 auto corrupted = compressed->clone();
414 corrupted->unshare();
416 corrupted->prev()->trimEnd(1);
417 if (!
codec_->needsUncompressedLength()) {
422 codec_->uncompress(corrupted.get(), uncompressedLength),
425 corrupted = compressed->clone();
426 corrupted->unshare();
428 ++(corrupted->writableData()[0]);
430 if (!
codec_->needsUncompressedLength()) {
435 codec_->uncompress(corrupted.get(), uncompressedLength),
480 static const struct {
482 bool needsDataLength;
491 for (
auto const&
test : expectations) {
500 for (
uint64_t const length : {1, 10, 100, 1000, 10000, 100000, 1000000}) {
512 auto const compressed =
codec_->compress(
data.get());
514 if (
auto const length =
codec_->getUncompressedLength(
data.get())) {
532 if (!
codec_->needsDataLength()) {
544 size_t compressedSize =
buffer->length() - output.
size();
545 auto const compressed =
547 auto inputRange = compressed->coalesce();
558 largeBuffer->append(largeBuffer->capacity());
560 output = {largeBuffer->writableData(), largeBuffer->length()};
596 inBuffer->writableData()[0] =
'a';
597 inBuffer->writableData()[1] =
'a';
599 const auto compressed =
codec_->compress(inBuffer.get());
605 const std::array<StreamCodec::FlushOp, 3> flushOps = {{
613 for (
const auto flushOp : flushOps) {
617 if (
codec_->needsDataLength()) {
618 codec_->resetStream(inBuffer->computeChainDataLength());
622 auto input = inBuffer->coalesce();
624 outBuffer->tailroom()};
626 while (!input.empty()) {
627 codec_->compressStream(input, output);
631 codec_->compressStream(emptyInput, emptyOutput, flushOp),
637 for (
const auto flushOp : flushOps) {
642 auto input = compressed->coalesce();
644 input.uncheckedSubtract(1);
647 while (!input.empty()) {
652 codec_->uncompressStream(emptyInput, emptyOutput, flushOp),
659 inBuffer->writableData()[0] =
'a';
660 inBuffer->writableData()[1] =
'a';
662 auto compressed =
codec_->compress(inBuffer.get());
663 ByteRange const in = compressed->coalesce();
665 MutableByteRange const out{outBuffer->writableTail(), outBuffer->tailroom()};
668 bool empty =
false) {
673 auto compress_all = [&](
bool expect,
676 bool empty =
false) {
679 while (!input.empty()) {
689 bool empty =
false) {
692 return codec_->uncompressStream(input,
output, flushOp);
696 if (!
codec_->needsDataLength()) {
735 codec_->resetStream(inBuffer->computeChainDataLength());
739 if (!
codec_->needsDataLength()) {
766 codec_->compress(inBuffer.get());
768 codec_->uncompress(compressed.get(), inBuffer->computeChainDataLength());
771 codec_->uncompress(compressed.get());
772 codec_->compress(inBuffer.get());
781 :
public testing::TestWithParam<std::tuple<int, int, CodecType>> {
788 auto const tup = GetParam();
789 uncompressedLength_ =
uint64_t(1) << std::get<0>(tup);
790 chunkSize_ = size_t(1) << std::get<1>(tup);
794 void runResetStreamTest(
DataHolder const& dh);
795 void runCompressStreamTest(
DataHolder const& dh);
796 void runUncompressStreamTest(
DataHolder const& dh);
808 size_t const pieces = std::max<size_t>(1, data.
size() / chunkSize_);
809 std::vector<ByteRange> result;
810 result.reserve(pieces + 1);
811 while (!data.
empty()) {
812 size_t const pieceSize =
std::min(data.
size(), chunkSize_);
813 result.push_back(data.
subpiece(0, pieceSize));
856 }
while (queue.
tailroom() == 0 && !result);
857 return std::make_pair(result, queue.
move());
861 auto const input = dh.
data(uncompressedLength_);
863 codec_->resetStream(uncompressedLength_);
866 if (
codec_->needsDataLength()) {
867 codec_->resetStream(uncompressedLength_);
873 auto const uncompressed =
codec_->uncompress(compressed.get(), input.size());
884 auto const inputs =
split(dh.
data(uncompressedLength_));
887 codec_->resetStream(uncompressedLength_);
889 for (
auto const input : inputs) {
898 auto const uncompressed =
codec_->uncompress(queue.front());
913 auto compressed =
codec_->compress(
data.get());
914 compressed->prependChain(
codec_->compress(
data.get()));
915 compressed->prependChain(
codec_->compress(
data.get()));
917 auto input = compressed->coalesce();
919 codec_->resetStream(
data->computeChainDataLength());
949 auto const inputs =
split(dh.
data(uncompressedLength_));
952 if (
codec_->needsDataLength()) {
953 codec_->resetStream(uncompressedLength_);
957 for (
auto input : inputs) {
961 auto compressedRange = compressed->coalesce();
973 EXPECT_EQ(input.size(), result.second->computeChainDataLength());
991 testing::Values(0, 1, 12, 22, 27),
992 testing::Values(12, 17, 20),
999 std::vector<CodecType> autoUncompressionCodecTypes = {{
1013 codecType_ = GetParam();
1015 autoType_ = std::any_of(
1016 autoUncompressionCodecTypes.begin(),
1017 autoUncompressionCodecTypes.end(),
1018 [&](
CodecType o) {
return codecType_ == o; });
1027 return (autoType_ ?
nullptr :
getCodec(codecType_));
1038 constexpr
uint64_t uncompressedLength = 1000;
1040 auto compressed =
codec_->compress(original.get());
1042 if (!
codec_->needsUncompressedLength()) {
1043 auto uncompressed = auto_->uncompress(compressed.get());
1044 EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
1048 auto uncompressed = auto_->uncompress(compressed.get(), uncompressedLength);
1049 EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
1052 ASSERT_GE(compressed->computeChainDataLength(), 8);
1053 for (
size_t i = 0;
i < 8; ++
i) {
1054 auto split = compressed->clone();
1055 auto rest = compressed->clone();
1059 auto uncompressed = auto_->uncompress(
split.get(), uncompressedLength);
1060 EXPECT_EQ(uncompressedLength, uncompressed->computeChainDataLength());
1074 const auto prefixes =
codec_->validPrefixes();
1075 for (
const auto&
prefix : prefixes) {
1087 if (
codec_->needsUncompressedLength()) {
1093 EXPECT_LE(
codec_->maxUncompressedLength(), auto_->maxUncompressedLength());
1098 std::vector<std::unique_ptr<Codec>> codecs;
1103 auto compressed =
codec_->compress(original.get());
1104 std::unique_ptr<IOBuf> decompressed;
1106 if (automatic->needsUncompressedLength()) {
1107 decompressed = automatic->uncompress(compressed.get(), length);
1109 decompressed = automatic->uncompress(compressed.get());
1116 class CustomCodec :
public Codec {
1119 return std::make_unique<CustomCodec>(
std::move(prefix),
type);
1127 std::vector<std::string> validPrefixes()
const override {
1131 uint64_t doMaxCompressedLength(
uint64_t uncompressedLength)
const override {
1132 return codec_->maxCompressedLength(uncompressedLength) +
prefix_.size();
1137 if (clone.length() <
prefix_.size()) {
1140 return memcmp(clone.data(),
prefix_.data(),
prefix_.size()) == 0;
1143 std::unique_ptr<IOBuf> doCompress(
const IOBuf* data)
override {
1145 result->appendChain(
codec_->compress(data));
1150 std::unique_ptr<IOBuf> doUncompress(
1153 EXPECT_TRUE(canUncompress(data, uncompressedLength));
1156 return codec_->uncompress(&clone, uncompressedLength);
1167 std::vector<std::unique_ptr<Codec>> codecs;
1173 auto abCompressed = ab->compress(original.get());
1174 std::unique_ptr<IOBuf> abDecompressed;
1175 if (automatic->needsUncompressedLength()) {
1176 abDecompressed = automatic->uncompress(abCompressed.get(), length);
1178 abDecompressed = automatic->uncompress(abCompressed.get());
1180 EXPECT_TRUE(automatic->canUncompress(abCompressed.get()));
1181 EXPECT_FALSE(auto_->canUncompress(abCompressed.get()));
1184 auto compressed =
codec_->compress(original.get());
1185 std::unique_ptr<IOBuf> decompressed;
1186 if (automatic->needsUncompressedLength()) {
1187 decompressed = automatic->uncompress(compressed.get(), length);
1189 decompressed = automatic->uncompress(compressed.get());
1197 std::vector<std::unique_ptr<Codec>> codecs;
1204 auto noneCompressed =
none->compress(original.get());
1205 std::unique_ptr<IOBuf> noneDecompressed;
1206 if (automatic->needsUncompressedLength()) {
1207 noneDecompressed = automatic->uncompress(noneCompressed.get(), length);
1209 noneDecompressed = automatic->uncompress(noneCompressed.get());
1211 EXPECT_TRUE(automatic->canUncompress(noneCompressed.get()));
1212 EXPECT_FALSE(auto_->canUncompress(noneCompressed.get()));
1215 auto compressed =
codec_->compress(original.get());
1216 std::unique_ptr<IOBuf> decompressed;
1217 if (automatic->needsUncompressedLength()) {
1218 decompressed = automatic->uncompress(compressed.get(), length);
1220 decompressed = automatic->uncompress(compressed.get());
1243 class ConstantCodec :
public Codec {
1245 static std::unique_ptr<Codec> create(
1248 return std::make_unique<ConstantCodec>(
std::move(uncompressed),
type);
1254 uint64_t doMaxCompressedLength(
uint64_t uncompressedLength)
const override {
1255 return uncompressedLength;
1258 std::unique_ptr<IOBuf> doCompress(
const IOBuf*)
override {
1259 throw std::runtime_error(
"ConstantCodec error: compress() not supported.");
1268 std::unique_ptr<Codec>
codec_;
1276 codecType_ = GetParam();
1290 auto const compressed =
codec_->compress(original);
1293 auto const uncompressed = auto_->uncompress(compressed);
1297 auto const truncated = compressed.substr(0, compressed.size() - 1);
1298 auto const truncatedBuf =
1300 EXPECT_TRUE(auto_->canUncompress(truncatedBuf.get()));
1306 EXPECT_TRUE(terminal->canUncompress(truncatedBuf.get()));
1307 EXPECT_EQ(terminal->uncompress(truncated),
"dummyString");
1314 {}, ConstantCodec::create(
"dummyString", codecType_));
1316 auto const compressed =
codec_->compress(original);
1317 EXPECT_EQ(terminal->uncompress(compressed),
"dummyString");
1323 testing::ValuesIn(autoUncompressionCodecTypes));
1325 TEST(ValidPrefixesTest, CustomCodec) {
1326 std::vector<std::unique_ptr<Codec>> codecs;
1329 const auto prefixes =
none->validPrefixes();
1330 const auto it = std::find(prefixes.begin(), prefixes.end(),
"none");
1334 #define EXPECT_THROW_IF_DEBUG(statement, expected_exception) \ 1337 EXPECT_THROW((statement), expected_exception); \ 1339 EXPECT_NO_THROW((statement)); \ 1343 TEST(CheckCompatibleTest, SimplePrefixSecond) {
1344 std::vector<std::unique_ptr<Codec>> codecs;
1351 TEST(CheckCompatibleTest, SimplePrefixFirst) {
1352 std::vector<std::unique_ptr<Codec>> codecs;
1360 std::vector<std::unique_ptr<Codec>> codecs;
1366 TEST(CheckCompatibleTest, ZstdPrefix) {
1367 std::vector<std::unique_ptr<Codec>> codecs;
1368 codecs.push_back(CustomCodec::create(
"\x28\xB5\x2F",
CodecType::ZSTD));
1373 TEST(CheckCompatibleTest, ZstdDuplicate) {
1374 std::vector<std::unique_ptr<Codec>> codecs;
1375 codecs.push_back(CustomCodec::create(
"\x28\xB5\x2F\xFD",
CodecType::ZSTD));
1380 TEST(CheckCompatibleTest, ZlibIsPrefix) {
1381 std::vector<std::unique_ptr<Codec>> codecs;
1382 codecs.push_back(CustomCodec::create(
"\x18\x76zzasdf",
CodecType::ZSTD));
1387 #if FOLLY_HAVE_LIBZSTD 1389 TEST(ZstdTest, BackwardCompatible) {
1393 auto compressed =
codec->compress(
data.get());
1394 compressed->coalesce();
1397 ZSTD_getDecompressedSize(compressed->data(), compressed->length()));
1402 auto compressed =
codec->compress(
data.get());
1403 compressed->coalesce();
1406 ZSTD_getDecompressedSize(compressed->data(), compressed->length()));
1410 TEST(ZstdTest, CustomOptions) {
1412 unsigned const wlog = 23;
1413 zstd::Options options(1);
1414 options.set(ZSTD_p_contentSizeFlag, contentSizeFlag);
1415 options.set(ZSTD_p_checksumFlag, 1);
1416 options.set(ZSTD_p_windowLog, wlog);
1418 size_t const uncompressedLength = (size_t)1 << 27;
1420 reinterpret_cast<const char*>(dh.
data(uncompressedLength).
data()),
1421 uncompressedLength);
1422 auto const compressed =
codec->compress(original);
1423 auto const uncompressed =
codec->uncompress(compressed);
1426 codec->getUncompressedLength(
1431 ZSTD_frameHeader zfh;
1432 ZSTD_getFrameHeader(&zfh, compressed.data(), compressed.size());
1434 EXPECT_EQ(zfh.windowSize, 1ULL << wlog);
1436 zfh.frameContentSize,
1437 contentSizeFlag ? uncompressedLength : ZSTD_CONTENTSIZE_UNKNOWN);
1440 for (
unsigned contentSizeFlag = 0; contentSizeFlag <= 1; ++contentSizeFlag) {
1446 TEST(ZstdTest, NegativeLevels) {
1448 EXPECT_EQ(zstd::Options(-1).level(), -1);
1452 auto const plusCompressed =
1454 auto const minusCompressed =
1456 EXPECT_GT(minusCompressed.size(), plusCompressed.size());
1458 auto const uncompressed = codec->uncompress(minusCompressed);
1466 using ZlibFormat = zlib::Options::Format;
1468 TEST(ZlibTest, Auto) {
1469 size_t const uncompressedLength_ = (size_t)1 << 15;
1471 reinterpret_cast<const char*>(
1473 uncompressedLength_);
1474 auto optionCodec =
zlib::getCodec(zlib::Options(ZlibFormat::AUTO));
1479 auto const compressed =
codec->compress(original);
1480 auto const uncompressed = optionCodec->uncompress(compressed);
1487 auto const compressed =
codec->compress(original);
1488 auto const uncompressed = optionCodec->uncompress(compressed);
1493 TEST(ZlibTest, DefaultOptions) {
1494 size_t const uncompressedLength_ = (size_t)1 << 20;
1496 reinterpret_cast<const char*>(
1498 uncompressedLength_);
1502 auto const compressed = optionCodec->compress(original);
1503 auto uncompressed =
codec->uncompress(compressed);
1505 uncompressed = optionCodec->uncompress(compressed);
1512 auto const compressed = optionCodec->compress(original);
1513 auto uncompressed =
codec->uncompress(compressed);
1515 uncompressed = optionCodec->uncompress(compressed);
1520 class ZlibOptionsTest
1521 :
public testing::TestWithParam<std::tuple<ZlibFormat, int, int, int>> {
1523 void SetUp()
override {
1524 auto tup = GetParam();
1525 options_.format = std::get<0>(tup);
1526 options_.windowSize = std::get<1>(tup);
1527 options_.memLevel = std::get<2>(tup);
1528 options_.strategy = std::get<3>(tup);
1532 void runSimpleRoundTripTest(
const DataHolder& dh);
1535 zlib::Options options_;
1536 std::unique_ptr<StreamCodec>
codec_;
1539 void ZlibOptionsTest::runSimpleRoundTripTest(
const DataHolder& dh) {
1540 size_t const uncompressedLength = (size_t)1 << 16;
1542 reinterpret_cast<const char*>(dh.
data(uncompressedLength).
data()),
1543 uncompressedLength);
1545 auto const compressed =
codec_->compress(original);
1546 auto const uncompressed =
codec_->uncompress(compressed);
1550 TEST_P(ZlibOptionsTest, simpleRoundTripTest) {
1564 testing::Values(9, 12, 15),
1565 testing::Values(1, 8, 9),
1573 #endif // FOLLY_HAVE_LIBZ static std::unique_ptr< IOBuf > compressSome(StreamCodec *codec, ByteRange data, uint64_t bufferSize, StreamCodec::FlushOp flush)
#define EXPECT_LE(val1, val2)
#define ASSERT_GE(val1, val2)
#define EXPECT_ANY_THROW(statement)
std::unique_ptr< Codec > codec_
std::vector< uint8_t > buffer(kBufferSize+16)
std::unique_ptr< Codec > auto_
uint64_t fnv64_buf(const void *buf, size_t n, uint64_t hash=FNV_64_HASH_START) noexcept
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
bool hasCodec(CodecType type)
RandomDataHolder randomDataHolder(dataSizeLog2)
#define EXPECT_THROW(statement, expected_exception)
bool uncompressStream(folly::ByteRange &input, folly::MutableByteRange &output, FlushOp flushOp=StreamCodec::FlushOp::NONE)
#define ASSERT_EQ(val1, val2)
static std::unique_ptr< IOBuf > create(std::size_t capacity)
static std::unique_ptr< IOBuf > wrapBuffer(const void *buf, std::size_t capacity)
static bool codecHasFlush(CodecType type)
std::vector< ByteRange > split(ByteRange data) const
void runSimpleTest(const DataHolder &dh)
bool hasStreamCodec(CodecType type)
#define EXPECT_EQ(val1, val2)
std::unordered_map< uint64_t, uint64_t > hashCache_
void runResetStreamTest(DataHolder const &dh)
constexpr size_t kMaxVarintLength64
static uint64_t test(std::string name, bool fc_, bool dedicated_, bool tc_, bool syncops_, uint64_t base)
constexpr detail::Map< Move > move
std::unique_ptr< Codec > codec_
constexpr size_type size() const
auto begin(TestAdlIterable &instance)
INSTANTIATE_TEST_CASE_P(CompressionTest, CompressionTest, testing::Combine(testing::Values(-1, 0, 1, 12, 22, 25, 27), testing::Values(1, 2, 3, 8, 65), testing::ValuesIn(availableCodecs())))
std::unique_ptr< folly::IOBuf > move()
—— Concurrent Priority Queue Implementation ——
std::unique_ptr< Codec > codec_
std::unique_ptr< StreamCodec > codec_
bool prefix(Cursor &c, uint32_t expected)
#define EXPECT_GE(val1, val2)
const uint64_t FNV_64_HASH_START
void split(const Delim &delimiter, const String &input, std::vector< OutputType > &out, bool ignoreEmpty)
uint64_t uncompressedLength_
static std::pair< bool, std::unique_ptr< IOBuf > > uncompressSome(StreamCodec *codec, ByteRange &data, uint64_t bufferSize, StreamCodec::FlushOp flush)
TEST_P(CompressionTest, RandomData)
std::vector< std::thread::id > threads
void runSimpleTest(const DataHolder &dh)
constexpr auto size(C const &c) -> decltype(c.size())
ConstantDataHolder(size_t sizeLog2)
constexpr bool empty() const
#define EXPECT_THROW_IF_DEBUG(statement, expected_exception)
constexpr auto empty(C const &c) -> decltype(c.empty())
uint64_t hashIOBuf(const IOBuf *buf)
void runSimpleStringTest(const DataHolder &dh)
std::unique_ptr< StreamCodec > getStreamCodec(CodecType type, int level)
auto end(TestAdlIterable &instance)
void runUncompressStreamTest(DataHolder const &dh)
constexpr Iter data() const
Range subpiece(size_type first, size_type length=npos) const
constexpr Range< Iter > range(Iter first, Iter last)
std::unique_ptr< IOBuf > split(std::unique_ptr< IOBuf > data) const
void expect(LineReader &lr, const char *expected)
RandomDataHolder(size_t sizeLog2)
std::string uncompressed_
std::size_t computeChainDataLength() const
#define EXPECT_TRUE(condition)
TEST(CompressionTestNeedsUncompressedLength, Simple)
constexpr size_t dataSizeLog2
std::unique_ptr< Codec > auto_
static std::vector< CodecType > availableCodecs()
void uncheckedAdvance(size_type n)
bool compressStream(folly::ByteRange &input, folly::MutableByteRange &output, FlushOp flushOp=StreamCodec::FlushOp::NONE)
std::unique_ptr< uint8_t[]> data_
void runSimpleTest(const DataHolder &dh)
Range< const unsigned char * > ByteRange
uint64_t uncompressedLength_
static std::vector< CodecType > availableStreamCodecs()
std::unique_ptr< Codec > getTerminalCodec()
void runSimpleIOBufTest(const DataHolder &dh)
ConstantDataHolder constantDataHolder(dataSizeLog2)
void trimStart(std::size_t amount)
std::unique_ptr< StreamCodec > codec_
IOBuf cloneCoalescedAsValue() const
#define EXPECT_FALSE(condition)
static std::vector< CodecType > supportedCodecs(std::vector< CodecType > const &v)
void runCompressStreamTest(DataHolder const &dh)
std::unique_ptr< Codec > getAutoUncompressionCodec(std::vector< std::unique_ptr< Codec >> customCodecs, std::unique_ptr< Codec > terminalCodec)
ByteRange data(size_t size) const
static std::unique_ptr< IOBuf > copyBuffer(const void *buf, std::size_t size, std::size_t headroom=0, std::size_t minTailroom=0)
uint64_t uncompressedLength_
#define ASSERT_TRUE(condition)
uint64_t oneBasedMsbPos(uint64_t number)
std::unique_ptr< Codec > getCodec(CodecType type, int level)
uint64_t hash(size_t size) const
uint32_t randomNumberSeed()
void runFlushTest(DataHolder const &dh)
std::unique_ptr< Codec > codec_
std::unique_ptr< Codec > codec_
std::unique_ptr< Codec > codec_
#define EXPECT_GT(val1, val2)
DataHolder(size_t sizeLog2)