ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码

C++使用protobuf传输中间包含\0的字节数组

来源:网络整理     时间:2015-12-09     关键词:

本篇文章主要介绍了"C++使用protobuf传输中间包含\0的字节数组",主要涉及到方面的内容,对于C/C++jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播感兴趣的同学可以参考一下: The C++ implementation of protocol buffers returns the byte and string types as ...

The C++ implementation of protocol buffers returns the byte and string types as std::string. This structure contains a length function telling you how long the corresponding data is (as well as the data itself.) Thus there is no special significance of embeded \0 characters.

The setting functions accept a string too, or there are versions that accept a buffer and length. If you want to set a field you can just do this:

pb.set_foo( std::string( data, data_length ));

or

pb.set_foo( data, data_length );
以上的方式在读取的时候,还是被转换为string(到第一个\0)
可以通过这样的方式解决:
pt.mutable_foo(),协议中再加上length即可

以上就介绍了C++使用protobuf传输中间包含\0的字节数组,包括了方面的内容,希望对C/C++jrs看球网直播吧_低调看直播体育app软件下载_低调看体育直播有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_240985.html

相关图片

相关文章