0

I have a RepeatedPtrField<M::Table> and a protobuf message M as:

message M {
  message Table {
    optional string guid = 1;
    optional int64 schema_version = 2;
    optional int64 data_version = 3;
    repeated Column column = 4;
  }
  repeated Table table = 1;
}

How to I create a instance of M having the contents of RepeatedPtrField. I can write a for loop to copy data explicitly, but I am currently looking for something more concise, preferably using std::move() like optimization.

v78
  • 2,803
  • 21
  • 44
  • I did `state.mutable_table()->Swap(&table);`, where table was the RepeatedPtrField, and it worked – v78 Dec 30 '19 at 08:17

1 Answers1

1

If you're using a new version of Protobuf, like Protobuf 3.6.0, RepeatedPtrField defines move constructor, and you can call std::move to achieve your goal.

If you're using an old version, you have to call Swap to do the work, as you mentioned in the comment.

for_stack
  • 21,012
  • 4
  • 35
  • 48