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>
51 static inline uint32_t
52 ROTL32(uint32_t x, int8_t r)
54 return (x << r) | (x >> (32 - r));
60 const uint8_t * data = (
const uint8_t*)key;
61 const int nblocks = len / 4;
65 const uint32_t c1 = 0xcc9e2d51;
66 const uint32_t c2 = 0x1b873593;
71 const uint32_t * blocks = (
const uint32_t *)(data + nblocks*4);
73 for (
int i = -nblocks; i; i++)
75 uint32_t k1 = blocks[i];
89 const uint8_t * tail = (
const uint8_t*)(data + nblocks*4);
95 case 3: k1 ^= tail[2] << 16;
97 case 2: k1 ^= tail[1] << 8;
99 case 1: k1 ^= tail[0];
100 k1 *= c1; k1 = ROTL32(k1,15); k1 *= c2; h1 ^= k1;
119 const auto& wire = name.wireEncode();
120 return murmurHash3(wire.value(), wire.value_size(), seed);
123 std::shared_ptr<ndn::Buffer>
126 namespace bio = boost::iostreams;
128 bio::filtering_istreambuf in;
135 #ifdef PSYNC_HAVE_ZLIB
136 in.push(bio::zlib_compressor(bio::zlib::best_compression));
143 #ifdef PSYNC_HAVE_GZIP
144 in.push(bio::gzip_compressor(bio::gzip::best_compression));
151 #ifdef PSYNC_HAVE_BZIP2
152 in.push(bio::bzip2_compressor());
159 #ifdef PSYNC_HAVE_LZMA
160 in.push(bio::lzma_compressor(bio::lzma::best_compression));
167 #ifdef PSYNC_HAVE_ZSTD
168 in.push(bio::zstd_compressor(bio::zstd::best_compression));
175 in.push(bio::array_source(
reinterpret_cast<const char*
>(buffer.data()), buffer.size()));
176 ndn::OBufferStream out;
182 std::shared_ptr<ndn::Buffer>
185 namespace bio = boost::iostreams;
187 bio::filtering_istreambuf in;
194 #ifdef PSYNC_HAVE_ZLIB
195 in.push(bio::zlib_decompressor());
202 #ifdef PSYNC_HAVE_GZIP
203 in.push(bio::gzip_decompressor());
210 #ifdef PSYNC_HAVE_BZIP2
211 in.push(bio::bzip2_decompressor());
218 #ifdef PSYNC_HAVE_LZMA
219 in.push(bio::lzma_decompressor());
226 #ifdef PSYNC_HAVE_ZSTD
227 in.push(bio::zstd_decompressor());
234 in.push(bio::array_source(
reinterpret_cast<const char*
>(buffer.data()), buffer.size()));
235 ndn::OBufferStream out;
uint32_t murmurHash3(const void *key, size_t len, uint32_t seed)
std::shared_ptr< ndn::Buffer > compress(CompressionScheme scheme, ndn::span< const uint8_t > buffer)
std::shared_ptr< ndn::Buffer > decompress(CompressionScheme scheme, ndn::span< const uint8_t > buffer)