@@ -578,31 +578,59 @@ bool WireFormat::ParseAndMergeField(
578
578
579
579
case FieldDescriptor::TYPE_GROUP: {
580
580
Message* sub_message;
581
- if (field->is_repeated ()) {
582
- sub_message = message_reflection->AddMessage (
583
- message, field, input->GetExtensionFactory ());
581
+ if (WireFormatLite::GetTagWireType (tag) ==
582
+ WireFormatLite::WIRETYPE_START_GROUP) {
583
+ if (field->is_repeated ()) {
584
+ sub_message = message_reflection->AddMessage (
585
+ message, field, input->GetExtensionFactory ());
586
+ } else {
587
+ sub_message = message_reflection->MutableMessage (
588
+ message, field, input->GetExtensionFactory ());
589
+ }
590
+
591
+ if (!WireFormatLite::ReadGroup (WireFormatLite::GetTagFieldNumber (tag),
592
+ input, sub_message))
593
+ return false ;
584
594
} else {
585
- sub_message = message_reflection->MutableMessage (
586
- message, field, input->GetExtensionFactory ());
587
- }
595
+ if (field->is_repeated ()) {
596
+ sub_message = message_reflection->AddMessage (
597
+ message, field, input->GetExtensionFactory ());
598
+ } else {
599
+ sub_message = message_reflection->MutableMessage (
600
+ message, field, input->GetExtensionFactory ());
601
+ }
588
602
589
- if (!WireFormatLite::ReadGroup (WireFormatLite::GetTagFieldNumber (tag),
590
- input, sub_message))
591
- return false ;
603
+ if (!WireFormatLite::ReadMessage (input, sub_message)) return false ;
604
+ }
592
605
break ;
593
606
}
594
607
595
608
case FieldDescriptor::TYPE_MESSAGE: {
596
609
Message* sub_message;
597
- if (field->is_repeated ()) {
598
- sub_message = message_reflection->AddMessage (
599
- message, field, input->GetExtensionFactory ());
610
+ if (WireFormatLite::GetTagWireType (tag) ==
611
+ WireFormatLite::WIRETYPE_START_GROUP) {
612
+ if (field->is_repeated ()) {
613
+ sub_message = message_reflection->AddMessage (
614
+ message, field, input->GetExtensionFactory ());
615
+ } else {
616
+ sub_message = message_reflection->MutableMessage (
617
+ message, field, input->GetExtensionFactory ());
618
+ }
619
+
620
+ if (!WireFormatLite::ReadGroup (WireFormatLite::GetTagFieldNumber (tag),
621
+ input, sub_message))
622
+ return false ;
600
623
} else {
601
- sub_message = message_reflection->MutableMessage (
602
- message, field, input->GetExtensionFactory ());
603
- }
624
+ if (field->is_repeated ()) {
625
+ sub_message = message_reflection->AddMessage (
626
+ message, field, input->GetExtensionFactory ());
627
+ } else {
628
+ sub_message = message_reflection->MutableMessage (
629
+ message, field, input->GetExtensionFactory ());
630
+ }
604
631
605
- if (!WireFormatLite::ReadMessage (input, sub_message)) return false ;
632
+ if (!WireFormatLite::ReadMessage (input, sub_message)) return false ;
633
+ }
606
634
break ;
607
635
}
608
636
}
@@ -997,19 +1025,59 @@ const char* WireFormat::_InternalParseAndMergeField(
997
1025
998
1026
case FieldDescriptor::TYPE_GROUP: {
999
1027
Message* sub_message;
1000
- if (field->is_repeated ()) {
1001
- sub_message = reflection->AddMessage (msg, field, ctx->data ().factory );
1028
+
1029
+ if (WireFormatLite::GetTagWireType (tag) ==
1030
+ WireFormatLite::WIRETYPE_START_GROUP) {
1031
+ if (field->is_repeated ()) {
1032
+ sub_message = reflection->AddMessage (msg, field, ctx->data ().factory );
1033
+ } else {
1034
+ sub_message =
1035
+ reflection->MutableMessage (msg, field, ctx->data ().factory );
1036
+ }
1037
+
1038
+ return ctx->ParseGroup (sub_message, ptr, tag);
1002
1039
} else {
1003
- sub_message =
1004
- reflection->MutableMessage (msg, field, ctx->data ().factory );
1005
- }
1040
+ if (field->is_repeated ()) {
1041
+ sub_message = reflection->AddMessage (msg, field, ctx->data ().factory );
1042
+ } else {
1043
+ sub_message =
1044
+ reflection->MutableMessage (msg, field, ctx->data ().factory );
1045
+ }
1046
+ ptr = ctx->ParseMessage (sub_message, ptr);
1047
+
1048
+ // For map entries, if the value is an unknown enum we have to push it
1049
+ // into the unknown field set and remove it from the list.
1050
+ if (ptr != nullptr && field->is_map ()) {
1051
+ auto * value_field = field->message_type ()->map_value ();
1052
+ auto * enum_type = value_field->enum_type ();
1053
+ if (enum_type != nullptr &&
1054
+ !internal::cpp::HasPreservingUnknownEnumSemantics (value_field) &&
1055
+ enum_type->FindValueByNumber (
1056
+ sub_message->GetReflection ()->GetEnumValue (
1057
+ *sub_message, value_field)) == nullptr ) {
1058
+ reflection->MutableUnknownFields (msg)->AddLengthDelimited (
1059
+ field->number (), sub_message->SerializeAsString ());
1060
+ reflection->RemoveLast (msg, field);
1061
+ }
1062
+ }
1006
1063
1007
- return ctx->ParseGroup (sub_message, ptr, tag);
1064
+ return ptr;
1065
+ }
1008
1066
}
1009
1067
1010
1068
case FieldDescriptor::TYPE_MESSAGE: {
1011
1069
Message* sub_message;
1012
- if (field->is_repeated ()) {
1070
+ if (WireFormatLite::GetTagWireType (tag) ==
1071
+ WireFormatLite::WIRETYPE_START_GROUP) {
1072
+ if (field->is_repeated ()) {
1073
+ sub_message = reflection->AddMessage (msg, field, ctx->data ().factory );
1074
+ } else {
1075
+ sub_message =
1076
+ reflection->MutableMessage (msg, field, ctx->data ().factory );
1077
+ }
1078
+
1079
+ return ctx->ParseGroup (sub_message, ptr, tag);
1080
+ } else if (field->is_repeated ()) {
1013
1081
sub_message = reflection->AddMessage (msg, field, ctx->data ().factory );
1014
1082
} else {
1015
1083
sub_message =
0 commit comments