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

Method ConvertToJsonObject

common/legacy_value.cc:641–675  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

639}
640
641absl::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
677bool LegacyMapValue::IsEmpty() const { return impl_->empty(); }
678

Callers

nothing calls this directly

Calls 8

MaybeWrapValueToMessageFunction · 0.85
AsMessageWrapperFunction · 0.85
MessageToJsonFunction · 0.85
CopyFromMethod · 0.80
message_ptrMethod · 0.80
CreateMapFunction · 0.50
GetDescriptorMethod · 0.45
GetTypeNameMethod · 0.45

Tested by

no test coverage detected