C++使用protobuf传输中间包含\0的字节数组
2015-12-09 11:52
525 查看
The C++ implementation of protocol buffers returns the byte and string types as
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:
or
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
\0characters.
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即可
相关文章推荐
- Memento(备忘录)设计模式
- C++中map的常用方法
- c++_4: 多态_1_虚函数的定义
- C++异常机制的实现方式和开销分析
- C++ 操作 MySQL
- C语言总结
- 【离散数学】实验四 图的随机生成及欧拉(回)路的确定
- 黑马程序员——C语言——文件读写
- 初来乍到之辛酸菜鸟
- 跟我一起玩Win32开发(1):关于C++的几个要点
- C语言结构类型
- Remove Element
- Remove Element
- 《C语言综合研究第2章宣讲会研究报告_20130610_v1.0》 2.docx
- 《C语言综合研究第1章宣讲会研究报告_20130609_v1.0》
- dev-c++ 添加boost库
- C++强大的背后(二)
- C++强大的背后(一)
- VC++中List Control控件的使用方法介绍
- C++11 元编程(meta-programming)判断T是否有==操作符