jeudi 3 décembre 2015

Copying a generic protobuf into a new object on the heap

I want to make a copy of a generic const protobuf Message for further manipulation. I came up with

Message* myfn(const Message *msg) {
  Message *copy = msg->New();
  copy->CopyFrom(*msg);
  // do stuff
  return copy;
}

Is this correct/idiomatic? Or is there a better way (perhaps C++11 specific)?

Aucun commentaire:

Enregistrer un commentaire