util.hpp
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014-2020, The University of Memphis
4  *
5  * This file is part of PSync.
6  * See AUTHORS.md for complete list of PSync authors and contributors.
7  *
8  * PSync is free software: you can redistribute it and/or modify it under the terms
9  * of the GNU Lesser General Public License as published by the Free Software Foundation,
10  * either version 3 of the License, or (at your option) any later version.
11  *
12  * PSync is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  * PURPOSE. See the GNU Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public License along with
17  * PSync, e.g., in COPYING.md file. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * murmurHash3 was written by Austin Appleby, and is placed in the public
20  * domain. The author hereby disclaims copyright to this source code.
21  * https://github.com/aappleby/smhasher/blob/master/src/murmurHash3.cpp
22  **/
23 
24 #ifndef PSYNC_UTIL_HPP
25 #define PSYNC_UTIL_HPP
26 
27 #include <ndn-cxx/name.hpp>
28 
29 #include <inttypes.h>
30 #include <vector>
31 #include <string>
32 
33 namespace psync {
34 
35 uint32_t
36 murmurHash3(uint32_t nHashSeed, const std::vector<unsigned char>& vDataToHash);
37 
38 uint32_t
39 murmurHash3(uint32_t nHashSeed, const std::string& str);
40 
41 uint32_t
42 murmurHash3(uint32_t nHashSeed, uint32_t value);
43 
45 {
46  ndn::Name prefix;
47  uint64_t lowSeq;
48  uint64_t highSeq;
49 };
50 
51 enum class CompressionScheme {
52  NONE,
53  ZLIB,
54  GZIP,
55  BZIP2,
56  LZMA,
57  ZSTD
58 };
59 
60 std::shared_ptr<ndn::Buffer>
61 compress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize);
62 
63 std::shared_ptr<ndn::Buffer>
64 decompress(CompressionScheme scheme, const uint8_t* buffer, size_t bufferSize);
65 
66 class Error : public std::runtime_error
67 {
68 public:
69  using std::runtime_error::runtime_error;
70 };
71 
72 } // namespace psync
73 
74 #endif // PSYNC_UTIL_HPP
ndn::Name prefix
Definition: util.hpp:46
uint32_t murmurHash3(uint32_t nHashSeed, const std::vector< unsigned char > &vDataToHash)
Definition: util.cpp:61
std::shared_ptr< ndn::Buffer > decompress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
Definition: util.cpp:187
CompressionScheme
Definition: util.hpp:51
std::shared_ptr< ndn::Buffer > compress(CompressionScheme scheme, const uint8_t *buffer, size_t bufferSize)
Definition: util.cpp:132
uint64_t highSeq
Definition: util.hpp:48