Hin*_*sum 8 c++ rpc controller channel protocol-buffers
我正在尝试使用 protobuf 生成使用 RpcChannel 和 RpcController 的服务。我参考了 google protobuf 的语言指南和:
我有这样的示例原型文件:
语法 = "proto2";
message SearchRequest
{
required string Request = 1;
}
message SearchResponse
{
required string Response = 2;
}
service SearchService {
rpc Search (SearchRequest) returns (SearchResponse);
}
Run Code Online (Sandbox Code Playgroud)
然后我编译它:
protoc --cpp_out=./ examples.proto
Run Code Online (Sandbox Code Playgroud)
我有 .h 和 .cc 文件。但是当我搜索生成的代码时,我只找到了“Request”和“Response”的类,而没有找到“SearchService”的类:
examples.pb.h:class SearchRequest;
examples.pb.h:class SearchResponse;
examples.pb.h:class SearchRequest : public ::google::protobuf::Message {
examples.pb.h: // @@protoc_insertion_point(class_scope:SearchRequest)
examples.pb.h:class SearchResponse : public ::google::protobuf::Message {
examples.pb.h: // @@protoc_insertion_point(class_scope:SearchResponse)
Run Code Online (Sandbox Code Playgroud)
语言指南网页提供了一个需要使用“SearchService”类的示例(https://developers.google.com/protocol-buffers/docs/proto#services):但在生成的代码中,没有搜索服务. 该指南没有提供 RpcChannel/RpcController 用法的完整示例。
那么如何修复示例以使其正常工作?我搜索了谷歌,但没有找到任何好的 cpp 示例,它提供了 RpcChannel/RpcController 如何工作的完整示例。任何提示或链接?
谢谢!
protobuf 本身不提供 RPC 实现;你应该使用插件接口来创建你自己的,或者使用 grpc。
例如,grpc 为此使用grpc_cpp_plugin插件。
$ protoc -I ../../protos --grpc_out=. --plugin=protoc-gen-grpc=`which grpc_cpp_plugin` ../../protos/route_guide.proto
Run Code Online (Sandbox Code Playgroud)
https://github.com/grpc/grpc/blob/master/examples/cpp/cpptutorial.md