[英]why protocol buffer bytes is string in c++?
protocol buffer say it can contain any arbitrary sequence of bytes . 协议缓冲区说它可以包含任意字节序列 。 but if my data contain '\\0' ,how protocol buffer can encode my whole data from a string variable.
但如果我的数据包含'\\ 0',协议缓冲区如何从字符串变量编码我的整个数据。
The C++ implementation of protocol buffers returns the byte and string types as std::string
. 协议缓冲区的C ++实现将字节和字符串类型返回为
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. 这个结构包含一个长度函数,告诉你相应的数据有多长(以及数据本身。)因此嵌入的
\\0
字符没有特殊的意义。
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 );
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.