| 429 | } |
| 430 | |
| 431 | absl::Status LegacyListValue::ConvertToJson( |
| 432 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
| 433 | google::protobuf::MessageFactory* absl_nonnull message_factory, |
| 434 | google::protobuf::Message* absl_nonnull json) const { |
| 435 | { |
| 436 | ABSL_DCHECK(descriptor_pool != nullptr); |
| 437 | ABSL_DCHECK(message_factory != nullptr); |
| 438 | ABSL_DCHECK(json != nullptr); |
| 439 | ABSL_DCHECK_EQ(json->GetDescriptor()->well_known_type(), |
| 440 | google::protobuf::Descriptor::WELLKNOWNTYPE_VALUE); |
| 441 | |
| 442 | google::protobuf::Arena arena; |
| 443 | const google::protobuf::Message* wrapped = |
| 444 | MaybeWrapValueToMessage(json->GetDescriptor(), message_factory, |
| 445 | CelValue::CreateList(impl_), &arena); |
| 446 | if (wrapped == nullptr) { |
| 447 | return absl::UnknownError("failed to convert legacy list to JSON"); |
| 448 | } |
| 449 | |
| 450 | if (wrapped->GetDescriptor() == json->GetDescriptor()) { |
| 451 | // We can directly use google::protobuf::Message::Copy(). |
| 452 | json->CopyFrom(*wrapped); |
| 453 | } else { |
| 454 | // Equivalent descriptors but not identical. Must serialize and |
| 455 | // deserialize. |
| 456 | absl::Cord serialized; |
| 457 | if (!wrapped->SerializePartialToString(&serialized)) { |
| 458 | return absl::UnknownError(absl::StrCat("failed to serialize message: ", |
| 459 | wrapped->GetTypeName())); |
| 460 | } |
| 461 | if (!json->ParsePartialFromString(serialized)) { |
| 462 | return absl::UnknownError( |
| 463 | absl::StrCat("failed to parsed message: ", json->GetTypeName())); |
| 464 | } |
| 465 | } |
| 466 | return absl::OkStatus(); |
| 467 | } |
| 468 | } |
| 469 | |
| 470 | absl::Status LegacyListValue::ConvertToJsonArray( |
| 471 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
nothing calls this directly
no test coverage detected