diff options
author | James Eady <jmeady@google.com> | 2015-11-04 14:54:50 -0500 |
---|---|---|
committer | James Eady <jmeady@gmail.com> | 2015-12-15 15:08:28 -0500 |
commit | 2e9ce91eb2f6fd0922d161da5b7ac6206d0770df (patch) | |
tree | f15074e3ee5f6c06985e643cf718ec0d4c58b380 /examples/cpp | |
parent | 5c8c3e78a5b2cd6fb8504b48bac7b7f030cce787 (diff) |
Use code type highlight for the code blocks in the cpp helloworld
example README.md
..
Diffstat (limited to 'examples/cpp')
-rw-r--r-- | examples/cpp/helloworld/README.md | 28 |
1 files changed, 14 insertions, 14 deletions
diff --git a/examples/cpp/helloworld/README.md b/examples/cpp/helloworld/README.md index 7a7194d111..90f3d6b147 100644 --- a/examples/cpp/helloworld/README.md +++ b/examples/cpp/helloworld/README.md @@ -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"; @@ -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"); @@ -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 { @@ -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 { @@ -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()); @@ -170,14 +170,14 @@ 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); ``` @@ -185,7 +185,7 @@ The channel and stub creation code is the same as the sync client. - 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); @@ -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()); @@ -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; @@ -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; @@ -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); |