Fix optional field check to exclude required fields in proto2
isOptionalField() reported proto2 required fields as optional, because
has_presence() is true for required and optional fields alike. Required
fields were therefore generated with std::optional storage and
hasX()/clearX() accessors, which does not match their semantics: a
required field is always present.
Check is_required() to exclude them. Required fields then carry no
presence flag, so mark them with FieldFlag::Required to keep the
serializers emitting them when they hold the type's default value.
Without that, a message whose required fields are all default-valued
serializes to nothing, and a conformant parser rejects it as missing
those fields.
Cover the generated property set for all three proto2 labels here.
Repeated fields need no check of their own: has_presence() returns false
for them unconditionally, so isOptionalField() already excluded them,
and the test pins that. The resulting encoding is covered by the proto2
serialization test in a following change, because a golden-file test
records whatever the generator emits and cannot detect a wire-format
change.
[ChangeLog][QtProtobuf] proto2 required fields are now always written to
the wire. A required field holding its type's default value used to be
omitted, producing a message that conformant parsers reject as missing
that field.
[ChangeLog][Potentially Source-Incompatible Changes][QtProtobuf]
Generated proto2 required fields no longer provide hasX() and clearX()
and are no longer stored as std::optional. A required field is always
present, so the presence API never applied to it.
Fixes: QTBUG-149955
Pick-to: 6.12 6.8
Change-Id: I12602ce8f74ef3f81ac1e8026500afcaa172f25e
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>