gRPC/Protobuf 3 语法:rpc 行以分号结尾与'{}'有什么区别?

gRPC/Protobuf 3 syntax: what is the difference between rpc lines that end with semicolon vs '{}'?

我见过使用 Protobuf v3 声明 gRPC 服务的两种不同方式。一些代码有 rpc line end with a semicolon(例如当前的 proto3 文档):

service SearchService {
  rpc Search (SearchRequest) returns (SearchResponse);
}

其他code has the rpc line end with{}:

service Greeter {
  rpc SayHello (HelloRequest) returns (HelloReply) {}
}

这两个都使用 protoc v3.0.0-alpha-2 编译器编译并生成相同的 (go) 代码。

这两种语法有什么区别?

没什么,真的;它们是等价的。

有选项时使用{}语法。如果您不指定任何选项,则两种语法都有效(就像在 C 中一样!)。