Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can protobuf service method return primitive type?

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)?

like image 380
4ntoine Avatar asked Mar 05 '15 11:03

4ntoine


People also ask

Can protobuf return null?

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 .

What is a service in protobuf?

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.

Is protobuf strongly typed?

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++.

What does protobuf generate?

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.


1 Answers

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.

like image 195
Kenton Varda Avatar answered Sep 21 '22 09:09

Kenton Varda