23 #include <msgpack.hpp> 40 using NetId = uint32_t;
41 using want_t = int_fast8_t;
45 using Sp = std::shared_ptr<T>;
47 template <
typename Key,
typename Item,
typename Condition>
48 void erase_if(std::map<Key, Item>& map,
const Condition& condition)
50 for (
auto it = map.begin(); it != map.end(); ) {
60 OPENDHT_PUBLIC std::pair<std::string, std::string>
66 std::runtime_error(
"DhtException occurred: " + str) {}
77 using clock = std::chrono::steady_clock;
78 using time_point = clock::time_point;
79 using duration = clock::duration;
81 time_point from_time_t(std::time_t t);
82 std::time_t to_time_t(time_point t);
90 return std::chrono::duration_cast<std::chrono::duration<double>>(d).count();
93 template <
typename Duration = duration>
95 using Base = std::uniform_int_distribution<typename Duration::rep>;
96 using param_type =
typename Base::param_type;
99 template <
class Generator>
100 Duration operator()(Generator && g) {
101 return Duration(Base::operator()(g));
103 template<
class Generator >
104 Duration operator()( Generator && g,
const param_type& params ) {
105 return Duration(Base::operator()(g, params));
114 using Blob = std::vector<uint8_t>;
121 template <
typename Type>
123 packMsg(
const Type& t) {
124 msgpack::sbuffer buffer;
125 msgpack::packer<msgpack::sbuffer> pk(&buffer);
127 return {buffer.data(), buffer.data()+buffer.size()};
130 template <
typename Type>
133 msgpack::unpacked msg_res = msgpack::unpack((
const char*)b.data(), b.size());
134 return msg_res.get().as<Type>();
137 msgpack::unpacked unpackMsg(
Blob b);
139 msgpack::object* findMapValue(msgpack::object& map,
const std::string& key);
static double print_dt(DT d)
std::vector< uint8_t > Blob
OPENDHT_PUBLIC Blob unpackBlob(msgpack::object &o)
OPENDHT_PUBLIC std::pair< std::string, std::string > splitPort(const std::string &s)