如何仅在Protobuf序列化字节数组中解析一个字段

发布于 2025-01-24 12:37:44 字数 84 浏览 5 评论 0原文

我只需要一个来自Protobuf序列化字节数组的字段,但是必须调用parsefrom函数,这是低性能的。我如何从字节数组中获得字段偏移,而通过偏移分析值。

I need only one field from protobuf serialize byte array, but must call parseFrom function, which is low performance. how can I get field offset from byte array, and parse value by offset.

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

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

发布评论

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

评论(1

我们的影子 2025-01-31 12:37:44

“ nofollow noreferrer”>“ nofollow noreferrer”>“ nofollow noreferrer”>“ nofollow” :

序列化消息时,无法保证其已知或未知字段的书面订单。序列化顺序是实施细节,任何特定实现的详细信息将来可能会发生变化。因此,协议缓冲区解析器必须能够按任何顺序解析字段。

因此,您不能有100%可靠的偏移到一个字段。您需要调用解析函数。

As mentioned in the Protocol Buffers documentation on fields order:

When a message is serialized, there is no guaranteed order for how its known or unknown fields will be written. Serialization order is an implementation detail, and the details of any particular implementation may change in the future. Therefore, protocol buffer parsers must be able to parse fields in any order.

Therefore you cannot have a 100% reliable offset to a field. You will need to call the ParseFrom function.

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