Search code examples
serializationnullprotocol-buffersdelta

Using google protobuffer for delta messages


I am looking into using Google Protobuffers for delta messaging. Meaning I only want to send out the changed values of my domain object.

But that exposes a problem with the protocol for this purpose. I can easily just omit the properties that have not changed, and that will present us with a compact message.

But what about properties that change value from _something_ to null? There is no way to distinguish between these two scenarios in a protocol buffer.

What have others done here? I am looking at a few different solutions:

  1. Add a meta property to all objects, that is an array of int. In case any of the properties should change to null, include the field number in this array. If no properties change, then the meta property is just omitted and doesn't take up bandwidth in the message.

  2. Add a meta property that is a bit mask, but works like the array mentioned in option 1. This might be harder for clients to understand though.

  3. Use a standard way that I haven't been able to find yet.

BR Jay


Solution

  • Protobuf 3 isn't very well suited for this. But in protobuf 2, you can have a field that is present but has value of null.

    Because protobuf 2 isn't going to disappear any time soon, I'd suggest just use that for this kind of purposes.