| 351 | } // namespace |
| 352 | |
| 353 | google::api::expr::runtime::CelValue UnsafeLegacyValue( |
| 354 | const Value& value, bool stable, google::protobuf::Arena* absl_nonnull arena) { |
| 355 | switch (value.kind()) { |
| 356 | case ValueKind::kNull: |
| 357 | return CelValue::CreateNull(); |
| 358 | case ValueKind::kBool: |
| 359 | return CelValue::CreateBool(value.GetBool()); |
| 360 | case ValueKind::kInt: |
| 361 | return CelValue::CreateInt64(value.GetInt()); |
| 362 | case ValueKind::kUint: |
| 363 | return CelValue::CreateUint64(value.GetUint()); |
| 364 | case ValueKind::kDouble: |
| 365 | return CelValue::CreateDouble(value.GetDouble()); |
| 366 | case ValueKind::kString: |
| 367 | return CelValue::CreateStringView( |
| 368 | LegacyStringValue(value.GetString(), stable, arena)); |
| 369 | case ValueKind::kBytes: |
| 370 | return CelValue::CreateBytesView( |
| 371 | LegacyBytesValue(value.GetBytes(), stable, arena)); |
| 372 | case ValueKind::kStruct: |
| 373 | return LegacyTrivialStructValue(arena, value); |
| 374 | case ValueKind::kDuration: |
| 375 | return CelValue::CreateDuration(value.GetDuration().ToDuration()); |
| 376 | case ValueKind::kTimestamp: |
| 377 | return CelValue::CreateTimestamp(value.GetTimestamp().ToTime()); |
| 378 | case ValueKind::kList: |
| 379 | return LegacyTrivialListValue(arena, value); |
| 380 | case ValueKind::kMap: |
| 381 | return LegacyTrivialMapValue(arena, value); |
| 382 | case ValueKind::kType: |
| 383 | return CelValue::CreateCelTypeView(value.GetType().name()); |
| 384 | default: |
| 385 | // Everything else is unsupported. |
| 386 | return CelValue::CreateError(google::protobuf::Arena::Create<absl::Status>( |
| 387 | arena, absl::InvalidArgumentError(absl::StrCat( |
| 388 | "unsupported conversion from cel::Value to CelValue: ", |
| 389 | value->GetRuntimeType().DebugString())))); |
| 390 | } |
| 391 | } |
| 392 | |
| 393 | } // namespace common_internal |
| 394 |
no test coverage detected