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

Function LegacyValue

common/legacy_value.cc:1104–1152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1102}
1103
1104absl::StatusOr<google::api::expr::runtime::CelValue> LegacyValue(
1105 google::protobuf::Arena* arena, const Value& modern_value) {
1106 switch (modern_value.kind()) {
1107 case ValueKind::kNull:
1108 return CelValue::CreateNull();
1109 case ValueKind::kBool:
1110 return CelValue::CreateBool(Cast<BoolValue>(modern_value).NativeValue());
1111 case ValueKind::kInt:
1112 return CelValue::CreateInt64(Cast<IntValue>(modern_value).NativeValue());
1113 case ValueKind::kUint:
1114 return CelValue::CreateUint64(
1115 Cast<UintValue>(modern_value).NativeValue());
1116 case ValueKind::kDouble:
1117 return CelValue::CreateDouble(
1118 Cast<DoubleValue>(modern_value).NativeValue());
1119 case ValueKind::kString:
1120 return CelValue::CreateStringView(common_internal::LegacyStringValue(
1121 modern_value.GetString(), /*stable=*/false, arena));
1122 case ValueKind::kBytes:
1123 return CelValue::CreateBytesView(common_internal::LegacyBytesValue(
1124 modern_value.GetBytes(), /*stable=*/false, arena));
1125 case ValueKind::kStruct:
1126 return common_internal::LegacyTrivialStructValue(arena, modern_value);
1127 case ValueKind::kDuration:
1128 return CelValue::CreateUncheckedDuration(
1129 modern_value.GetDuration().NativeValue());
1130 case ValueKind::kTimestamp:
1131 return CelValue::CreateTimestamp(
1132 modern_value.GetTimestamp().NativeValue());
1133 case ValueKind::kList:
1134 return common_internal::LegacyTrivialListValue(arena, modern_value);
1135 case ValueKind::kMap:
1136 return common_internal::LegacyTrivialMapValue(arena, modern_value);
1137 case ValueKind::kUnknown:
1138 return CelValue::CreateUnknownSet(google::protobuf::Arena::Create<Unknown>(
1139 arena, Cast<UnknownValue>(modern_value).NativeValue()));
1140 case ValueKind::kType:
1141 return CelValue::CreateCelType(
1142 CelValue::CelTypeHolder(google::protobuf::Arena::Create<std::string>(
1143 arena, Cast<TypeValue>(modern_value).NativeValue().name())));
1144 case ValueKind::kError:
1145 return CelValue::CreateError(google::protobuf::Arena::Create<absl::Status>(
1146 arena, Cast<ErrorValue>(modern_value).NativeValue()));
1147 default:
1148 return absl::InvalidArgumentError(
1149 absl::StrCat("google::api::expr::runtime::CelValue does not support ",
1150 ValueKindToString(modern_value.kind())));
1151 }
1152}
1153
1154namespace interop_internal {
1155

Callers

nothing calls this directly

Calls 14

LegacyStringValueFunction · 0.85
LegacyBytesValueFunction · 0.85
LegacyTrivialStructValueFunction · 0.85
LegacyTrivialListValueFunction · 0.85
LegacyTrivialMapValueFunction · 0.85
ValueKindToStringFunction · 0.85
CreateErrorFunction · 0.50
kindMethod · 0.45
NativeValueMethod · 0.45
GetStringMethod · 0.45
GetBytesMethod · 0.45
GetDurationMethod · 0.45

Tested by

no test coverage detected