grpc-dlang
所属分类:collect
开发工具:D
文件大小:0KB
下载次数:0
上传日期:2022-03-12 05:22:40
上 传 者:
sh-1993
说明: Grpc for D编程语言,基于hunt http库。,
(Grpc for D programming language, hunt-http library based.,)
文件列表:
LICENSE (11357, 2022-03-08)
compiler/ (0, 2022-03-08)
compiler/CMakeLists.txt (814, 2022-03-08)
compiler/deps/ (0, 2022-03-08)
compiler/deps/protobuf/ (0, 2022-03-08)
compiler/src/ (0, 2022-03-08)
compiler/src/config.h (2877, 2022-03-08)
compiler/src/config_protobuf.h (3491, 2022-03-08)
compiler/src/dlang_plugin.cc (8064, 2022-03-08)
compiler/src/generator_helpers.h (8596, 2022-03-08)
dub.json (309, 2022-03-08)
examples/ (0, 2022-03-08)
examples/RouteGuideDemo/ (0, 2022-03-08)
examples/RouteGuideDemo/dub.json (254, 2022-03-08)
examples/RouteGuideDemo/proto/ (0, 2022-03-08)
examples/RouteGuideDemo/proto/generate.sh (207, 2022-03-08)
examples/RouteGuideDemo/proto/route_guide.proto (3489, 2022-03-08)
examples/RouteGuideDemo/route_guide_db.json (13768, 2022-03-08)
examples/RouteGuideDemo/source/ (0, 2022-03-08)
examples/RouteGuideDemo/source/app.d (9415, 2022-03-08)
examples/RouteGuideDemo/source/routeguide/ (0, 2022-03-08)
examples/RouteGuideDemo/source/routeguide/route_guide.d (924, 2022-03-08)
examples/RouteGuideDemo/source/routeguide/route_guiderpc.d (1650, 2022-03-08)
examples/SimpleDemo/ (0, 2022-03-08)
examples/SimpleDemo/Makefile (857, 2022-03-08)
examples/SimpleDemo/dub.json (550, 2022-03-08)
examples/SimpleDemo/proto/ (0, 2022-03-08)
examples/SimpleDemo/proto/helloworld.proto (1212, 2022-03-08)
examples/SimpleDemo/python/ (0, 2022-03-08)
examples/SimpleDemo/python/Makefile (89, 2022-03-08)
examples/SimpleDemo/python/client.py (315, 2022-03-08)
examples/SimpleDemo/python/server.py (681, 2022-03-08)
... ...
# grpc-dlang
gRPC implementation for D.
### Building
### Building the protocol buffer compiler for D
```sh
$ git clone https://github.com/dcarp/protobuf-d
$ cd protobuf-d
$ dub build :protoc-gen-d
$ sudo cp build/protoc-gen-d /usr/local/bin
```
### Building the gRPC plugin for D
```sh
$ git submodule update --init --recursive
# Update Git submodule to latest commit on origin
# git submodule update --remote --merge
$ cd compiler
$ mkdir build
$ cd build
$ cmake ..
$ make -j4
$ sudo cp deps/protobuf/protoc* /usr/local/bin
$ sudo cp grpc_dlang_plugin /usr/local/bin
```
### Building the core library
```sh
cd grpc-dlang
dub build
```
### Generating protobuf code
```sh
protoc --plugin=/usr/local/bin/protoc-gen-d --d_out=./examples -I ./examples ./examples/helloworld.proto
```
### Generating grpc client and server code
```sh
protoc --plugin=protoc-gen-grpc=/usr/local/bin/grpc_dlang_plugin -I ./examples --grpc_out=./examples ./examples/helloworld.proto
```
### Building the examples
1. A simple demo
```shell
$ cd examples/SimpleDemo/proto/
$ ./generate.sh
$ cd ..
$ ./build.sh
```
2. Demo for streaming
```sh
dub build -c=streamexample
./streamexample -f ./examples/route_guide_db.json
```
## Samples
### The server
```D
import grpc;
import helloworld.helloworld;
import helloworld.helloworldrpc;
class GreeterImpl : GreeterBase
{
override Status SayHello(HelloRequest request , ref HelloReply reply)
{
reply.message = "hello " ~ request.name;
return Status.OK;
}
}
string host = "0.0.0.0";
ushort port = 50051;
auto server = new Server();
server.listen(host , port);
server.register( new GreeterImpl());
server.start();
```
### The client
```D
import helloworld.helloworld;
import helloworld.helloworldrpc;
import grpc;
import std.stdio;
auto channel = new Channel("127.0.0.1" , 50051);
GreeterClient client = new GreeterClient(channel);
auto request = new HelloRequest();
request.name = "test";
HelloReply reply = client.SayHello(request);
if(reply !is null)
{
writeln(reply.message);
}
```
### The streaming
We implemented the offical example [RouteGuide](https://github.com/huntlabs/grpc-dlang/tree/master/examples/RouteGuideDemo).
## Resources
- [cpp quickstart](https://grpc.io/docs/languages/cpp/quickstart/).
近期下载者:
相关文件:
收藏者: