如何在没有定义的情况下获取 Google Protobuf 消息的结构

发布于 2024-08-16 15:18:32 字数 247 浏览 4 评论 0原文

我必须获取传输给我的 protobuf 消息的消息结构,而无需消息的定义。使用 UnknownFieldSet 方法,我能够获取消息的字符串表示形式,如下所示:

1: "a"
2: {
   3:"b"
   4:"c"
}

字段 2 表示什么数据结构?使用 UnknownFieldSet.Field.getGroupList 我能够获取字段 3 和 4 的内容,这是否意味着字段 2 具有“已弃用”的组结构?

I have to get the message structure of a protobuf message transfered to me without the message's definition. Using UnknownFieldSet methods, I was able to get a string representation of the message as below:

1: "a"
2: {
   3:"b"
   4:"c"
}

What data structure does field 2 represent ? Using UnknownFieldSet.Field.getGroupList i was able to get the content of field 3 and 4, does that means field 2 has the "deprecated" group structure ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

墨离汐 2024-08-23 15:18:32

如果您发布了原始二进制数据,我们可以告诉您 - 或者您可以查看 协议缓冲区编码文档。如果您看到接线类型为 3 的字段,则表示有一个组。

我对 UnknownFieldSet API 不太熟悉,但听起来确实像是在与一个团体打交道。

另一方面,我预计群组的大部分使用都在 Google 内部 - 这些数据来自哪里?诚然,没有什么可以阻止人们使用已弃用的组格式而不是嵌入消息,但我希望很少有人这样做......

有什么理由可以'不询问涉及的 .proto 文件吗?虽然一些信息当然可以从没有定义的协议缓冲区中收集,但它们实际上是设计用于两端知道消息格式的情况 - 尽管可能不同版本。

If you posted the raw binary data we could tell you - or you could look at the protocol buffer encoding documentation. If you see a field with a wire type of 3, that indicates a group.

I'm not as familiar with the UnknownFieldSet API as I probably should be, but it does sound like you're dealing with a group.

On the other hand, I'd expect most of the uses of groups to be internal to Google - where did this data come from? Admittedly there's nothing to stop people from using the deprecated group format instead of embedded messages, but I would hope that few are doing so...

Is there any reason you can't ask for the .proto file involved? While some information can certainly be gleaned from protocol buffers without their definitions, they're really designed to be used in situations where both ends do know the message format - although possibly different versions.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文