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.
精彩评论