MCPcopy Create free account
hub / github.com/cel-expr/cel-cpp / Equals

Method Equals

internal/message_equality.cc:829–873  ·  view source on GitHub ↗

Equality between messages.

Source from the content-addressed store, hash-verified

827
828 // Equality between messages.
829 absl::StatusOr<bool> Equals(const Message& lhs, const Message& rhs) {
830 const auto* lhs_descriptor = lhs.GetDescriptor();
831 const auto* rhs_descriptor = rhs.GetDescriptor();
832 // Deal with well known types, starting with any.
833 auto lhs_well_known_type = lhs_descriptor->well_known_type();
834 auto rhs_well_known_type = rhs_descriptor->well_known_type();
835 const Message* absl_nonnull lhs_ptr = &lhs;
836 const Message* absl_nonnull rhs_ptr = &rhs;
837 Unique<Message> lhs_unpacked;
838 Unique<Message> rhs_unpacked;
839 // Deal with any first. We could in theory check if we should bother
840 // unpacking, but that is more complicated. We can always implement it
841 // later.
842 if (lhs_well_known_type == Descriptor::WELLKNOWNTYPE_ANY) {
843 CEL_ASSIGN_OR_RETURN(
844 lhs_unpacked,
845 well_known_types::UnpackAnyIfResolveable(
846 &arena_, lhs_reflection_.any_reflection, lhs, pool_, factory_));
847 if (lhs_unpacked) {
848 lhs_ptr = cel::to_address(lhs_unpacked);
849 lhs_descriptor = lhs_ptr->GetDescriptor();
850 lhs_well_known_type = lhs_descriptor->well_known_type();
851 }
852 }
853 if (rhs_well_known_type == Descriptor::WELLKNOWNTYPE_ANY) {
854 CEL_ASSIGN_OR_RETURN(
855 rhs_unpacked,
856 well_known_types::UnpackAnyIfResolveable(
857 &arena_, rhs_reflection_.any_reflection, rhs, pool_, factory_));
858 if (rhs_unpacked) {
859 rhs_ptr = cel::to_address(rhs_unpacked);
860 rhs_descriptor = rhs_ptr->GetDescriptor();
861 rhs_well_known_type = rhs_descriptor->well_known_type();
862 }
863 }
864 CEL_ASSIGN_OR_RETURN(
865 auto lhs_value,
866 AsEquatableValue(lhs_reflection_, *lhs_ptr, lhs_descriptor,
867 lhs_well_known_type, lhs_scratch_));
868 CEL_ASSIGN_OR_RETURN(
869 auto rhs_value,
870 AsEquatableValue(rhs_reflection_, *rhs_ptr, rhs_descriptor,
871 rhs_well_known_type, rhs_scratch_));
872 return EquatableValueEquals(lhs_value, rhs_value);
873 }
874
875 // Equality between map message fields.
876 absl::StatusOr<bool> MapFieldEquals(

Callers 1

MessageEqualsFunction · 0.45

Calls 5

UnpackAnyIfResolveableFunction · 0.85
to_addressFunction · 0.85
EquatableValueEqualsFunction · 0.85
CEL_ASSIGN_OR_RETURNFunction · 0.50
GetDescriptorMethod · 0.45

Tested by

no test coverage detected