| 804 | |
| 805 | template <typename Map> |
| 806 | absl::Status MapValueToJsonObject( |
| 807 | const Map& map, const google::protobuf::DescriptorPool* absl_nonnull descriptor_pool, |
| 808 | google::protobuf::MessageFactory* absl_nonnull message_factory, |
| 809 | google::protobuf::Message* absl_nonnull json) { |
| 810 | ABSL_DCHECK(descriptor_pool != nullptr); |
| 811 | ABSL_DCHECK(message_factory != nullptr); |
| 812 | ABSL_DCHECK(json != nullptr); |
| 813 | ABSL_DCHECK_EQ(json->GetDescriptor()->well_known_type(), |
| 814 | google::protobuf::Descriptor::WELLKNOWNTYPE_STRUCT); |
| 815 | |
| 816 | StructReflection reflection; |
| 817 | CEL_RETURN_IF_ERROR(reflection.Initialize(json->GetDescriptor())); |
| 818 | |
| 819 | json->Clear(); |
| 820 | |
| 821 | if (map.empty()) { |
| 822 | return absl::OkStatus(); |
| 823 | } |
| 824 | |
| 825 | for (const auto& entry : map) { |
| 826 | CEL_ASSIGN_OR_RETURN(auto key, ValueToJsonString(entry.first)); |
| 827 | CEL_RETURN_IF_ERROR(entry.second.ConvertToJson( |
| 828 | descriptor_pool, message_factory, reflection.InsertField(json, key))); |
| 829 | } |
| 830 | return absl::OkStatus(); |
| 831 | } |
| 832 | |
| 833 | template <typename Map> |
| 834 | absl::Status MapValueToJson( |
no test coverage detected