protobuf 消息的分隔符是什么?我正在处理序列化消息。我想知道消息是否以 $$__$$ 开头并以相同的符号结尾。
最佳答案
(除了现有的答案 1 , 2 )
Protocol Buffer 的常用框架方法是在前面添加 varint在实际的 protobuf 消息之前。
该实现已经是 protobuf 库的一部分,例如:
SerializeDelimitedToFileDescriptor()
) 祝你的项目好运!
编辑> The official reference指出:
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.)
关于serialization - protobuf 消息的分隔符是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52336629/