-
Notifications
You must be signed in to change notification settings - Fork 571
/
KQuery_serialization.h
79 lines (66 loc) · 2.46 KB
/
KQuery_serialization.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
/*
* KQuery.h
*
* Created on: 2013-5-1
* Author: fasiondog
*/
#pragma once
#ifndef SERIALIZATION_KQUERY_H_
#define SERIALIZATION_KQUERY_H_
#include "../KQuery.h"
#include "../config.h"
#if HKU_SUPPORT_SERIALIZATION
namespace boost {
namespace serialization {
template <class Archive>
void save(Archive& ar, const hku::KQuery& query, unsigned int version) {
hku::string queryType, kType, recoverType;
queryType = hku::KQuery::getQueryTypeName(query.queryType());
kType = hku::KQuery::getKTypeName(query.kType());
recoverType = hku::KQuery::getRecoverTypeName(query.recoverType());
ar& BOOST_SERIALIZATION_NVP(queryType);
ar& BOOST_SERIALIZATION_NVP(kType);
ar& BOOST_SERIALIZATION_NVP(recoverType);
if (query.queryType() == hku::KQuery::INDEX) {
hku::int64_t start = query.start();
hku::int64_t end = query.end();
ar& BOOST_SERIALIZATION_NVP(start);
ar& BOOST_SERIALIZATION_NVP(end);
} else if (query.queryType() == hku::KQuery::DATE) {
hku::uint64_t start = query.startDatetime().number();
hku::uint64_t end = query.endDatetime().number();
ar& BOOST_SERIALIZATION_NVP(start);
ar& BOOST_SERIALIZATION_NVP(end);
} else {
// 非法忽略
}
}
template <class Archive>
void load(Archive& ar, hku::KQuery& query, unsigned int version) {
hku::string queryType, kType, recoverType;
ar& BOOST_SERIALIZATION_NVP(queryType);
ar& BOOST_SERIALIZATION_NVP(kType);
ar& BOOST_SERIALIZATION_NVP(recoverType);
hku::KQuery::QueryType enum_query = hku::KQuery::getQueryTypeEnum(queryType);
hku::KQuery::KType enmu_ktype = hku::KQuery::getKTypeEnum(kType);
hku::KQuery::RecoverType enum_recover = hku::KQuery::getRecoverTypeEnum(recoverType);
if (enum_query == hku::KQuery::INDEX) {
hku::int64_t start, end;
ar& BOOST_SERIALIZATION_NVP(start);
ar& BOOST_SERIALIZATION_NVP(end);
query = hku::KQuery(start, end, enmu_ktype, enum_recover);
} else if (enum_query == hku::KQuery::DATE) {
hku::uint64_t start, end;
ar& BOOST_SERIALIZATION_NVP(start);
ar& BOOST_SERIALIZATION_NVP(end);
query =
hku::KQueryByDate(hku::Datetime(start), hku::Datetime(end), enmu_ktype, enum_recover);
} else {
// 非法忽略
}
}
} // namespace serialization
} // namespace boost
BOOST_SERIALIZATION_SPLIT_FREE(hku::KQuery)
#endif /* HKU_SUPPORT_SERIALIZATION */
#endif /* SERIALIZATION_KQUERY_H_ */