Reputation: 2137
I'm trying to describe an RPC service using Google's Protocol Buffers
service WhoamiService {
rpc WhoAreYou() returns (Whoami) {}
}
message Whoami {
optional bytes request_id = 1;
optional string hostname = 2;
optional string message = 3;
}
When I try to compile this definition, I get an error Expected type name
pointing to the WhoAreYou()
piece.
It works fine if I replace WhoAreYou()
with WhoAreYou(Whoami)
, but in this case, the method does not need any parameters.. Is there a way to do this or is it simply not supported?
Upvotes: 100
Views: 61751
Reputation: 2531
You can specify google.protobuf.Empty
instead of your own empty message.
Example:
rpc WhoAreYou(google.protobuf.Empty) returns (Whoami) {
}
Don't forget to import appropriate proto file:
import "google/protobuf/empty.proto";
Reference: https://protobuf.dev/reference/protobuf/google.protobuf/#empty
Upvotes: 152
Reputation: 45286
You have to specify an input type. If you don't want the method to take any parameters, define an empty message type, like:
message WhoAreYouParams {}
The reason this is required is so that if you later need to add an optional parameter, you can do so without breaking existing code.
Upvotes: 151