Files
rest_rpc/main.cpp
T

51 lines
1.0 KiB
C++
Raw Normal View History

2018-12-20 12:20:12 +08:00
#include "rpc_server.h"
using namespace rest_rpc;
using namespace rpc_service;
struct dummy{
int add(connection* conn, int a, int b) { return a + b; }
};
std::string translate(connection* conn, const std::string& orignal) {
std::string temp = orignal;
for (auto& c : temp) {
c = std::toupper(c);
}
return temp;
}
void hello(connection* conn, const std::string& str) {
std::cout << "hello " << str << std::endl;
}
2019-01-09 15:08:25 +08:00
struct person {
int id;
std::string name;
int age;
MSGPACK_DEFINE(id, name, age);
};
std::string get_person_name(connection* conn, const person& p) {
return p.name;
}
2019-01-10 06:03:42 +08:00
person get_person(connection* conn) {
return { 1, "tom", 20 };
}
2018-12-20 12:20:12 +08:00
int main() {
rpc_server server(9000, 4);
dummy d;
server.register_handler("add", &dummy::add, &d);
server.register_handler("translate", translate);
server.register_handler("hello", hello);
2019-01-09 15:08:25 +08:00
server.register_handler("get_person_name", get_person_name);
2019-01-10 06:03:42 +08:00
server.register_handler("get_person", get_person);
2018-12-20 12:20:12 +08:00
server.run();
std::string str;
std::cin >> str;
}