| 347 | } |
| 348 | |
| 349 | std::string ProtoField::get() const |
| 350 | { |
| 351 | const auto* reflection = _message->GetReflection(); |
| 352 | if (_field->is_repeated()) |
| 353 | { |
| 354 | if (_index == -1) |
| 355 | error("field '{}' is repeated but no index is provided", |
| 356 | _field->name()); |
| 357 | |
| 358 | switch (_field->type()) |
| 359 | { |
| 360 | case google::protobuf::FieldDescriptor::TYPE_FLOAT: |
| 361 | return fmt::format("{:g}", |
| 362 | reflection->GetRepeatedFloat(*_message, _field, _index)); |
| 363 | |
| 364 | case google::protobuf::FieldDescriptor::TYPE_DOUBLE: |
| 365 | return fmt::format("{:g}", |
| 366 | reflection->GetRepeatedDouble(*_message, _field, _index)); |
| 367 | |
| 368 | case google::protobuf::FieldDescriptor::TYPE_INT32: |
| 369 | return std::to_string( |
| 370 | reflection->GetRepeatedInt32(*_message, _field, _index)); |
| 371 | |
| 372 | case google::protobuf::FieldDescriptor::TYPE_INT64: |
| 373 | return std::to_string( |
| 374 | reflection->GetRepeatedInt64(*_message, _field, _index)); |
| 375 | |
| 376 | case google::protobuf::FieldDescriptor::TYPE_UINT32: |
| 377 | return std::to_string( |
| 378 | reflection->GetRepeatedUInt32(*_message, _field, _index)); |
| 379 | |
| 380 | case google::protobuf::FieldDescriptor::TYPE_UINT64: |
| 381 | return std::to_string( |
| 382 | reflection->GetRepeatedUInt64(*_message, _field, _index)); |
| 383 | |
| 384 | case google::protobuf::FieldDescriptor::TYPE_STRING: |
| 385 | return reflection->GetRepeatedString(*_message, _field, _index); |
| 386 | |
| 387 | case google::protobuf::FieldDescriptor::TYPE_MESSAGE: |
| 388 | error("'{}' is a message and can't be directly fetched", |
| 389 | _field->name()); |
| 390 | |
| 391 | default: |
| 392 | error("unknown field type when fetching repeated field '{}'", |
| 393 | _field->name()); |
| 394 | } |
| 395 | } |
| 396 | else |
| 397 | { |
| 398 | if (_index != -1) |
| 399 | error("field '{}' is not repeated but an index is provided", |
| 400 | _field->name()); |
| 401 | switch (_field->type()) |
| 402 | { |
| 403 | case google::protobuf::FieldDescriptor::TYPE_FLOAT: |
| 404 | return fmt::format( |
| 405 | "{:g}", reflection->GetFloat(*_message, _field)); |
| 406 |
no test coverage detected