为什么为 Protobuf v3 决定隐式存在和常用默认值?

Why was implicit presence with commonly used defaults decided for Protobuf v3?

我是 Protobuf v3 的新手。

据此 doc 看来,Protobuf v3 隐式存在字段。因此,Protobuf 消息的接收者无法知道是否

我的问题是 - 为什么做出这个决定?

例如,我在 Protobuf 消息中有一个名为 num_children 的字段,例如

syntax = "proto3";

message Family {
  uint32 num_children = 1;
}

作为 Family 消息的接收者,如果我看到 num_children = 0 我无法知道这个家庭是否真的有 0 children 或者发件人是否忘记指定消息的数量children.

乍一看,这在我看来是一个设计缺陷。这是什么道理?对此的最佳做法是什么?

好消息。存在检测现在回到了 proto3 中,并且已经有几个月了。只需在字段前添加 optional - 它们都是可选的(在 proto3 中),但此关键字启用存在跟踪。这解决了隐式默认值与显式默认值的问题。 optional 现在在这里意味着完全不同的东西,这有点令人困惑,但这可能比添加新的 keyword/syntax!

相关的问题要好
syntax = "proto3";

message Family {
  optional uint32 num_children = 1;
}

您 link 的文档已过期;这不再是实验性功能,默认情况下启用。