26 #include <ndn-cxx/encoding/buffer-stream.hpp> 27 #include <ndn-cxx/util/backports.hpp> 28 #include <ndn-cxx/util/exception.hpp> 30 #include <boost/iostreams/copy.hpp> 31 #include <boost/iostreams/device/array.hpp> 32 #include <boost/iostreams/filtering_stream.hpp> 33 #ifdef PSYNC_HAVE_ZLIB 34 #include <boost/iostreams/filter/zlib.hpp> 36 #ifdef PSYNC_HAVE_GZIP 37 #include <boost/iostreams/filter/gzip.hpp> 39 #ifdef PSYNC_HAVE_BZIP2 40 #include <boost/iostreams/filter/bzip2.hpp> 42 #ifdef PSYNC_HAVE_LZMA 43 #include <boost/iostreams/filter/lzma.hpp> 45 #ifdef PSYNC_HAVE_ZSTD 46 #include <boost/iostreams/filter/zstd.hpp> 52 namespace bio = boost::iostreams;
54 static inline uint32_t
57 return (x << r) | (x >> (32 - r));
63 const uint8_t * data = (
const uint8_t*)key;
64 const int nblocks = len / 4;
68 const uint32_t c1 = 0xcc9e2d51;
69 const uint32_t c2 = 0x1b873593;
74 const uint32_t * blocks = (
const uint32_t *)(data + nblocks*4);
76 for (
int i = -nblocks; i; i++)
78 uint32_t k1 = blocks[i];
92 const uint8_t * tail = (
const uint8_t*)(data + nblocks*4);
98 case 3: k1 ^= tail[2] << 16;
100 case 2: k1 ^= tail[1] << 8;
102 case 1: k1 ^= tail[0];
103 k1 *= c1; k1 =
ROTL32(k1,15); k1 *= c2; h1 ^= k1;
119 std::shared_ptr<ndn::Buffer>
122 ndn::OBufferStream out;
123 bio::filtering_streambuf<bio::input> in;
127 #ifdef PSYNC_HAVE_ZLIB 128 in.push(bio::zlib_compressor(bio::zlib::best_compression));
135 #ifdef PSYNC_HAVE_GZIP 136 in.push(bio::gzip_compressor(bio::gzip::best_compression));
143 #ifdef PSYNC_HAVE_BZIP2 144 in.push(bio::bzip2_compressor());
151 #ifdef PSYNC_HAVE_LZMA 152 in.push(bio::lzma_compressor(bio::lzma::best_compression));
159 #ifdef PSYNC_HAVE_ZSTD 160 in.push(bio::zstd_compressor(bio::zstd::best_compression));
169 in.push(bio::array_source(reinterpret_cast<const char*>(buffer), bufferSize));
175 std::shared_ptr<ndn::Buffer>
178 ndn::OBufferStream out;
179 bio::filtering_streambuf<bio::input> in;
183 #ifdef PSYNC_HAVE_ZLIB 184 in.push(bio::zlib_decompressor());
191 #ifdef PSYNC_HAVE_GZIP 192 in.push(bio::gzip_decompressor());
199 #ifdef PSYNC_HAVE_BZIP2 200 in.push(bio::bzip2_decompressor());
207 #ifdef PSYNC_HAVE_LZMA 208 in.push(bio::lzma_decompressor());
215 #ifdef PSYNC_HAVE_ZSTD 216 in.push(bio::zstd_decompressor());
225 in.push(bio::array_source(reinterpret_cast<const char*>(buffer), bufferSize));
std::shared_ptr< ndn::Buffer > decompress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
static uint32_t ROTL32(uint32_t x, int8_t r)
std::shared_ptr< ndn::Buffer > compress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
uint32_t murmurHash3(const void *key, size_t len, uint32_t seed)