How can unknown field functionality be replicated in proto3?

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

How can unknown field functionality be replicated in proto3?

问题

谷歌已经在proto3中删除了未知字段。我很想听听这个选择背后的原因。另外,如果有人知道如何复制proto2的行为,我也很想听听。

如果有关系的话,我们是用Go语言编写我们的代码。

由于proto3和grpc是并行开发的,我也想与grpc社区联系。

来源:未知字段的删除

英文:

Google has removed unknown fields in proto3. I would love to hear the reasoning behind this choice. Also, if anyone has any way to replicate the proto2 behavior I would love to hear it.

If it matters, we are writing our code in Go.

As proto3 and grpc were developed in parallel, I wanted to reach out to the grpc community as well.

Source: [Removal of unknown fields][2]

[2]: https://github.com/google/protobuf/releases/tag/v3.0.0-alpha-2 "Release Protocol Buffers v3.0.0-alpha-2 · google/protobuf"

答案1

得分: 2

去除原始类型的字段存在对于Protobuf来说在许多语言中更加“自然”和高效,因为C/C++、Java、C#和Go中的原始类型必须存在。在这些语言中,如果你想要存在信息,你可以通过将原始类型包装成指向原始类型的指针来实现。

Protobuf 3去除了原始类型的存在信息,但对于消息类型仍然保留了存在信息。因此,你可以使用相同的“包装”技术来处理Protobuf。Protobuf现在有包装原始类型的标准消息

英文:

Getting rid of field presence for primitives makes Protobuf more "natural" and efficient in many languages, since primitives in C/C++, Java, C#, and Go must be present. In such languages, if you want presence information you "box" the primitive by making it a pointer to a primitive.

Protobuf 3 gets rid of presence for primitives but still has it for messages. Thus, you can use the same "boxing" technique for Protobuf. Protobuf now has standard messages that box primitives.

huangapple
  • 本文由 发表于 2015年4月8日 11:15:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/29505302.html
匿名

发表评论

匿名网友

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

确定