Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ironsdu/drpc
泛型是什么?
https://github.com/ironsdu/drpc
rpc
Last synced: 7 days ago
JSON representation
泛型是什么?
- Host: GitHub
- URL: https://github.com/ironsdu/drpc
- Owner: IronsDu
- License: mit
- Created: 2017-07-28T05:58:21.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2023-02-14T13:39:32.000Z (almost 2 years ago)
- Last Synced: 2024-11-28T14:44:25.277Z (2 months ago)
- Topics: rpc
- Language: C++
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 2
- Forks: 1
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DRPC
DRPC是一个C++ 智能RPC库,开发者只需要通过简单的接口定义服务名称以及服务实现函数,调用者直接使用参数进行调用,无需考虑封包和解包。
## 例子
使用本地进程内进行模拟测试(可以很简单的通过网络库发送请求即可跨机器使用此RPC库)
```
#include#include "RpcService.h"
#include "JsonRpc.h"
#include "MsgpackRpc.h"using namespace std;
using namespace dodo::rpc;int main()
{
RpcService rpc;// 无论实参如何,call 总是返回 std::tuple>
// 前者表示参数pack的json字符串,后者如果不为nullptr则表示回调函数(接收string,即可执行)auto fuck1 = rpc.call(1, 2, "hehe", [](const std::string& value, int a) {
cout << "receive " << value << endl;
});
auto fuck2 = rpc.call("haha", 10);// def 函数则直接返回一个包装函数 std::function,跟 call函数返回的tuple第二个值完全同类.
auto service = rpc.def([](const std::string& value, int a) {
cout << "receive " << value << endl;
});// 向 service 传递一个string,即可调用回调
service(std::get<0>(fuck2));
std::get<1>(fuck1)(std::get<0>(fuck2));return 0;
}
```