mardi 13 octobre 2015

protobuf delete sub message by reflection

I've got a problem of erase a sub-message by reflection. For example:

message Resource {
   ...
   google.protobuf.Timestamp ct = 5;
   ...
}

To totally erase it, use this API:

Resource res;
res.clear_ct();

Then you wouldn't see ct field in wire format. My problem is to do that by reflection:

google::protobuf::Descriptor* d = res.GetDescriptor();
google::protobuf::Reflection* r = res.GetReflection();
r->ClearField(&res, d->FindFieldByName("ct"));

I always get a shadow ct on wire (in Json):

"ct": { }

Is there any way I can do the same thing by Reflection as clear_ct() API does?

Thanks, Ray





Aucun commentaire:

Enregistrer un commentaire