I'm trying to use Google protobuf and i 'm having the next descriptions:
message.proto file:
message Request { required int32 id = 1; optional string value = 2; }
service.proto file:
import "message.proto"; service Service { rpc request (Request) returns (bool); }
I'm trying to generate c++ sources and getting an error:
$ protoc service.proto --cpp_out=/tmp/proto/build
service.proto:4:40: Expected message type.
Do i have to return user-defined types only? Are primitive (like bool
or string
) supported? Can i use primitive types as service method argument (instead of Request
in my example)?
No, there is no case where it returns null . In fact, none of the field accessors on Java protobuf generated classes ever return null ; they always return the default value if the field is not present. Similarly, the setters do not allow you to set null .
Protocol buffers are a mechanism for sending data through the series of tubes known as the Internet. One common use of them is to define gRPC specifications — essentially a form of remote procedure calls. With gRPC service definitions, you create a “service” that has RPC methods.
Protobuf is a strongly typed flexible standard. The protobuf format is well supported by many programming languages. Protobuf ist not designed to be human readable. Protobuf is very fast, especially in C++.
For a oneof field, the protobuf compiler generates a single field with an interface type isMessageName_MyField . It also generates a struct for each of the singular fields within the oneof. These all implement this isMessageName_MyField interface.
No, you cannot use a primitive type as either the request or response. You must use a message type.
This is important because a message type can be extended later, in case you decide you want to add a new parameter or return some additional data.
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