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

Method ConvertToJson

common/legacy_value.cc:431–468  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

429}
430
431absl::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
470absl::Status LegacyListValue::ConvertToJsonArray(
471 const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool,

Callers

nothing calls this directly

Calls 9

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

Tested by

no test coverage detected