Reputation: 14462
I want to compare two arbitrary google::protobuf::Message
objects.
I assume that objects are equal when
I know, that I can write such comparison function by myself, but may be there is already some simple or predefined solution?
Also, may be I'm missing some principal issue about incomparability of such objects - I would like to know if it's so.
Upvotes: 26
Views: 22124
Reputation: 396
My experience has shown me that the comparison depends on the message structure. If you have a deep tree like message structure then do not compare if you have to be finished quickly.
For example I have a 7 nodes deep structure (don't ask why) but it would be a bed idea for me to compare field by field.
One tick you can use is to get sizes of the repeated fields and compare them. But you are sill dependent on the message structure and size.
Upvotes: 0
Reputation: 693
You can use google::protobuf::util::MessageDifferencer for this. Take a look at my answer here.
Upvotes: 11
Reputation:
From https://groups.google.com/d/msg/protobuf/5sOExQkB2eQ/ZSBNZI0K54YJ:
In C++, you could serialize the two and compare the bytes. Alternatively, you could write some code that iterates over the fields via reflection and compares them.
Upvotes: 9