c++ - 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?
解决方案
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).
推荐阅读
- java - 带 int 的 if 语句:Java 认为我想转换为布尔值
- bootstrap-4 - 将 Bootstrap 4 导航选项卡设置为相同的高度
- javascript - 在 reactjs 中从 URL 预渲染图像
- python - 将类对象读/写到python中的dat文件
- .net - 我们如何在 .net core 2.2 中使用 HttpClient 实现缓存
- ruby-on-rails - 无法安装导轨。错误:您没有 /usr/local/rvm/gems/ruby-2.6.3 目录的写入权限
- r - 如何将数据框转换为 arules 的事务对象
- json - 在 Oracle APEX 19.2 中解析 JSON
- javascript - Babel 插件 transform-remove-console 不适用于 Vue CLI 4 @vue/cli-plugin-babel/preset?
- class - 在 Flutter 中的两个类之间传递变量