【问题标题】:grpc proto file genertion to c++ issuegrpc proto 文件生成到 C++ 问题
【发布时间】:2021-01-27 17:15:36
【问题描述】:

我使用 protoc 生成了这个 proto 文件。 protoc -I=C:\proto --cpp_out=C:\proto C:\proto\test.proto

syntax = "proto3";

option java_package = "ex.grpc";

package mathtest;

// Defines the service
service MathTest {
    // Function invoked to send the request
    rpc sendRequest (MathRequest) returns (MathReply) {}
}

// The request message containing requested numbers
message MathRequest {
    int32 a = 1;
    int32 b = 2;
}

// The response message containing response
message MathReply {
    int32 result = 1;
}

生成这个函数的头文件:

  virtual void sendRequest(::PROTOBUF_NAMESPACE_ID::RpcController* controller,
                       const ::mathtest::MathRequest* request,
                       ::mathtest::MathReply* response,
                       ::google::protobuf::Closure* done);

当我基于的示例像这样覆盖此函数时:

/Status sendRequest(
        ServerContext* context,
        const MathRequest* request,
        MathReply* reply
    ) override {

我做错了什么以及我应该如何生成 proto 文件?

【问题讨论】:

    标签: c++ grpc protobuf-c


    【解决方案1】:

    更新: 发现需要运行这个命令生成grpc.pb头:

    protoc -IC:\proto --grpc_out=C:\Users\alon.h\grpc.build --plugin=protoc-gen-grpc=C:\proto\grpc_cpp_plugin.exe C:\proto\test.原型

    需要grpc_cpp_plugin.exe,可以在grpc git仓库中找到

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-03-05
      • 2019-05-12
      • 1970-01-01
      • 1970-01-01
      • 2021-04-17
      • 2021-03-20
      • 2020-08-24
      • 2018-08-01
      相关资源
      最近更新 更多