-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutil.h
More file actions
35 lines (34 loc) · 681 Bytes
/
util.h
File metadata and controls
35 lines (34 loc) · 681 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#ifndef UTIL_H
#define UTIL_H
#include <stdint.h>
#include <cstddef>
#include <msgpack.hpp>
#include <assert.h>
#include <stdio.h>
namespace msgskip{
namespace misc{
template <typename T>
std::size_t estimate_packed_size(const T& t){
assert(&t != NULL);
// printf("ptr:%p\n",&t);
msgpack::sbuffer sb;
msgpack::pack(sb,t);
return sb.size();
}
template <typename type>
std::size_t pack_it(void* b, const type* const v){
if(v){
msgpack::sbuffer sb;
msgpack::pack(sb, *v);
memcpy(b, sb.data(), sb.size());
return sb.size();
}else{
msgpack::sbuffer sb;
msgpack::pack(sb, NULL);
memcpy(b, sb.data(), sb.size());
return sb.size();
}
}
}// misc
}// msgskip
#endif