首页 > 解决方案 > 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. The example 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 also contains enumeration value for a type of the message.

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?

标签: c++protocol-buffers

解决方案


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).


推荐阅读