MCPcopy Create free account
hub / github.com/Snapchat/Valdi / postprocessForField

Method postprocessForField

valdi_protobuf/src/valdi_protobuf/Message.cpp:423–471  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

421}
422
423bool 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
473bool Message::postprocess(bool recursive, ExceptionTracker& exceptionTracker) {
474 DefaultMessageFactory messageFactory;

Callers

nothing calls this directly

Calls 11

onPopulateFieldErrorFunction · 0.85
getInternalTypeMethod · 0.80
getRawMethod · 0.80
setMessageMethod · 0.80
getRepeatedMethod · 0.80
lastMethod · 0.80
decodeMethod · 0.65
getMethod · 0.65
getMessageMethod · 0.65
newMessageMethod · 0.45
postprocessMethod · 0.45

Tested by

no test coverage detected