C++ 等效于 SerializeWithLengthPrefix [英] C++ equivalent to SerializeWithLengthPrefix
问题描述
我使用协议缓冲区(protobuf-net)和套接字(TcpListener 和 TcpClient)构建了一个通信库,它工作正常,但现在一位同事需要编写一个库来使用 C++ 与我的软件进行通信.>
事实证明我正在使用 Serializer.NonGeneric.SerializeWithLengthPrefix
和 Serializer.NonGeneric.TryDeserializeWithLengthPrefix
.
protobuf C++ 库中是否有等价的函数?如果没有,有谁知道如何实现它,或者已经实现了共享?
我非常不熟悉 C++ API;但是如果您首先将数据写入缓冲区,那么长度前缀本身非常简单,特别是如果您使用固定宽度的 32 位编码(而不是 base-128 可变长度).另请参阅 google-groups 论坛上的此主题.
I built a communication library using Protocol Buffers (protobuf-net) using Sockets (TcpListener and TcpClient) and it is working fine, but now a co-worker needs to write a library to communicate with my software using C++.
Turns out that I'm using the Serializer.NonGeneric.SerializeWithLengthPrefix
and Serializer.NonGeneric.TryDeserializeWithLengthPrefix
.
Are there equivalent functions in the protobuf C++ libraries? If not, anyone knows how to implement it, or have it implemented to share?
I'm not hugely familiar with the C++ API; but the length prefix itself is pretty simple if you write the data to a buffer first, especially if you use the fixed-width 32-bit encoding (rather than base-128 variable-length). See also this thread on the google-groups forum.
这篇关于C++ 等效于 SerializeWithLengthPrefix的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!