21,493
社区成员
发帖
与我相关
我的任务
分享最近使用protobuf给bytes赋值的时候遇到了麻烦,麻烦给位网友帮忙,谢谢!
.proto文件
message Example1 {
optional string stringVal = 1;
optional bytes bytesVal = 2;
}
c++赋值bytes
Example1 example1;
example1.set_stringval("hello,world");
example1.set_bytesval("are you ok?");
参考了网站:ProtoBuf在中C++使用介绍_R-QWERT的博客-CSDN博客_protobuf使用详解c++
这样写,本地打印也ok。但是服务端拿到bytesVal字段,在取值的时候发现bytesVal字段是个字符串,直接报错,请求各位,怎么解决,
bytes在c++当中,到底应该怎么赋值,
example1.bytesVal().c_str(),bytes 在 proto2 下解析完就是 string