Giter Club home page Giter Club logo

grpc-dlang's Introduction

grpc-dlang

gRPC implementation for D.

Building

Building the protocol buffer compiler for D

$ 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

$ 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

cd grpc-dlang
dub build

Generating protobuf code

protoc --plugin=/usr/local/bin/protoc-gen-d --d_out=./examples -I ./examples ./examples/helloworld.proto

Generating grpc client and server code

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
$ cd examples/SimpleDemo/proto/
$ ./generate.sh
$ cd ..
$ ./build.sh 
  1. Demo for streaming
dub build -c=streamexample
./streamexample -f ./examples/route_guide_db.json

Samples

The server

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

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.

Resources

grpc-dlang's People

Contributors

aravindavk avatar gaoxincheng avatar heromyth avatar kubo39 avatar mw66 avatar xiaoshuaisen avatar zhangyuchun avatar zoujiaqing avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.