| 1071 | } |
| 1072 | |
| 1073 | absl::StatusOr<bool> FieldEquals( |
| 1074 | const Message& lhs, const FieldDescriptor* absl_nullable lhs_field, |
| 1075 | const Message& rhs, const FieldDescriptor* absl_nullable rhs_field) { |
| 1076 | ABSL_DCHECK(lhs_field != nullptr || |
| 1077 | rhs_field != nullptr); // Both cannot be null. |
| 1078 | if (lhs_field != nullptr && lhs_field->is_map()) { |
| 1079 | // map<?, ?> == map<?, ?> |
| 1080 | // map<?, ?> == google.protobuf.Value |
| 1081 | // map<?, ?> == google.protobuf.Struct |
| 1082 | // map<?, ?> == google.protobuf.Any |
| 1083 | |
| 1084 | // Right hand side should be a map, `google.protobuf.Value`, |
| 1085 | // `google.protobuf.Struct`, or `google.protobuf.Any`. |
| 1086 | if (rhs_field != nullptr && rhs_field->is_map()) { |
| 1087 | // map<?, ?> == map<?, ?> |
| 1088 | return MapFieldEquals(lhs, lhs_field, rhs, rhs_field); |
| 1089 | } |
| 1090 | if (rhs_field != nullptr && |
| 1091 | (rhs_field->is_repeated() || |
| 1092 | rhs_field->type() != FieldDescriptor::TYPE_MESSAGE)) { |
| 1093 | return false; |
| 1094 | } |
| 1095 | const Message* absl_nullable rhs_packed = nullptr; |
| 1096 | Unique<Message> rhs_unpacked; |
| 1097 | if (rhs_field != nullptr && IsAnyField(rhs_field)) { |
| 1098 | rhs_packed = &rhs.GetReflection()->GetMessage(rhs, rhs_field); |
| 1099 | } else if (rhs_field == nullptr && IsAny(rhs)) { |
| 1100 | rhs_packed = &rhs; |
| 1101 | } |
| 1102 | if (rhs_packed != nullptr) { |
| 1103 | CEL_RETURN_IF_ERROR(rhs_reflection_.any_reflection.Initialize( |
| 1104 | rhs_packed->GetDescriptor())); |
| 1105 | auto rhs_type_url = rhs_reflection_.any_reflection.GetTypeUrl( |
| 1106 | *rhs_packed, rhs_scratch_); |
| 1107 | if (!rhs_type_url.ConsumePrefix("type.googleapis.com/") && |
| 1108 | !rhs_type_url.ConsumePrefix("type.googleprod.com/")) { |
| 1109 | return false; |
| 1110 | } |
| 1111 | if (rhs_type_url != "google.protobuf.Value" && |
| 1112 | rhs_type_url != "google.protobuf.Struct" && |
| 1113 | rhs_type_url != "google.protobuf.Any") { |
| 1114 | return false; |
| 1115 | } |
| 1116 | CEL_ASSIGN_OR_RETURN(rhs_unpacked, |
| 1117 | well_known_types::UnpackAnyIfResolveable( |
| 1118 | &arena_, rhs_reflection_.any_reflection, |
| 1119 | *rhs_packed, pool_, factory_)); |
| 1120 | if (rhs_unpacked) { |
| 1121 | rhs_field = nullptr; |
| 1122 | } |
| 1123 | } |
| 1124 | const Message* absl_nonnull rhs_message = |
| 1125 | rhs_field != nullptr |
| 1126 | ? &rhs.GetReflection()->GetMessage(rhs, rhs_field) |
| 1127 | : rhs_unpacked != nullptr ? cel::to_address(rhs_unpacked) |
| 1128 | : &rhs; |
| 1129 | const auto* rhs_descriptor = rhs_message->GetDescriptor(); |
| 1130 | const auto rhs_well_known_type = rhs_descriptor->well_known_type(); |
no test coverage detected