| 98 | } |
| 99 | |
| 100 | absl::StatusOr<absl::optional<ErrorValue>> ProtoMessageFromValueImpl( |
| 101 | const Value& value, const google::protobuf::DescriptorPool* absl_nonnull pool, |
| 102 | google::protobuf::MessageFactory* absl_nonnull factory, |
| 103 | well_known_types::Reflection* absl_nonnull well_known_types, |
| 104 | google::protobuf::Message* absl_nonnull message) { |
| 105 | CEL_ASSIGN_OR_RETURN(const auto* to_desc, GetDescriptor(*message)); |
| 106 | switch (to_desc->well_known_type()) { |
| 107 | case google::protobuf::Descriptor::WELLKNOWNTYPE_FLOATVALUE: { |
| 108 | if (auto double_value = value.AsDouble(); double_value) { |
| 109 | CEL_RETURN_IF_ERROR(well_known_types->FloatValue().Initialize( |
| 110 | message->GetDescriptor())); |
| 111 | well_known_types->FloatValue().SetValue( |
| 112 | message, static_cast<float>(double_value->NativeValue())); |
| 113 | return absl::nullopt; |
| 114 | } |
| 115 | return TypeConversionError(value.GetTypeName(), to_desc->full_name()); |
| 116 | } |
| 117 | case google::protobuf::Descriptor::WELLKNOWNTYPE_DOUBLEVALUE: { |
| 118 | if (auto double_value = value.AsDouble(); double_value) { |
| 119 | CEL_RETURN_IF_ERROR(well_known_types->DoubleValue().Initialize( |
| 120 | message->GetDescriptor())); |
| 121 | well_known_types->DoubleValue().SetValue(message, |
| 122 | double_value->NativeValue()); |
| 123 | return absl::nullopt; |
| 124 | } |
| 125 | return TypeConversionError(value.GetTypeName(), to_desc->full_name()); |
| 126 | } |
| 127 | case google::protobuf::Descriptor::WELLKNOWNTYPE_INT32VALUE: { |
| 128 | if (auto int_value = value.AsInt(); int_value) { |
| 129 | if (int_value->NativeValue() < std::numeric_limits<int32_t>::min() || |
| 130 | int_value->NativeValue() > std::numeric_limits<int32_t>::max()) { |
| 131 | return ErrorValue(absl::OutOfRangeError("int64 to int32 overflow")); |
| 132 | } |
| 133 | CEL_RETURN_IF_ERROR(well_known_types->Int32Value().Initialize( |
| 134 | message->GetDescriptor())); |
| 135 | well_known_types->Int32Value().SetValue( |
| 136 | message, static_cast<int32_t>(int_value->NativeValue())); |
| 137 | return absl::nullopt; |
| 138 | } |
| 139 | return TypeConversionError(value.GetTypeName(), to_desc->full_name()); |
| 140 | } |
| 141 | case google::protobuf::Descriptor::WELLKNOWNTYPE_INT64VALUE: { |
| 142 | if (auto int_value = value.AsInt(); int_value) { |
| 143 | CEL_RETURN_IF_ERROR(well_known_types->Int64Value().Initialize( |
| 144 | message->GetDescriptor())); |
| 145 | well_known_types->Int64Value().SetValue(message, |
| 146 | int_value->NativeValue()); |
| 147 | return absl::nullopt; |
| 148 | } |
| 149 | return TypeConversionError(value.GetTypeName(), to_desc->full_name()); |
| 150 | } |
| 151 | case google::protobuf::Descriptor::WELLKNOWNTYPE_UINT32VALUE: { |
| 152 | if (auto uint_value = value.AsUint(); uint_value) { |
| 153 | if (uint_value->NativeValue() > std::numeric_limits<uint32_t>::max()) { |
| 154 | return ErrorValue(absl::OutOfRangeError("uint64 to uint32 overflow")); |
| 155 | } |
| 156 | CEL_RETURN_IF_ERROR(well_known_types->UInt32Value().Initialize( |
| 157 | message->GetDescriptor())); |
no test coverage detected