Proto3在Go中的可选支持

huangapple go评论85阅读模式
英文:

Optional support in Proto3 for Go

问题

proto3(Go)不支持optional关键字。在proto3中,所有字段都是必需的,没有可选字段的概念。因此,无法在proto3中使用optional关键字。如果你需要可选字段的功能,可以考虑使用proto2版本。

英文:

Does optional supports in proto3 while working with Go? I tried with this:

protoc person.proto --go_out=. --experimental_allow_proto3_optional

but got this error

> person.proto: is a proto3 file that contains optional fields, but code generator protoc-gen-go hasn't been updated to support optional
> fields in proto3. Please ask the owner of this code generator to
> support proto3 optional.--go_out:

so proto3 (Go) does not support optional keyword?

答案1

得分: 6

protoc从版本v3.15.0开始支持此功能。请参阅发布说明

proto3的可选字段默认启用,不再需要--experimental_allow_proto3_optional标志。

protoc-gen-go插件从v1.22.0开始支持此功能。请参阅发布说明

此版本添加了对即将在protobuf语言的v3.12.0版本中引入的实验性proto3可选语义的支持[...]。

请确保将您的protoc-gen-go升级到v1.22.0或更高版本。

英文:

protoc does support it, starting from version v3.15.0. See the release notes:

> Optional fields for proto3 are enabled by default, and no longer require
the --experimental_allow_proto3_optional flag.

The protoc-gen-go plugin does starting from v1.22.0. Release notes:

> This release adds support for the experimental proto3 optional semantics coming in the v3.12.0 release of the protobuf language, [...]

Make sure to upgrade your protoc-gen-go to version v1.22.0 or above.

huangapple
  • 本文由 发表于 2021年10月19日 20:39:52
  • 转载请务必保留本文链接:https://go.coder-hub.com/69631001.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定