I'm trying to use protobuf to generate a service using RpcChannel and RpcController. I referred to language guide of google protobuf and:
I've got sample proto file like this:
syntax = "proto2";
message SearchRequest
{
required string Request = 1;
}
message SearchResponse
{
required string Response = 2;
}
service SearchService {
rpc Search (SearchRequest) returns (SearchResponse);
}
Then I compiled it with:
protoc --cpp_out=./ examples.proto
I got .h and .cc files. But when I search the generated code, I only found classes for "Request" and "Response", but not a class for "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)
The language guide web-page provided an example(https://developers.google.com/protocol-buffers/docs/proto#services) which requires to use class of "SearchService": but in the generated code, there's no search service. The guide didn't provide a complete sample of RpcChannel/RpcController usages.
So how can I fix the example to make it work? I searched google but didn't find any good cpp example that gives a complete sample of how RpcChannel/RpcController could work. Any hints or links?
Thanks!
Proto3 is the latest version of Protocol Buffers and includes the following changes from proto2: Field presence, also known as hasField , is removed by default for primitive fields. An unset primitive field has a language-defined default value.
Protobuf is the most commonly used IDL (Interface Definition Language) for gRPC. It's where you basically store your data and function contracts in the form of a proto file.
Protocol Buffer (Protobuf) provides two simpler options for dealing with values that might be of more than one type. The Any type can represent any known Protobuf message type. And you can use the oneof keyword to specify that only one of a range of fields can be set in any message.
protobuf does not offer RPC implementation by itself; you should use plugin interface to create your own, or use grpc.
For example, grpc uses grpc_cpp_plugin
plugin for it.
$ 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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With