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

Function FromLegacyValue

common/legacy_value.cc:1156–1208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1154namespace interop_internal {
1155
1156absl::StatusOr<Value> FromLegacyValue(google::protobuf::Arena* arena,
1157 const CelValue& legacy_value, bool) {
1158 switch (legacy_value.type()) {
1159 case CelValue::Type::kNullType:
1160 return NullValue{};
1161 case CelValue::Type::kBool:
1162 return BoolValue(legacy_value.BoolOrDie());
1163 case CelValue::Type::kInt64:
1164 return IntValue(legacy_value.Int64OrDie());
1165 case CelValue::Type::kUint64:
1166 return UintValue(legacy_value.Uint64OrDie());
1167 case CelValue::Type::kDouble:
1168 return DoubleValue(legacy_value.DoubleOrDie());
1169 case CelValue::Type::kString:
1170 return StringValue(Borrower::Arena(arena),
1171 legacy_value.StringOrDie().value());
1172 case CelValue::Type::kBytes:
1173 return BytesValue(Borrower::Arena(arena),
1174 legacy_value.BytesOrDie().value());
1175 case CelValue::Type::kMessage: {
1176 auto message_wrapper = legacy_value.MessageWrapperOrDie();
1177 return common_internal::LegacyStructValue(
1178 google::protobuf::DownCastMessage<google::protobuf::Message>(
1179 message_wrapper.message_ptr()),
1180 message_wrapper.legacy_type_info());
1181 }
1182 case CelValue::Type::kDuration:
1183 return UnsafeDurationValue(legacy_value.DurationOrDie());
1184 case CelValue::Type::kTimestamp:
1185 return UnsafeTimestampValue(legacy_value.TimestampOrDie());
1186 case CelValue::Type::kList:
1187 return ListValue(
1188 common_internal::LegacyListValue(legacy_value.ListOrDie()));
1189 case CelValue::Type::kMap:
1190 return MapValue(common_internal::LegacyMapValue(legacy_value.MapOrDie()));
1191 case CelValue::Type::kUnknownSet:
1192 return UnknownValue{*legacy_value.UnknownSetOrDie()};
1193 case CelValue::Type::kCelType:
1194 return CreateTypeValueFromView(arena,
1195 legacy_value.CelTypeOrDie().value());
1196 case CelValue::Type::kError:
1197 return ErrorValue(*legacy_value.ErrorOrDie());
1198 case CelValue::Type::kAny:
1199 return absl::InternalError(absl::StrCat(
1200 "illegal attempt to convert special CelValue type ",
1201 CelValue::TypeName(legacy_value.type()), " to cel::Value"));
1202 default:
1203 break;
1204 }
1205 return absl::UnimplementedError(absl::StrCat(
1206 "conversion from CelValue to cel::Value for type ",
1207 CelValue::TypeName(legacy_value.type()), " is not yet implemented"));
1208}
1209
1210absl::StatusOr<google::api::expr::runtime::CelValue> ToLegacyValue(
1211 google::protobuf::Arena* arena, const Value& value, bool) {

Callers 2

TestWrapMessageMethod · 0.85

Calls 15

ArenaFunction · 0.85
UnsafeDurationValueFunction · 0.85
UnsafeTimestampValueFunction · 0.85
CreateTypeValueFromViewFunction · 0.85
ErrorValueFunction · 0.85
typeMethod · 0.80
BoolOrDieMethod · 0.80
Int64OrDieMethod · 0.80
Uint64OrDieMethod · 0.80
DoubleOrDieMethod · 0.80
StringOrDieMethod · 0.80
BytesOrDieMethod · 0.80

Tested by 1

TestWrapMessageMethod · 0.68