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 <[email protected]> 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 <[email protected]> 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 [email protected]. >>> To post to this group, send email to [email protected]. >> >> >>> 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 [email protected]. > To post to this group, send email to [email protected]. > 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 [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/protobuf. For more options, visit https://groups.google.com/d/optout.
