Skip to content

Commit 9ad16da

Browse files
maskri17copybara-github
authored andcommitted
Map well-known protobuf types to their CEL equivalents in LegacyRuntimeType.
PiperOrigin-RevId: 919297884
1 parent a552526 commit 9ad16da

3 files changed

Lines changed: 81 additions & 1 deletion

File tree

common/BUILD

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -583,7 +583,6 @@ cc_library(
583583
"//internal:string_pool",
584584
"@com_google_absl//absl/algorithm:container",
585585
"@com_google_absl//absl/base:core_headers",
586-
"@com_google_absl//absl/base:no_destructor",
587586
"@com_google_absl//absl/base:nullability",
588587
"@com_google_absl//absl/container:flat_hash_map",
589588
"@com_google_absl//absl/container:flat_hash_set",

common/type.cc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,53 @@ Type LegacyRuntimeType(absl::string_view name) {
685685
if (name == kCelTypeTypeName) {
686686
return TypeType{};
687687
}
688+
if (cel::IsWellKnownMessageType(name)) {
689+
if (name == "google.protobuf.Any") {
690+
return AnyType();
691+
}
692+
if (name == "google.protobuf.BoolValue") {
693+
return BoolWrapperType();
694+
}
695+
if (name == "google.protobuf.BytesValue") {
696+
return BytesWrapperType();
697+
}
698+
if (name == "google.protobuf.DoubleValue") {
699+
return DoubleWrapperType();
700+
}
701+
if (name == "google.protobuf.Duration") {
702+
return DurationType();
703+
}
704+
if (name == "google.protobuf.FloatValue") {
705+
return DoubleWrapperType();
706+
}
707+
if (name == "google.protobuf.Int32Value") {
708+
return IntWrapperType();
709+
}
710+
if (name == "google.protobuf.Int64Value") {
711+
return IntWrapperType();
712+
}
713+
if (name == "google.protobuf.ListValue") {
714+
return ListType();
715+
}
716+
if (name == "google.protobuf.StringValue") {
717+
return StringWrapperType();
718+
}
719+
if (name == "google.protobuf.Struct") {
720+
return JsonMapType();
721+
}
722+
if (name == "google.protobuf.Timestamp") {
723+
return TimestampType();
724+
}
725+
if (name == "google.protobuf.UInt32Value") {
726+
return UintWrapperType();
727+
}
728+
if (name == "google.protobuf.UInt64Value") {
729+
return UintWrapperType();
730+
}
731+
if (name == "google.protobuf.Value") {
732+
return DynType();
733+
}
734+
}
688735
return common_internal::MakeBasicStructType(name);
689736
}
690737

common/type_test.cc

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -638,5 +638,39 @@ TEST(Type, Wrap) {
638638
EXPECT_EQ(Type(AnyType()).Wrap(), AnyType());
639639
}
640640

641+
TEST(Type, LegacyRuntimeType) {
642+
EXPECT_EQ(common_internal::LegacyRuntimeType("bool"), BoolType());
643+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.Any"),
644+
AnyType());
645+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.BoolValue"),
646+
BoolWrapperType());
647+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.BytesValue"),
648+
BytesWrapperType());
649+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.DoubleValue"),
650+
DoubleWrapperType());
651+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.Duration"),
652+
DurationType());
653+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.FloatValue"),
654+
DoubleWrapperType());
655+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.Int32Value"),
656+
IntWrapperType());
657+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.Int64Value"),
658+
IntWrapperType());
659+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.ListValue"),
660+
ListType());
661+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.StringValue"),
662+
StringWrapperType());
663+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.Struct"),
664+
JsonMapType());
665+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.Timestamp"),
666+
TimestampType());
667+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.UInt32Value"),
668+
UintWrapperType());
669+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.UInt64Value"),
670+
UintWrapperType());
671+
EXPECT_EQ(common_internal::LegacyRuntimeType("google.protobuf.Value"),
672+
DynType());
673+
}
674+
641675
} // namespace
642676
} // namespace cel

0 commit comments

Comments
 (0)