web-dev-qa-db-ja.com

null要求または応答でgrpc呼び出しを定義できますか?

Proto3のrpc構文は、null要求または応答を許可しますか?

例えば次のものと同等のものが欲しい:

rpc Logout;
rpc Status returns (Status);
rpc Log (LogData);

または、null型を作成するだけですか?

message Null {};

rpc Logout (Null) returns (Null);
rpc Status (Null) returns (Status);
rpc Log (LogData) returns (Null);
86
Mark Kahn

以下のケントンのコメントは適切なアドバイスです。

...開発者としての私たちは、将来何が欲しいかを推測するのが本当に苦手です。そのため、空であっても、すべてのメソッドのカスタムパラメータと結果タイプを常に定義することにより、安全であることをお勧めします。


自分の質問に答える:

デフォルトのプロトファイルを見ると、私は に出くわしました。これは上で提案したNullタイプとまったく同じです:)

そのファイルからの抜粋:

// A generic empty message that you can re-use to avoid defining duplicated
// empty messages in your APIs. A typical example is to use it as the request
// or the response type of an API method. For instance:
//
//     service Foo {
//       rpc Bar(google.protobuf.Empty) returns (google.protobuf.Empty);
//     }
//

message Empty {

}
117
Mark Kahn