protobuf: Write unset proto2 required message fields
A required field is always present, so the serializers write required
scalars even when they hold the type's default value. A message field
never reached that check: an unset one reads back as a null pointer and
is skipped as empty. A required submessage left unset was therefore
dropped, and a conformant parser rejects the result as missing that
field.
Write a default instance of the submessage instead, created from the
field's metatype. Reading the field through its property getter would
also produce one, but the getter initializes the field in place, which
would modify the message being serialized.
protoc accepts required fields that form a cycle, such as a message
requiring a field of its own type. No finite message satisfies such a
cycle, and filling in defaults would recurse without end, so stop at the
first type that repeats and warn that the output is incomplete.
Task-number: QTBUG-149955
Pick-to: 6.12 6.11 6.8
Change-Id: Icaedc20dc7949443071da8370e70f91550ebb822
Reviewed-by: Tatiana Borisova <tatiana.borisova@qt.io>