| 639 | } |
| 640 | |
| 641 | absl::Status LegacyMapValue::ConvertToJsonObject( |
| 642 | const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
| 643 | google::protobuf::MessageFactory* absl_nonnull message_factory, |
| 644 | google::protobuf::Message* absl_nonnull json) const { |
| 645 | ABSL_DCHECK(descriptor_pool != nullptr); |
| 646 | ABSL_DCHECK(message_factory != nullptr); |
| 647 | ABSL_DCHECK(json != nullptr); |
| 648 | ABSL_DCHECK_EQ(json->GetDescriptor()->well_known_type(), |
| 649 | google::protobuf::Descriptor::WELLKNOWNTYPE_STRUCT); |
| 650 | |
| 651 | google::protobuf::Arena arena; |
| 652 | const google::protobuf::Message* wrapped = |
| 653 | MaybeWrapValueToMessage(json->GetDescriptor(), message_factory, |
| 654 | CelValue::CreateMap(impl_), &arena); |
| 655 | if (wrapped == nullptr) { |
| 656 | return absl::UnknownError("failed to convert legacy map to JSON"); |
| 657 | } |
| 658 | |
| 659 | if (wrapped->GetDescriptor() == json->GetDescriptor()) { |
| 660 | // We can directly use google::protobuf::Message::Copy(). |
| 661 | json->CopyFrom(*wrapped); |
| 662 | } else { |
| 663 | // Equivalent descriptors but not identical. Must serialize and deserialize. |
| 664 | absl::Cord serialized; |
| 665 | if (!wrapped->SerializePartialToString(&serialized)) { |
| 666 | return absl::UnknownError(absl::StrCat("failed to serialize message: ", |
| 667 | wrapped->GetTypeName())); |
| 668 | } |
| 669 | if (!json->ParsePartialFromString(serialized)) { |
| 670 | return absl::UnknownError( |
| 671 | absl::StrCat("failed to parsed message: ", json->GetTypeName())); |
| 672 | } |
| 673 | } |
| 674 | return absl::OkStatus(); |
| 675 | } |
| 676 | |
| 677 | bool LegacyMapValue::IsEmpty() const { return impl_->empty(); } |
| 678 |
nothing calls this directly
no test coverage detected