Message diff and merge

7 views
Skip to first unread message

Igor Yudnikov

unread,
Nov 23, 2018, 8:52:59 AM11/23/18
to ScalaPB
Is there any functionality to do this with generated models?

Nadav Samet

unread,
Nov 23, 2018, 1:30:36 PM11/23/18
to igoryu...@gmail.com, sca...@googlegroups.com
Hi Igor,

We don't have message diffing functionality, but since these are just case classes you might find some generic solution that fits your needs such as https://github.com/xdotai/diff.

Merging is also not directly supported, but it is possible with the following:

a.mergeFrom(CodedInputStream.newInstance(b.toByteArray))

This would add the values from b on top of the values of a, overriding any existing optional and required fields, and concatenating repeated fields. The downside is that "b" gets serialized and deserialized in the process, so with some work, this can be made more performant.

-Nadav


On Fri, Nov 23, 2018 at 5:53 AM Igor Yudnikov <igoryu...@gmail.com> wrote:
Is there any functionality to do this with generated models?

--
You received this message because you are subscribed to the Google Groups "ScalaPB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalapb+u...@googlegroups.com.
To post to this group, send email to sca...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalapb/55164e4b-285d-4bf4-b87a-ecf96b2960ec%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
-Nadav

Igor Yudnikov

unread,
Nov 23, 2018, 3:56:23 PM11/23/18
to ScalaPB
Thanks, Nadav! Your library is really awesome! A bit complicated setup for sbt especially with multiple projects, and external jar dependencies, but it's because of sbt, and in general I like working with scalapb much.
Now I've implemented diff and merge as implicit class extensions for PMessage. Also I've done method isDefault to define contains PValue default value (natural zero value) or not. At all about 50 lines of code :) Did not measured the performance yet.
Will take a look at your recommendations. Thank you! 

пятница, 23 ноября 2018 г., 21:30:36 UTC+3 пользователь Nadav Samet написал:
Reply all
Reply to author
Forward
0 new messages