开发者

Google Protocol Buffers

开发者 https://www.devze.com 2023-03-19 04:05 出处:网络
I\'m trying to parse a very big message (approx 25 fields) and serialize them. The开发者_如何学Python fields in the message appear in the same order all the time and in the proto file I numbered them

I'm trying to parse a very big message (approx 25 fields) and serialize them. The开发者_如何学Python fields in the message appear in the same order all the time and in the proto file I numbered them accordingly. Is there a method to set the fields with the tag value (the number in the proto file)?

Thanks, Chem.


google::protobuf::Message myMessage;
const google::protobuf::Descriptor * myDescriptor = myMessage.GetDescriptor();
const google::protobuf::FieldDescriptor * myField = myDescriptor->FindFieldByNumber(9001);
const google::protobuf::Reflection * myReflection = myMessage.GetReflection();
myReflection->SetInt32( &myMessage, myField, 7);

Obviously you'll need to change the field number, type of the field, and value to which you want to set.

0

精彩评论

暂无评论...
验证码 换一张
取 消