C++ C++;Google协议缓冲区:将二进制流分配给protobuf对象
我有以下protoc文件:C++ C++;Google协议缓冲区:将二进制流分配给protobuf对象,c++,protocol-buffers,C++,Protocol Buffers,我有以下protoc文件: message DataChunk{ required bool isHash=1; required int64 hash=2; required string data=3; } message responseBody{ repeated DataChunk dataChunk=1; } 我有以下C++函数: void eamorr(string data){ //data is a protocol buffer str
message DataChunk{
required bool isHash=1;
required int64 hash=2;
required string data=3;
}
message responseBody{
repeated DataChunk dataChunk=1;
}
我有以下C++函数:
void eamorr(string data){ //data is a protocol buffer stream converted to a string
responseBody rb;
rb=some_function_of(data); //what to do here?
}
字符串“data”是使用以下方法创建的:
...
std::ostringstream stream;
rb.SerializeToOstream(&stream);
string protobufStream = stream.str();
...
我的问题是:如何将字符串转换为protoc对象,以便访问成员元素?请记住,我对C++非常陌生。< P>创建数据对象时,为什么不做:
responseBody rb; //this is your proto object;
rb.SerializeToString(&data);
然后在反序列化时:
void eamorr(string data){
responseBody rb;
rb.ParseFromString(data);
}
创建数据对象时,为什么不制作:
responseBody rb; //this is your proto object;
rb.SerializeToString(&data);
然后在反序列化时:
void eamorr(string data){
responseBody rb;
rb.ParseFromString(data);
}
你可以用
rb.ParseFromString(data)
你可以用
rb.ParseFromString(data)
你好,谢谢你。它正在工作。抱歉,回复迟了。如果没有生成
ParseFromString
方法怎么办?您好,谢谢。它正在工作。抱歉,回复迟了。如果没有生成ParseFromString
方法怎么办?