谷歌Protobuf编译器不为服务标签生成类?
google protobuf compiler doesn't generate class for service tag?
我正在尝试使用 protobuf 使用 RpcChannel 和 RpcController 生成服务。我参考了谷歌protobuf的语言指南,并且:
我有这样的示例原型文件:
语法 = "proto2";
message SearchRequest
{
required string Request = 1;
}
message SearchResponse
{
required string Response = 2;
}
service SearchService {
rpc Search (SearchRequest) returns (SearchResponse);
}
然后我用:
protoc --cpp_out=./ examples.proto
我有 .h 和 .cc 文件。但是当我搜索生成的代码时,我只找到了"请求"和"响应"的类,但没有找到"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)
语言指南网页提供了一个示例(https://developers.google.com/protocol-buffers/docs/proto#services),它需要使用"SearchService"类:但在生成的代码中,没有搜索服务。该指南没有提供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
https://github.com/grpc/grpc/blob/master/examples/cpp/cpptutorial.md
相关文章:
- Active Directory:从网络服务帐户下运行的Windows服务调用ADsOpenObject时失败
- 检测win32服务创建和删除的最佳方法
- 使用 mod_gsoap 部署服务时,如何在 Gsoap 中更改 soap 上下文的模式?
- 当服务中的事件被触发时,如何将响应从服务发送回客户端?
- C 和 C++ 中开关语句的案例标签的常量值,但显示不同的行为
- gRPC 生成的代码缺少服务实现
- 如何正确指定 goto 语句的标签?
- C# DLL 从C++应用程序调用 SOAP Web 服务
- 在 Winrt/C++ 中使用应用服务
- 将第二个 GATT 服务添加到 Movesense 容器
- 从运行服务的应用程序代码中提取窗口句柄
- 使用g++静态初始化带有命名标签的嵌套C++结构
- 通过水平滚动条更改标签
- 对于使用高级服务的分钟数和应付金额,我不断得到相同的数字
- 通过 Tor 服务C++ socket.io 客户端
- 创建服务失败0x6f7存根收到错误数据
- 从 QFontDatabase 设置 QFont 将所有标签设置为等宽字体?Qt C++
- Windows 后台服务(系统配置文件)无法使用 C++ 访问 win 10 上的用户 appData 文件夹?
- 在C++中存储要输入的标签列表
- 谷歌Protobuf编译器不为服务标签生成类?