Zyo
Zyo

Reputation: 2068

How to find "delta" or "diff" between 2 objects using protobuf.net, to track have been changed

I know the question is rather vague, but lets say I have the 2 objects

Object A
{
  Id: 1,
  Title: "Abc",
  Flag: true
}

Object B
{
  Id: 1,
  Title: "",
  Flag: false
}

Is there a way in to find what got changed? Knowing that the title was set to "" (or null is ok) and the Flag was set to false.

All my object are currently serialized with protobuf.net (C#) and I would like to know if there is a "magic" way to do that. The objects have 100+ properties so I would like a way to do not it one by one.

Can we enumerate all properties grammatically and store that in a generic container?

The code is used in a context of synchronizing objects from concurrent users.

Thanks

Upvotes: 1

Views: 576

Answers (1)

Marc Gravell
Marc Gravell

Reputation: 1064054

protobuf-net itself does not track differences - that simply isn't a feature (it has no "context" wrapper to store the before/after state). However, your type can, if it likes, and protobuf-net is able to use "conditional serialization" to only transmit deltas. This is effectively a re-statement of this answer here, which includes a code example of doing this.

Upvotes: 1

Related Questions