Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add proto3 optional support #6

Closed
wants to merge 2 commits into from
Closed

Conversation

shengdoushi
Copy link

No description provided.

@onanying
Copy link
Member

onanying commented Nov 6, 2023

在 Protocol Buffers 的第三版(proto3)中,所有字段都是可选的(optional),但这个版本的语法中并没有明确的 optional 关键字。这意味着如果一个字段没有设置值,那么它会被赋予默认值。对于数字类型,这个默认值是 0;对于字符串,这个默认值是空字符串;对于布尔类型,这个默认值是 false;对于枚举,这个默认值是第一个定义的枚举值。

然而,从 Protocol Buffers 3.12.0 版本开始,optional 关键字再次被引入到 proto3 中,允许字段显式地被标记为可选。这是为了解决在某些情况下,无法区分字段是被设置为默认值,还是根本没有被设置的问题。

所以,optional 关键字在早期的 proto3 版本中被废弃,但在后续的版本中又被重新引入。

@onanying
Copy link
Member

onanying commented Nov 6, 2023

@shengdoushi 要提交到这个主库,现在这个库是个同步克隆库,看这里 mix-php/mix#91

@onanying
Copy link
Member

onanying commented Nov 9, 2023

@shengdoushi 要提交到这个主库,当前这个库是个同步克隆库,没办法接收PR,看这里 mix-php/mix#91

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants