| 421 | } |
| 422 | |
| 423 | bool Message::postprocessForField(const google::protobuf::FieldDescriptor& fieldDescriptor, |
| 424 | Field& fieldValue, |
| 425 | bool recursive, |
| 426 | IMessageFactory& messageFactory, |
| 427 | ExceptionTracker& exceptionTracker) { |
| 428 | for (;;) { |
| 429 | auto internalFieldType = fieldValue.getInternalType(); |
| 430 | |
| 431 | if (internalFieldType == Field::InternalType::Raw) { |
| 432 | auto raw = fieldValue.getRaw(); |
| 433 | auto childMessage = messageFactory.newMessage(fieldDescriptor.message_type(), _dataSource); |
| 434 | if (!childMessage->decode(raw.data, raw.length, exceptionTracker)) { |
| 435 | return onPopulateFieldError(fieldDescriptor, "Failed to decode", exceptionTracker); |
| 436 | } |
| 437 | |
| 438 | if (recursive) { |
| 439 | if (!childMessage->postprocess(true, messageFactory, exceptionTracker)) { |
| 440 | return onPopulateFieldError(fieldDescriptor, "Failed to populate child messages", exceptionTracker); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | fieldValue.setMessage(childMessage.get()); |
| 445 | } else if (internalFieldType == Field::InternalType::Ref) { |
| 446 | const auto* repeated = fieldValue.getRepeated(); |
| 447 | if (repeated != nullptr) { |
| 448 | // If we parsed the field as a repeated field, |
| 449 | // transform it into a single field |
| 450 | fieldValue = repeated->last(); |
| 451 | // Re-try again now that we have made the field non repeated |
| 452 | continue; |
| 453 | } |
| 454 | |
| 455 | auto* childMessage = fieldValue.getMessage(); |
| 456 | if (childMessage == nullptr) { |
| 457 | return onPopulateFieldError(fieldDescriptor, "Expected message type", exceptionTracker); |
| 458 | } |
| 459 | |
| 460 | if (recursive) { |
| 461 | if (!childMessage->postprocess(true, exceptionTracker)) { |
| 462 | return onPopulateFieldError(fieldDescriptor, "Failed to populate child messages", exceptionTracker); |
| 463 | } |
| 464 | } |
| 465 | } else { |
| 466 | return onPopulateFieldError(fieldDescriptor, "Invalid decoded field type", exceptionTracker); |
| 467 | } |
| 468 | |
| 469 | return true; |
| 470 | } |
| 471 | } |
| 472 | |
| 473 | bool Message::postprocess(bool recursive, ExceptionTracker& exceptionTracker) { |
| 474 | DefaultMessageFactory messageFactory; |
nothing calls this directly
no test coverage detected