gpt4 book ai didi

protocol-buffers - protobuf 3 单数与可选有什么不同

转载 作者:行者123 更新时间:2023-12-04 02:00:55 27 4
gpt4 key购买 nike

查看proto3引用:

https://developers.google.com/protocol-buffers/docs/proto3#simple

它说的是关于 singular :

singular: a well-formed message can have zero or one of this field (but not more than one).

我不清楚这与 optional 有何不同.是 singular只是一种明确的方式来说明某事是 optional (现在对于 proto3 是隐含的)?或者还有什么我遗漏的吗?

谢谢。

最佳答案

可选的是 proto2句法。单数是 proto3句法。

在proto3中,singular是默认规则。今天文档需要改进,还有一个 Unresolved 问题:google/protobuf#3457 .

另见 google/protobuf#2497 why messge type remove 'required,optional'? ,以及哈伯曼对 GoogleCloudPlatform/google-cloud-python#1402 的评论:

I think the question is: what are you trying to do? Why is it relevant to you whether a field is set or not and what do you intend to do with this information?

In proto3, field presence for scalar fields simply doesn't exist. Your mental model for proto3 should be that it's a C++ or Go struct. For integers and strings, there is no such thing as being set or not, it always has a value. For submessages, it's a pointer to the submessage instance which can be NULL, that's why you can test presence for it.

关于protocol-buffers - protobuf 3 单数与可选有什么不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47339981/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com