By source values i meant the values of enums in "in" message: void copy(A 
&in, B &out). The enum values in A and B differ by one element.

By nested messages, 
message A {
   enum foo {
      field1 = 0;
      field2 = 1;
   }
   int32 id;
   string name;
   foo type;
   NestedMsg1 msg1;
}

message NestedMsg1 {
   int32 id;
   string name;
}

If message B were to also have a similar structure, will 
out.ParseFromString(in.SerializeToString()) take care of nested messages as 
well ?

I also explore CopyFrom(Message&) but not sure if it will work-

Thanks,
Shyam

On Wednesday, April 4, 2018 at 9:37:38 AM UTC-7, Bo Yang wrote:
>
> I don't quite follow your question.
> What's the source values and nested messages you are referring to ?
>
> On Tue, Apr 3, 2018 at 5:52 PM Shyam S R <sr.s...@gmail.com <javascript:>> 
> wrote:
>
>> thanks for the reply @Bo. Follow up: What happens to the enums, the 
>> source values are maintained i suppose ?
>>
>> Does it work with nested messages also, in the sense, does 
>> ParseFromString look for any message type information within the stream or 
>> as long as the scalar types are good it parses ok ?
>>
>> On Tuesday, April 3, 2018 at 5:42:26 PM UTC-7, Bo Yang wrote:
>>
>>> The second copy looks correct to me.
>>>
>>> On Tue, Apr 3, 2018 at 5:26 PM Shyam S R <sr.s...@gmail.com> wrote:
>>>
>> 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!
>>>>
>>>> -- 
>>>> You received this message because you are subscribed to the Google 
>>>> Groups "Protocol Buffers" group.
>>>>
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>>> an email to protobuf+u...@googlegroups.com.
>>>> To post to this group, send email to prot...@googlegroups.com.
>>>
>>>
>>>> Visit this group at https://groups.google.com/group/protobuf.
>>>> For more options, visit https://groups.google.com/d/optout.
>>>>
>>> -- 
>> You received this message because you are subscribed to the Google Groups 
>> "Protocol Buffers" group.
>> To unsubscribe from this group and stop receiving emails from it, send an 
>> email to protobuf+u...@googlegroups.com <javascript:>.
>> To post to this group, send email to prot...@googlegroups.com 
>> <javascript:>.
>> Visit this group at https://groups.google.com/group/protobuf.
>> For more options, visit https://groups.google.com/d/optout.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to protobuf+unsubscr...@googlegroups.com.
To post to this group, send email to protobuf@googlegroups.com.
Visit this group at https://groups.google.com/group/protobuf.
For more options, visit https://groups.google.com/d/optout.

Reply via email to