gpt4 book ai didi

c++ - 关于 Google 的 protobuf

转载 作者:搜寻专家 更新时间:2023-10-31 00:04:46 25 4
gpt4 key购买 nike

我知道它可以用来从文件中发送/接收结构化对象,

但是它可以用于从套接字发送/接收结构化对象序列吗?

http://code.google.com/p/protobuf/

最佳答案

Protocol Buffers 是一个结构化数据序列化(和反序列化)框架。它只关心将选择的预定义数据类型编码到数据流中。您对该流做什么取决于您。引用维基:

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.

是的,您可以使用它通过套接字发送/接收多个对象,但您必须做一些额外的工作来区分每个对象流。

关于c++ - 关于 Google 的 protobuf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3571879/

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