qtgrpc/tests
Alexey Edelev 2e3fdd5c05 Add support for the 'oneof' type
This patch adds support for 'oneof', a union-like type in protobuf,
that need not contain a value, with the following features:
 - Setting a oneof field will automatically clear all other
   members of the oneof.
 - If the parser encounters multiple members of the same oneof
   on the wire, only the last member seen is used in the
   parsed message.
 - A oneof cannot be repeated.
 - A oneof cannot contain repeated or map fields.
 - If you set a oneof field to the default value (even the default,
   such as 0 for an int32 oneof field), the "case" of that oneof
   field will be set, and the value will be serialized on the
   wire.

Unlike the reference C++ implementation, the Qt implementation of
'oneof' fields adds the 'has<PropertyName>' functions for every
'oneof' member. The protobuf generator generates a Q_PROPERTY for each
member of the 'oneof'; these properties are collectively implemented
as a single class member.

'oneof' fields are represented by the
QtProtobufPrivate::QProtobufOptional class. The class holds the 'oneof'
field number and the value that it contains as QVariant.
A QExplicitSharedDataPointer is used as reference counter, and to copy
and to free the memory of protobuf messages that are stored inside the
nested QVariant as pointers.

The class could also be used to hold 'optional' fields in follow up
commits, but has small overhead since it holds field number, that
is not used by optional fields.

The generated classes also allows reading field number that is
currently stored in the 'oneof' field.
The QtProtobuf::InvalidFieldNumber constant indicates that oneof fields
is uninitialized.

The serialization and deserialization tests use the expected values
from the results of the reference C++ serialization(protobuf version
3.19).

Task-number: QTBUG-103981
Change-Id: Ie4053cb164bba6bc5f14f8cedb34bad62a638c43
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
2023-02-23 12:48:57 +01:00
..
auto Add support for the 'oneof' type 2023-02-23 12:48:57 +01:00
manual/qprotobuf Rename qtprotobufgen options 2022-12-07 12:29:45 +01:00
CMakeLists.txt Introduce QtGrpc 2022-12-09 15:00:04 +01:00