Hi all,
Is there a favored way to copy a protobuf message from one type to another ? A little background:
I have two messages for example:
message A {
enum foo {
field1 = 0;
field2 = 1;
}
int32 id;
string name;
foo type;
}
message B {
enum foo {
field1 = 0;
field2 = 1;
field3 =2;
}
int32 id;
string name;
foo type;
}
I have references to these messages and want to implement this method:
void copy(A &in, B &out) {
// in's contents need to be copied to out
}
the only difference between A and B is the enum field and they are named different. There could be more messages within the message types A and B with the same fields, but only enum's having an extra field in B. How should i go about this ?
Do the following options look feasible :
void copy(A &in, B &out) {
// in's contents need to be copied to out
cast in to type B
out = in;
}
void copy(A &in, B &out) {
// in's contents need to be copied to out
Use in.SerializeAsString() and pipe it to out.ParseFromString()
}
Appreciate the community's help!
Thanks!