简体   繁体   English

google protobuf 消息是否具有带有元信息的可解析标头?

[英]Do google protobuf messages have parseable headers with meta information?

I couldn't find a proper guide to send and receive protobuf messages over network.我找不到合适的指南来通过网络发送和接收 protobuf 消息。 Theexample from tutorial shows how to read from and write to a file.教程中的示例显示了如何读取和写入文件。 So a naive approach would be to create a custom header for a network protocol and send protobuf files.因此,一种天真的方法是为网络协议创建自定义 header 并发送 protobuf 文件。 Header also contains enumeration value for a type of the message. Header 还包含消息类型的枚举值。

So the question is: Does protobuf provide an API to read a message's header to be able to distinguish its type and length?If it does, can it be acquired without receiving the whole message?那么问题来了: protobuf 是否提供了一个 API 来读取消息的 header 以便能够区分它的类型和长度?如果有,是否可以在不接收整个消息的情况下获取它?

No, a vanilla protobuf payload does not contain metadata about the message type (the recipient is expected to know that in advance), nor is it self-framing (if sending multiple messages on the same transport, you are expected to use your own framing protocol).不,vanilla protobuf 有效负载不包含有关消息类型的元数据(预计收件人会提前知道这一点),也不是自成帧(如果在同一传输上发送多条消息,您应该使用自己的成帧协议)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM