Skip to content

Commit

Permalink
Use code type highlight for the code blocks in the cpp helloworld
Browse files Browse the repository at this point in the history
example README.md

..
  • Loading branch information
jeady committed Dec 15, 2015
1 parent 5c8c3e7 commit 2e9ce91
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions examples/cpp/helloworld/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ message from the remote client containing the user's name, then send back
a greeting in a single `HelloReply`. This is the simplest type of RPC you
can specify in gRPC - we'll look at some other types later in this document.

```
```protobuf
syntax = "proto3";
option java_package = "ex.grpc";
Expand Down Expand Up @@ -93,20 +93,20 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto
channel can be created with the target address, credentials to use and
arguments as follows

```
```cpp
auto channel = CreateChannel("localhost:50051", InsecureChannelCredentials());
```

- Create a stub. A stub implements the rpc methods of a service and in the
generated code, a method is provided to created a stub with a channel:

```
```cpp
auto stub = helloworld::Greeter::NewStub(channel);
```

- Make a unary rpc, with `ClientContext` and request/response proto messages.

```
```cpp
ClientContext context;
HelloRequest request;
request.set_name("hello");
Expand All @@ -116,7 +116,7 @@ $ protoc -I ../../protos/ --cpp_out=. ../../protos/helloworld.proto

- Check returned status and response.

```
```cpp
if (status.ok()) {
// check reply.message()
} else {
Expand All @@ -130,7 +130,7 @@ For a working example, refer to [greeter_client.cc](greeter_client.cc).

- Implement the service interface

```
```cpp
class GreeterServiceImpl final : public Greeter::Service {
Status SayHello(ServerContext* context, const HelloRequest* request,
HelloReply* reply) override {
Expand All @@ -144,7 +144,7 @@ For a working example, refer to [greeter_client.cc](greeter_client.cc).

- Build a server exporting the service

```
```cpp
GreeterServiceImpl service;
ServerBuilder builder;
builder.AddListeningPort("0.0.0.0:50051", grpc::InsecureServerCredentials());
Expand All @@ -170,22 +170,22 @@ The channel and stub creation code is the same as the sync client.
- Initiate the rpc and create a handle for the rpc. Bind the rpc to a
`CompletionQueue`.

```
```cpp
CompletionQueue cq;
auto rpc = stub->AsyncSayHello(&context, request, &cq);
```

- Ask for reply and final status, with a unique tag

```
```cpp
Status status;
rpc->Finish(&reply, &status, (void*)1);
```

- Wait for the completion queue to return the next tag. The reply and status are
ready once the tag passed into the corresponding `Finish()` call is returned.

```
```cpp
void* got_tag;
bool ok = false;
cq.Next(&got_tag, &ok);
Expand All @@ -203,7 +203,7 @@ completion queue to return the tag. The basic flow is

- Build a server exporting the async service

```
```cpp
helloworld::Greeter::AsyncService service;
ServerBuilder builder;
builder.AddListeningPort("0.0.0.0:50051", InsecureServerCredentials());
Expand All @@ -214,7 +214,7 @@ completion queue to return the tag. The basic flow is

- Request one rpc

```
```cpp
ServerContext context;
HelloRequest request;
ServerAsyncResponseWriter<HelloReply> responder;
Expand All @@ -224,7 +224,7 @@ completion queue to return the tag. The basic flow is
- Wait for the completion queue to return the tag. The context, request and
responder are ready once the tag is retrieved.

```
```cpp
HelloReply reply;
Status status;
void* got_tag;
Expand All @@ -239,7 +239,7 @@ completion queue to return the tag. The basic flow is
- Wait for the completion queue to return the tag. The rpc is finished when the
tag is back.

```
```cpp
void* got_tag;
bool ok = false;
cq.Next(&got_tag, &ok);
Expand Down

0 comments on commit 2e9ce91

Please sign in to comment.