| 256 | } |
| 257 | |
| 258 | bool ValueToProtoMapKey(const Value& key, |
| 259 | google::protobuf::FieldDescriptor::CppType cpp_type, |
| 260 | google::protobuf::MapKey* absl_nonnull proto_key, |
| 261 | std::string& proto_key_scratch) { |
| 262 | switch (cpp_type) { |
| 263 | case google::protobuf::FieldDescriptor::CPPTYPE_BOOL: { |
| 264 | if (auto bool_key = key.AsBool(); bool_key) { |
| 265 | proto_key->SetBoolValue(bool_key->NativeValue()); |
| 266 | return true; |
| 267 | } |
| 268 | return false; |
| 269 | } |
| 270 | case google::protobuf::FieldDescriptor::CPPTYPE_INT32: { |
| 271 | if (auto int_key = ValueAsInt32(key); int_key) { |
| 272 | proto_key->SetInt32Value(*int_key); |
| 273 | return true; |
| 274 | } |
| 275 | return false; |
| 276 | } |
| 277 | case google::protobuf::FieldDescriptor::CPPTYPE_INT64: { |
| 278 | if (auto int_key = ValueAsInt64(key); int_key) { |
| 279 | proto_key->SetInt64Value(*int_key); |
| 280 | return true; |
| 281 | } |
| 282 | return false; |
| 283 | } |
| 284 | case google::protobuf::FieldDescriptor::CPPTYPE_UINT32: { |
| 285 | if (auto int_key = ValueAsUInt32(key); int_key) { |
| 286 | proto_key->SetUInt32Value(*int_key); |
| 287 | return true; |
| 288 | } |
| 289 | return false; |
| 290 | } |
| 291 | case google::protobuf::FieldDescriptor::CPPTYPE_UINT64: { |
| 292 | if (auto int_key = ValueAsUInt64(key); int_key) { |
| 293 | proto_key->SetUInt64Value(*int_key); |
| 294 | return true; |
| 295 | } |
| 296 | return false; |
| 297 | } |
| 298 | case google::protobuf::FieldDescriptor::CPPTYPE_STRING: { |
| 299 | if (auto string_key = key.AsString(); string_key) { |
| 300 | proto_key_scratch = string_key->NativeString(); |
| 301 | proto_key->SetStringValue(proto_key_scratch); |
| 302 | return true; |
| 303 | } |
| 304 | return false; |
| 305 | } |
| 306 | default: |
| 307 | // protobuf map keys can only be bool, integrals, or string. |
| 308 | return false; |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | } // namespace |
| 313 |
no test coverage detected