int decompress(bufferlist::iterator &p,
size_t compressed_len,
bufferlist &dst) override {
- size_t res_len = 0;
- // Trick, decompress only need first few bytes of buffer. note
- // that 4 bytes is *not* enough.. it works for small buffers (a
- // few MB), but not large ones (~260 MB), because the 32-bit value
- // is encoded as a varint. From snappy.cc:
- // if (Varint::Parse32WithLimit(start, limit, &v) != NULL) {
- // 8 bytes is enough.
- bufferlist::const_iterator ptmp = p;
- bufferlist tmp;
- ptmp.copy(std::min(8lu, compressed_len), tmp);
- if (!snappy::GetUncompressedLength(tmp.c_str(), tmp.length(), &res_len)) {
+ snappy::uint32 res_len = 0;
+ BufferlistSource source_1(p, compressed_len);
+ if (!snappy::GetUncompressedLength(&source_1, &res_len)) {
return -1;
}
- BufferlistSource source(p, compressed_len);
+ BufferlistSource source_2(p, compressed_len);
bufferptr ptr(res_len);
- if (snappy::RawUncompress(&source, ptr.c_str())) {
- p = source.get_pos();
+ if (snappy::RawUncompress(&source_2, ptr.c_str())) {
+ p = source_2.get_pos();
dst.append(ptr);
return 0;
}