MergeFrom requested enhancement for repeated fields

657 views
Skip to first unread message

Walt

unread,
Feb 22, 2012, 11:20:31 AM2/22/12
to Protocol Buffers
The MergeFrom semantics are clearly defined: For primitive types the
values are replaced when set; for repeated types the values are
concatenated.

It would be a useful enhancement to support a second method:
MergeFromReplace – which would have symmetric behavior for primitive
as well as repeated types. Instead of concatenating the array
elements – the array contents of the source (if set) – would replace
the array contents of the destination.

Jason Hsueh

unread,
Feb 22, 2012, 12:37:12 PM2/22/12
to Walt, Protocol Buffers
It's unlikely that we'd add more generated code to support this use case; code size is something that's watched carefully when making changes to the protobuf library.

However, you can get this behavior by preprocessing the message with reflection; you could iterate over the fields; if a repeated field is set in both the target and the source, then clear the field in the target. You would also need to recurse into nested singular messages. You can then just call MergeFrom() and get the desired output.


--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To post to this group, send email to prot...@googlegroups.com.
To unsubscribe from this group, send email to protobuf+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/protobuf?hl=en.


Reply all
Reply to author
Forward
0 new messages