ShadowFax
ShadowFax

Reputation: 95

Google Protocol Buffers

I'm trying to parse a very big message (approx 25 fields) and serialize them. The 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.

Upvotes: 2

Views: 1069

Answers (1)

tgoodhart
tgoodhart

Reputation: 3266

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.

Upvotes: 7

Related Questions