有没有人有和google protobuf一起使用cocoaasyncsocket的经验?我想使用varint来分离帧,使用基于netty的客户端/服务器组合很简单,但在使用cocoaasync读取时,我看不到一种简单的方法来解码初始varint。
发布于 2011-05-25 04:47:39
在C++方面,您必须结合使用ReadVarint32()和VarintSize32()来执行以下操作:
char buf[4];
buf = some_api_call(); /* _Copy/peak_ up to 4 bytes off the wire */
CodedInputStream cos(buf, sizeof(buf) - 1);
uint32_t frame_sz;
if (!cos.ReadInputStream(&frame_sz)) {
// Unable to read the frame size
return false;
}frame_sz应该有一个有效的值,该值将告诉您它需要读取多少字节。
uint32_t consumed_bytes = CodedOutputStream::VarintSize32(frame_sz);现在您知道了生成frame_sz消耗了多少字节。
我会将这些调用包装在一个库中,并将其从您的应用程序中链接进来。
https://stackoverflow.com/questions/5797193
复制相似问题