If you want to write multiple messages to a single file or stream, it
is up to you to keep track of where one message ends and the next
begins. The Protocol Buffer wire format is not self-delimiting, so
protocol buffer parsers cannot determine where a message ends on their
own. The easiest way to solve this problem is to write the size of
each message before you write the message itself. When you read the
messages back in, you read the size, then read the bytes into a
separate buffer, then parse from that buffer. (If you want to avoid
copying bytes to a separate buffer, check out the CodedInputStream
class (in both C++ and Java) which can be told to limit reads to a
certain number of bytes.)
从原型指南中可以看出,你需要自己处理信息的大小:
https://developers.google.com/protocol-buffers/docs/techniques
一个简单的解决方案是在base64中,在文件的新行上序列化每个proto。在
这样,python就可以很容易地解析和使用它们。在
相关问题 更多 >
编程相关推荐