gRPC/Protobuf 3语法:以分号和'{}'结尾的rpc行之间有什么区别? [英] gRPC/Protobuf 3 syntax: what is the difference between rpc lines that end with semicolon vs '{}'?

查看:387
本文介绍了gRPC/Protobuf 3语法:以分号和'{}'结尾的rpc行之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经看到了使用Protobuf v3声明gRPC服务的两种不同方式.某些代码的 rpc行以分号结尾(例如当前proto3文档):

I've seen two different ways of declaring an gRPC service using Protobuf v3. Some code has the rpc line end with a semicolon (such as the current proto3 documentation):

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

其他代码的rpc行结尾为 {}:

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

这两者都使用protoc v3.0.0-alpha-2编译器进行编译,并产生相同的代码.

Both of these compile with the protoc v3.0.0-alpha-2 compiler and produce the same (go) code.

这两种语法有什么区别?

What is the difference between the two syntaxes?

推荐答案

没什么,真的;它们是等效的.

Nothing, really; they are equivalent.

当有选项时,将使用{}语法.如果不指定任何选项,则两种语法都可以工作(就像在C中一样!).

The {} syntax is used when there are options. If you don't specify any options, either syntax works (just like in C!).

这篇关于gRPC/Protobuf 3语法:以分号和'{}'结尾的rpc行之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆