aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/google/protobuf/util/message_differencer.cc
diff options
context:
space:
mode:
authorGravatar Jisi Liu <jisi.liu@gmail.com>2015-10-05 11:59:43 -0700
committerGravatar Jisi Liu <jisi.liu@gmail.com>2015-10-05 11:59:43 -0700
commit46e8ff63cb67a6520711da5317aaaef04d0414d0 (patch)
tree64370726fe469f8dfca7b14f8b8cb80b6cc856f6 /src/google/protobuf/util/message_differencer.cc
parent0087da9d4775f79c67362cc89c653f3a33a9bae2 (diff)
Down-integrate from google internal.
Diffstat (limited to 'src/google/protobuf/util/message_differencer.cc')
-rw-r--r--src/google/protobuf/util/message_differencer.cc52
1 files changed, 43 insertions, 9 deletions
diff --git a/src/google/protobuf/util/message_differencer.cc b/src/google/protobuf/util/message_differencer.cc
index d709da57..9a268973 100644
--- a/src/google/protobuf/util/message_differencer.cc
+++ b/src/google/protobuf/util/message_differencer.cc
@@ -946,6 +946,18 @@ bool MessageDifferencer::IsIgnored(
return false;
}
+bool MessageDifferencer::IsUnknownFieldIgnored(
+ const Message& message1, const Message& message2,
+ const SpecificField& field, const vector<SpecificField>& parent_fields) {
+ for (int i = 0; i < ignore_criteria_.size(); ++i) {
+ if (ignore_criteria_[i]->IsUnknownFieldIgnored(message1, message2, field,
+ parent_fields)) {
+ return true;
+ }
+ }
+ return false;
+}
+
const MessageDifferencer::MapKeyComparator* MessageDifferencer
::GetMapKeyComparator(const FieldDescriptor* field) {
if (!field->is_repeated()) return NULL;
@@ -1127,15 +1139,6 @@ bool MessageDifferencer::CompareUnknownFields(
continue;
}
- if (change_type == ADDITION || change_type == DELETION ||
- change_type == MODIFICATION) {
- if (reporter_ == NULL) {
- // We found a difference and we have no reproter.
- return false;
- }
- is_different = true;
- }
-
// Build the SpecificField. This is slightly complicated.
SpecificField specific_field;
specific_field.unknown_field_number = focus_field->number();
@@ -1160,6 +1163,25 @@ bool MessageDifferencer::CompareUnknownFields(
specific_field.new_index = index2 - current_repeated_start2;
}
+ if (IsUnknownFieldIgnored(message1, message2, specific_field,
+ *parent_field)) {
+ if (reporter_ != NULL) {
+ parent_field->push_back(specific_field);
+ reporter_->ReportUnknownFieldIgnored(message1, message2, *parent_field);
+ parent_field->pop_back();
+ }
+ return true;
+ }
+
+ if (change_type == ADDITION || change_type == DELETION ||
+ change_type == MODIFICATION) {
+ if (reporter_ == NULL) {
+ // We found a difference and we have no reproter.
+ return false;
+ }
+ is_different = true;
+ }
+
parent_field->push_back(specific_field);
switch (change_type) {
@@ -1625,6 +1647,18 @@ void MessageDifferencer::StreamReporter::ReportIgnored(
printer_->Print("\n"); // Print for newlines.
}
+void MessageDifferencer::StreamReporter::ReportUnknownFieldIgnored(
+ const Message& message1, const Message& message2,
+ const vector<SpecificField>& field_path) {
+ printer_->Print("ignored: ");
+ PrintPath(field_path, true);
+ if (CheckPathChanged(field_path)) {
+ printer_->Print(" -> ");
+ PrintPath(field_path, false);
+ }
+ printer_->Print("\n"); // Print for newlines.
+}
+
} // namespace util
} // namespace protobuf
} // namespace google