Is there any options to get difference between two protobufs using C++ and protobuf API? For example:
I have two files
1.txt
Config {
OtherField: 42
GoodField: 13
AnotherField: 4200
}
2.txt
Config {
OtherField: 19
GoodField: 13
}
I want to get output like:
Diff:
OtherField - 1.txt: 42
- 2.txt: 19
AnotherField - 1.txt: 4200
- 2.txt: missing
See google::protobuf::util::MessageDifferencer
. Because there's no single definition for the "difference" between two proto messages, MessageDifferencer
comes with a number of ways to customize the comparison, including
IgnoreField
(maybe your message contains a globally unique ID that you don't want to compare)TreatAsSet
- but note that set-like comparison is quadratic in the number of elements!EQUIVALENT
comparison for treating unset fields as though they were set to their default valueOnce you've configured the MessageDifferencer
, use ReportDifferencesTo
or ReportDifferencesToString
to specify how you want to handle the conflicts between the messages, and finally call Compare
to do the actual work of differencing.