forked from mambaru/mysql-tarantool-replication
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathserializable.h
87 lines (73 loc) · 1.92 KB
/
serializable.h
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#ifndef REPLICATOR_SERIALIZABLE_H
#define REPLICATOR_SERIALIZABLE_H
#include <string>
#include <map>
#include <sstream>
#include <memory>
#include <boost/any.hpp>
namespace replicator {
class SerializableValue {
private:
boost::any value;
public:
template<typename T>
inline SerializableValue& operator= (T&& value_) {
value = boost::any(std::forward<T>(value_));
return *this;
}
inline SerializableValue& operator= (boost::any&& value_) {
value = std::forward<boost::any>(value_);
return *this;
}
template<typename T> inline bool is() const {
return value.type() == typeid(T);
}
template<typename T> inline T as() const {
return boost::any_cast<T>(value);
}
std::string to_string() const {
std::ostringstream s;
if (is<std::string()>()) {
s << as<std::string>();
} else if (is<char>()) {
s << as<char>();
} else if (is<unsigned char>()) {
s << as<unsigned char>();
} else if (is<short>()) {
s << as<short>();
} else if (is<unsigned short>()) {
s << as<unsigned short>();
} else if (is<int>()) {
s << as<int>();
} else if (is<unsigned int>()) {
s << as<unsigned int>();
} else if (is<long>()) {
s << as<long>();
} else if (is<unsigned long>()) {
s << as<unsigned long>();
} else if (is<long long>()) {
s << as<long long>();
} else if (is<unsigned long long>()) {
s << as<unsigned long long>();
} else if (is<float>()) {
s << as<float>();
} else if (is<double>()) {
s << as<double>();
}
return s.str();
}
};
struct SerializableBinlogEvent
{
std::string binlog_name;
unsigned long binlog_pos;
// unsigned long seconds_behind_master;
// unsigned long unix_timestamp;
std::string database;
std::string table;
std::string event;
std::map<unsigned, SerializableValue> row;
};
typedef std::unique_ptr<SerializableBinlogEvent> SerializableBinlogEventPtr;
} // replicator
#endif // REPLICATOR_SERIALIZABLE_H