gpt4 book ai didi

serialization - protobuf 消息的分隔符是什么?

转载 作者:行者123 更新时间:2023-12-04 03:36:12 29 4
gpt4 key购买 nike

protobuf 消息的分隔符是什么?我正在处理序列化消息。我想知道消息是否以 $$__$$ 开头并以相同的符号结尾。

最佳答案

(除了现有的答案 12 )

Protocol Buffer 的常用框架方法是在前面添加 varint在实际的 protobuf 消息之前。

该实现已经是 protobuf 库的一部分,例如:

  • 对于 Java:MessageLite.writeDelimitedTo() , Parser.parseDelimitedFrom()
  • 对于 C:标题中的方法 google/protobuf/util/delimited_message_util.h (例如 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/

    29 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com