-
Notifications
You must be signed in to change notification settings - Fork 71
/
read_kind_sample.cpp
executable file
·68 lines (55 loc) · 2.36 KB
/
read_kind_sample.cpp
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
#include <cstdio>
#include <iostream>
#include <fstream>
#include "kind.pb.h"
#include "libresloader.h"
int main(int argc, char* argv[]) {
const char* file_path = "../role_cfg.bin";
if (argc > 1) {
file_path = argv[1];
} else {
printf("usage: %s <path to role_cfg.bin>\n");
return 1;
}
// key - value
do {
typedef xresloader::conf_manager_kv<role_cfg, uint32_t> kind_upg_cfg_t;
kind_upg_cfg_t upg_mgr;
upg_mgr.set_key_handle([](kind_upg_cfg_t::value_type p) {
return std::make_tuple<uint32_t>(p->id());
});
upg_mgr.load_file(file_path);
kind_upg_cfg_t::value_type data1 = upg_mgr.get(10002);
if (NULL == data1) {
std::cerr<< "role id: 10002 not found, load file "<< file_path<< " failed."<< std::endl;
break;
}
if (data1->has_dep_test()) {
printf("role id: %u, unlock level: %u, name %s, dep_test.name: %s\n", data1->id(), data1->unlock_level(), data1->name().c_str(), data1->dep_test().name().c_str());
} else {
printf("role id: %u, unlock level: %u, name %s, dep_test.name: NONE\n", data1->id(), data1->unlock_level(), data1->name().c_str());
}
printf("%s\n", data1->DebugString().c_str());
} while(false);
// key - list
do {
typedef xresloader::conf_manager_kl<role_cfg, uint32_t> kind_upg_cfg_t;
kind_upg_cfg_t upg_mgr;
upg_mgr.set_key_handle([](kind_upg_cfg_t::value_type p) {
return std::make_tuple<uint32_t>(p->id());
});
upg_mgr.load_file(file_path);
kind_upg_cfg_t::value_type data1 = upg_mgr.get(10003, 0);
if (NULL == data1) {
std::cerr<< "role id: 10003 not found, load file "<< file_path<< " failed."<< std::endl;
break;
}
if (data1->has_dep_test()) {
printf("role id: %u, unlock level: %u, name %s, dep_test.name: %s\n", data1->id(), data1->unlock_level(), data1->name().c_str(), data1->dep_test().name().c_str());
} else {
printf("role id: %u, unlock level: %u, name %s, dep_test.name: NONE\n", data1->id(), data1->unlock_level(), data1->name().c_str());
}
printf("%s\n", data1->DebugString().c_str());
} while(false);
return 0;
}