25 #include "PSync/detail/config.hpp" 27 #include <ndn-cxx/encoding/buffer-stream.hpp> 28 #include <ndn-cxx/util/backports.hpp> 29 #include <ndn-cxx/util/exception.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> 48 #include <boost/iostreams/copy.hpp> 52 namespace bio = boost::iostreams;
57 return (x << r) | (x >> (32 - r));
61 murmurHash3(uint32_t nHashSeed,
const std::vector<unsigned char>& vDataToHash)
63 uint32_t h1 = nHashSeed;
64 const uint32_t c1 = 0xcc9e2d51;
65 const uint32_t c2 = 0x1b873593;
67 const size_t nblocks = vDataToHash.size() / 4;
71 const uint32_t * blocks = (
const uint32_t *)(&vDataToHash[0] + nblocks*4);
73 for (
size_t i = -nblocks; i; i++) {
74 uint32_t k1 = blocks[i];
87 const uint8_t * tail = (
const uint8_t*)(&vDataToHash[0] + nblocks*4);
91 switch (vDataToHash.size() & 3) {
102 k1 *= c1; k1 =
ROTL32(k1,15); k1 *= c2; h1 ^= k1;
107 h1 ^= vDataToHash.size();
120 return murmurHash3(nHashSeed, std::vector<unsigned char>(str.begin(), str.end()));
127 std::vector<unsigned char>((
unsigned char*)&value,
128 (
unsigned char*)&value +
sizeof(uint32_t)));
131 std::shared_ptr<ndn::Buffer>
134 ndn::OBufferStream out;
135 bio::filtering_streambuf<bio::input> in;
138 #ifdef PSYNC_HAVE_ZLIB 139 in.push(bio::zlib_compressor(bio::zlib::best_compression));
141 NDN_THROW(
Error(
"ZLIB compression not supported!"));
146 #ifdef PSYNC_HAVE_GZIP 147 in.push(bio::gzip_compressor(bio::gzip::best_compression));
149 NDN_THROW(
Error(
"GZIP compression not supported!"));
154 #ifdef PSYNC_HAVE_BZIP2 155 in.push(bio::bzip2_compressor());
157 NDN_THROW(
Error(
"BZIP2 compression not supported!"));
162 #ifdef PSYNC_HAVE_LZMA 163 in.push(bio::lzma_compressor(bio::lzma::best_compression));
165 NDN_THROW(
Error(
"LZMA compression not supported!"));
170 #ifdef PSYNC_HAVE_ZSTD 171 in.push(bio::zstd_compressor(bio::zstd::best_compression));
173 NDN_THROW(
Error(
"ZSTD compression not supported!"));
180 in.push(bio::array_source(reinterpret_cast<const char*>(buffer), bufferSize));
186 std::shared_ptr<ndn::Buffer>
189 ndn::OBufferStream out;
190 bio::filtering_streambuf<bio::input> in;
193 #ifdef PSYNC_HAVE_ZLIB 194 in.push(bio::zlib_decompressor());
196 NDN_THROW(
Error(
"ZLIB decompression not supported!"));
201 #ifdef PSYNC_HAVE_GZIP 202 in.push(bio::gzip_decompressor());
204 NDN_THROW(
Error(
"GZIP compression not supported!"));
209 #ifdef PSYNC_HAVE_BZIP2 210 in.push(bio::bzip2_decompressor());
212 NDN_THROW(
Error(
"BZIP2 compression not supported!"));
217 #ifdef PSYNC_HAVE_LZMA 218 in.push(bio::lzma_decompressor());
220 NDN_THROW(
Error(
"LZMA compression not supported!"));
225 #ifdef PSYNC_HAVE_ZSTD 226 in.push(bio::zstd_decompressor());
228 NDN_THROW(
Error(
"ZSTD compression not supported!"));
235 in.push(bio::array_source(reinterpret_cast<const char*>(buffer), bufferSize));
uint32_t murmurHash3(uint32_t nHashSeed, const std::vector< unsigned char > &vDataToHash)
std::shared_ptr< ndn::Buffer > decompress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
std::shared_ptr< ndn::Buffer > compress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
static uint32_t ROTL32(uint32_t x, int8_t r)