mirror of https://github.com/qt/qtgrpc.git
Implement support of 'optional' fields
'optional' fields is the legacy mechanism from 'proto2' times. In 'proto3' schemes this keyword changes the 'presence' handling of the fields that are marked as 'optional'. By default protobuf messages(serializer to be precise) treat all fields as optional. This means that if field has the default value(0, 0.0f, false, nullptr) the field will not be serialized at all. This mechanism can be overwritten using the 'optional' attribute or keyword. If the message field is marked as 'optional' it gets the following methods in addition to the regular field one: - clear<fieldName> - has<fieldName> These methods allow to clear the value and to check whether the field was ever set. The optional fields get serialized if they were explicitly set in the message, even if they have the default value. This is the key difference that this attribute/keyword makes on the serialization process. [ChangeLog][QtProtobuf] All message fieds now have 'has' methods that indicate if message was initialized and contain value or not. Task-number: QTBUG-103978 Change-Id: Ia948be85486175bb2d81357352f5c04da12af846 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Konrad Kujawa <konrad.kujawa@qt.io>
This commit is contained in:
parent
da5a32e7c4
commit
913aef61d8
|
|
@ -238,7 +238,8 @@ QProtobufMessage::property(const QtProtobufPrivate::QProtobufPropertyOrderingInf
|
|||
if (!metaProperty.isValid())
|
||||
return {};
|
||||
|
||||
if (fieldInfo.getFieldFlags() & QtProtobufPrivate::Oneof) {
|
||||
if (fieldInfo.getFieldFlags() & QtProtobufPrivate::Oneof
|
||||
|| fieldInfo.getFieldFlags() & QtProtobufPrivate::Optional) {
|
||||
int hasPropertyIndex = propertyIndex + 1;
|
||||
QMetaProperty hasProperty = metaObject()->property(hasPropertyIndex);
|
||||
Q_ASSERT_X(hasProperty.isValid() && hasProperty.metaType().id() == QMetaType::Bool,
|
||||
|
|
|
|||
|
|
@ -50,11 +50,11 @@ private:
|
|||
};
|
||||
Q_GLOBAL_STATIC(HandlersRegistry, handlersRegistry)
|
||||
|
||||
inline bool isOneofField(const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo)
|
||||
inline bool
|
||||
isOneofOrOptionalField(const QtProtobufPrivate::QProtobufPropertyOrderingInfo &fieldInfo)
|
||||
{
|
||||
// TODO: Add the check for the optional flag once the functionality is
|
||||
// implemented.
|
||||
return fieldInfo.getFieldFlags() & QtProtobufPrivate::Oneof;
|
||||
return fieldInfo.getFieldFlags() & QtProtobufPrivate::Oneof
|
||||
|| fieldInfo.getFieldFlags() & QtProtobufPrivate::Optional;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
|
@ -455,7 +455,7 @@ bool QProtobufSerializer::deserializeMapPair(QVariant &key, QVariant &value, QPr
|
|||
QByteArray QProtobufSerializer::serializeEnum(QtProtobuf::int64 value,
|
||||
const QProtobufPropertyOrderingInfo &fieldInfo) const
|
||||
{
|
||||
if (value == 0 && !isOneofField(fieldInfo))
|
||||
if (value == 0 && !isOneofOrOptionalField(fieldInfo))
|
||||
return {};
|
||||
|
||||
QtProtobuf::WireTypes type = QtProtobuf::WireTypes::Varint;
|
||||
|
|
@ -636,7 +636,7 @@ QProtobufSerializerPrivate::serializeProperty(const QVariant &propertyValue,
|
|||
auto basicHandler = findIntegratedTypeHandler(
|
||||
metaType, fieldInfo.getFieldFlags() & QtProtobufPrivate::NonPacked);
|
||||
if (basicHandler) {
|
||||
bool serializeUninitialized = isOneofField(fieldInfo);
|
||||
bool serializeUninitialized = isOneofOrOptionalField(fieldInfo);
|
||||
if (!basicHandler->isPresent(propertyValue) && !serializeUninitialized) {
|
||||
return {};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ QT_BEGIN_NAMESPACE
|
|||
|
||||
namespace QtProtobufPrivate {
|
||||
|
||||
enum FieldFlag : uint { NoFlags = 0x0, NonPacked = 0x1, Oneof = 0x02 };
|
||||
enum FieldFlag : uint { NoFlags = 0x0, NonPacked = 0x1, Oneof = 0x02, Optional = 0x04 };
|
||||
|
||||
struct QProtobufPropertyOrdering
|
||||
{
|
||||
|
|
|
|||
|
|
@ -217,7 +217,16 @@ void MessageDeclarationPrinter::printProperties()
|
|||
: CommonTemplates::PropertyOneofTemplate());
|
||||
m_printer->Print(propertyMap, CommonTemplates::PropertyHasOneofTemplate());
|
||||
continue;
|
||||
} else if (common::isPureMessage(field)) {
|
||||
}
|
||||
|
||||
if (common::isOptionalField(field)) {
|
||||
const auto propertyMap = common::producePropertyMap(field, m_descriptor);
|
||||
m_printer->Print(propertyMap, CommonTemplates::PropertyOneofTemplate());
|
||||
m_printer->Print(propertyMap, CommonTemplates::PropertyHasOneofTemplate());
|
||||
continue;
|
||||
}
|
||||
|
||||
if (common::isPureMessage(field)) {
|
||||
propertyTemplate = CommonTemplates::PropertyMessageTemplate();
|
||||
} else if (common::hasQmlAlias(field)) {
|
||||
propertyTemplate = CommonTemplates::PropertyNonScriptableTemplate();
|
||||
|
|
@ -271,6 +280,11 @@ void MessageDeclarationPrinter::printGetters()
|
|||
: CommonTemplates::GetterOneofDeclarationTemplate());
|
||||
return;
|
||||
}
|
||||
if (common::isOptionalField(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::GetterOneofDeclarationTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
if (common::isPureMessage(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
|
|
@ -304,6 +318,12 @@ void MessageDeclarationPrinter::printSetters()
|
|||
CommonTemplates::SetterOneofDeclarationTemplate());
|
||||
return;
|
||||
}
|
||||
if (common::isOptionalField(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::SetterOneofDeclarationTemplate());
|
||||
m_printer->Print(propertyMap, CommonTemplates::ClearOneofDeclarationTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
switch (field->type()) {
|
||||
case FieldDescriptor::TYPE_MESSAGE:
|
||||
|
|
@ -344,6 +364,9 @@ void MessageDeclarationPrinter::printPrivateGetters()
|
|||
? CommonTemplates::
|
||||
PrivateGetterOneofMessageDeclarationTemplate()
|
||||
: CommonTemplates::PrivateGetterOneofDeclarationTemplate());
|
||||
} else if (common::isOptionalField(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::PrivateGetterOneofDeclarationTemplate());
|
||||
} else if (common::isPureMessage(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::PrivateGetterMessageDeclarationTemplate());
|
||||
|
|
@ -366,6 +389,9 @@ void MessageDeclarationPrinter::printPrivateSetters()
|
|||
? CommonTemplates::
|
||||
PrivateSetterOneofMessageDeclarationTemplate()
|
||||
: CommonTemplates::PrivateSetterOneofDeclarationTemplate());
|
||||
} else if (common::isOptionalField(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::PrivateSetterOneofDeclarationTemplate());
|
||||
} else if (common::isPureMessage(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::PrivateSetterMessageDeclarationTemplate());
|
||||
|
|
|
|||
|
|
@ -41,8 +41,9 @@ void MessageDefinitionPrinter::printClassMembers()
|
|||
m_descriptor, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) {
|
||||
if (common::isOneofField(field))
|
||||
return;
|
||||
|
||||
if (common::isPureMessage(field)) {
|
||||
if (common::isOptionalField(field)) {
|
||||
m_printer->Print(propertyMap, CommonTemplates::MemberOptionalTemplate());
|
||||
} else if (common::isPureMessage(field)) {
|
||||
m_printer->Print(propertyMap, CommonTemplates::MemberMessageTemplate());
|
||||
} else if (field->is_repeated() && !field->is_map()) {
|
||||
m_printer->Print(propertyMap, CommonTemplates::MemberRepeatedTemplate());
|
||||
|
|
@ -86,7 +87,7 @@ void MessageDefinitionPrinter::printDataClassCopy()
|
|||
m_printer->Indent();
|
||||
common::iterateMessageFields(
|
||||
m_descriptor, [&](const FieldDescriptor *field, const PropertyMap &propertyMap) {
|
||||
if (common::isOneofField(field))
|
||||
if (common::isOneofField(field) || common::isOptionalField(field))
|
||||
return;
|
||||
|
||||
m_printer->Print(",\n");
|
||||
|
|
@ -250,9 +251,9 @@ void MessageDefinitionPrinter::printUintData(const char *templateString)
|
|||
{ "json_name", field->json_name() },
|
||||
};
|
||||
|
||||
// Oneof properties generate additional has<OneofField> property next to the field property
|
||||
// one.
|
||||
if (common::isOneofField(field))
|
||||
// Oneof and optional properties generate additional has<FieldName> property next to the
|
||||
// field property one.
|
||||
if (common::isOneofField(field) || common::isOptionalField(field))
|
||||
++propertyIndex;
|
||||
|
||||
m_printer->Print(variables, templateString);
|
||||
|
|
@ -309,7 +310,8 @@ void MessageDefinitionPrinter::printInitializationList()
|
|||
m_printer->Indent();
|
||||
common::iterateMessageFields(
|
||||
m_descriptor, [&](const FieldDescriptor *field, PropertyMap propertyMap) {
|
||||
if (field->is_repeated() || common::isOneofField(field))
|
||||
if (field->is_repeated() || common::isOneofField(field)
|
||||
|| common::isOptionalField(field))
|
||||
return;
|
||||
|
||||
if (!propertyMap["initializer"].empty()) {
|
||||
|
|
@ -396,6 +398,14 @@ void MessageDefinitionPrinter::printGetters()
|
|||
return;
|
||||
}
|
||||
|
||||
if (common::isOptionalField(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::PrivateGetterOptionalDefinitionTemplate());
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::GetterOptionalDefinitionTemplate());
|
||||
return;
|
||||
}
|
||||
|
||||
if (common::hasQmlAlias(field)) {
|
||||
m_printer->Print(propertyMap, CommonTemplates::GetterNonScriptableDefinitionTemplate());
|
||||
}
|
||||
|
|
@ -427,6 +437,15 @@ void MessageDefinitionPrinter::printGetters()
|
|||
: CommonTemplates::PrivateSetterOneofDefinitionTemplate());
|
||||
return;
|
||||
}
|
||||
if (common::isOptionalField(field)) {
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::SetterOptionalDefinitionTemplate());
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::PrivateSetterOptionalDefinitionTemplate());
|
||||
m_printer->Print(propertyMap,
|
||||
CommonTemplates::ClearOptionalDefinitionTemplate());
|
||||
return;
|
||||
}
|
||||
if (common::hasQmlAlias(field)) {
|
||||
m_printer->Print(propertyMap, CommonTemplates::SetterNonScriptableDefinitionTemplate());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -191,14 +191,8 @@ void QProtobufGenerator::GenerateHeader(const FileDescriptor *file,
|
|||
if (hasOneofFields)
|
||||
externalIncludes.insert("QtProtobuf/qprotobufoneof.h");
|
||||
|
||||
if (hasOptionalFields) {
|
||||
std::cerr << "WARNING: '" << file->name() << "' contains 'optional' fields.\n"
|
||||
"\nOptional fields are not supported in this qtprotobufgen version\n"
|
||||
"The generator disregards the keyword, but generates the regular\n"
|
||||
"fields instead.\n"
|
||||
"\nPlease upgrade Qt to the most recent version to get full support\n"
|
||||
"of the 'optional' fields.\n";
|
||||
}
|
||||
if (hasOptionalFields)
|
||||
externalIncludes.insert("optional");
|
||||
|
||||
for (const auto &qtTypeInclude: qtTypesSet) {
|
||||
std::string qtTypeLower = qtTypeInclude;
|
||||
|
|
|
|||
|
|
@ -297,6 +297,10 @@ const char *CommonTemplates::MemberOneofTemplate()
|
|||
{
|
||||
return "QtProtobufPrivate::QProtobufOneof m_$optional_property_name$;\n";
|
||||
}
|
||||
const char *CommonTemplates::MemberOptionalTemplate()
|
||||
{
|
||||
return "std::optional<$scope_type$> m_$optional_property_name$;\n";
|
||||
}
|
||||
const char *CommonTemplates::MemberRepeatedTemplate()
|
||||
{
|
||||
return "$scope_list_type$ m_$property_name$;\n";
|
||||
|
|
@ -461,11 +465,15 @@ const char *CommonTemplates::ClearMessageDefinitionTemplate()
|
|||
|
||||
const char *CommonTemplates::GetterMessageDeclarationTemplate()
|
||||
{
|
||||
return "$getter_type$ &$property_name$() const;\n";
|
||||
return "bool has$property_name_cap$() const;\n"
|
||||
"$getter_type$ &$property_name$() const;\n";
|
||||
}
|
||||
const char *CommonTemplates::GetterMessageDefinitionTemplate()
|
||||
{
|
||||
return "$getter_type$ &$classname$::$property_name$() const\n{\n"
|
||||
return "bool $classname$::has$property_name_cap$() const\n{\n"
|
||||
" return dptr->m_$property_name$.operator bool();\n"
|
||||
"}\n\n"
|
||||
"$getter_type$ &$classname$::$property_name$() const\n{\n"
|
||||
" return *dptr->m_$property_name$;\n"
|
||||
"}\n\n";
|
||||
}
|
||||
|
|
@ -482,6 +490,14 @@ const char *CommonTemplates::PrivateGetterOneofDefinitionTemplate()
|
|||
"$getter_type$($initializer$);\n"
|
||||
"}\n\n";
|
||||
}
|
||||
const char *CommonTemplates::PrivateGetterOptionalDefinitionTemplate()
|
||||
{
|
||||
return "$getter_type$ $classname$::$property_name$_p() const\n{\n"
|
||||
" return dptr->m_$optional_property_name$ ?\n"
|
||||
" dptr->m_$optional_property_name$.value() : "
|
||||
"$getter_type$();\n"
|
||||
"}\n\n";
|
||||
}
|
||||
|
||||
const char *CommonTemplates::PrivateGetterOneofMessageDeclarationTemplate()
|
||||
{
|
||||
|
|
@ -522,6 +538,16 @@ const char *CommonTemplates::GetterOneofDefinitionTemplate()
|
|||
" return dptr->m_$optional_property_name$.value<$getter_type$>();\n"
|
||||
"}\n\n";
|
||||
}
|
||||
const char *CommonTemplates::GetterOptionalDefinitionTemplate()
|
||||
{
|
||||
return "bool $classname$::has$property_name_cap$() const\n{\n"
|
||||
" return dptr->m_$optional_property_name$.has_value();\n"
|
||||
"}\n"
|
||||
"$getter_type$ $classname$::$property_name$() const\n{\n"
|
||||
" Q_ASSERT(dptr->m_$optional_property_name$.has_value());\n"
|
||||
" return dptr->m_$optional_property_name$.value();\n"
|
||||
"}\n\n";
|
||||
}
|
||||
|
||||
const char *CommonTemplates::GetterOneofMessageDeclarationTemplate()
|
||||
{
|
||||
|
|
@ -646,6 +672,17 @@ const char *CommonTemplates::PrivateSetterOneofDefinitionTemplate()
|
|||
" }\n"
|
||||
"}\n\n";
|
||||
}
|
||||
const char *CommonTemplates::PrivateSetterOptionalDefinitionTemplate()
|
||||
{
|
||||
return "void $classname$::set$property_name_cap$_p($setter_type$ $property_name$)\n"
|
||||
"{\n"
|
||||
" if (!dptr->m_$optional_property_name$ || dptr->m_$optional_property_name$ != "
|
||||
"$property_name$) {\n"
|
||||
" dptr.detach();\n"
|
||||
" dptr->m_$optional_property_name$ = $property_name$;\n"
|
||||
" }\n"
|
||||
"}\n\n";
|
||||
}
|
||||
|
||||
const char *CommonTemplates::ClearOneofDeclarationTemplate()
|
||||
{
|
||||
|
|
@ -661,6 +698,15 @@ const char *CommonTemplates::ClearOneofDefinitionTemplate()
|
|||
" }\n"
|
||||
"}\n";
|
||||
}
|
||||
const char *CommonTemplates::ClearOptionalDefinitionTemplate()
|
||||
{
|
||||
return "void $classname$::clear$optional_property_name_cap$()\n{\n"
|
||||
" if (dptr->m_$optional_property_name$.has_value()) {\n"
|
||||
" dptr.detach();\n"
|
||||
" dptr->m_$optional_property_name$.reset();\n"
|
||||
" }"
|
||||
"}\n";
|
||||
}
|
||||
|
||||
const char *CommonTemplates::SetterOneofDeclarationTemplate()
|
||||
{
|
||||
|
|
@ -675,7 +721,16 @@ const char *CommonTemplates::SetterOneofDefinitionTemplate()
|
|||
" }\n"
|
||||
"}\n\n";
|
||||
}
|
||||
|
||||
const char *CommonTemplates::SetterOptionalDefinitionTemplate()
|
||||
{
|
||||
return "void $classname$::set$property_name_cap$(const $setter_type$ &$property_name$)\n{\n"
|
||||
" if (!dptr->m_$optional_property_name$ || dptr->m_$optional_property_name$.value() "
|
||||
"!= $property_name$) {\n"
|
||||
" dptr.detach();\n"
|
||||
" dptr->m_$optional_property_name$ = $property_name$;\n"
|
||||
" }\n"
|
||||
"}\n\n";
|
||||
}
|
||||
const char *CommonTemplates::SetterDeclarationTemplate()
|
||||
{
|
||||
return "void set$property_name_cap$(const $setter_type$ &$property_name$);\n";
|
||||
|
|
|
|||
|
|
@ -74,6 +74,7 @@ public:
|
|||
static const char *MemberRepeatedTemplate();
|
||||
static const char *MemberMessageTemplate();
|
||||
static const char *MemberOneofTemplate();
|
||||
static const char *MemberOptionalTemplate();
|
||||
static const char *PublicBlockTemplate();
|
||||
static const char *PrivateBlockTemplate();
|
||||
static const char *EnumDefinitionTemplate();
|
||||
|
|
@ -103,12 +104,14 @@ public:
|
|||
static const char *GetterMessageDefinitionTemplate();
|
||||
static const char *PrivateGetterOneofDeclarationTemplate();
|
||||
static const char *PrivateGetterOneofDefinitionTemplate();
|
||||
static const char *PrivateGetterOptionalDefinitionTemplate();
|
||||
static const char *PrivateGetterOneofMessageDeclarationTemplate();
|
||||
static const char *PrivateGetterOneofMessageDefinitionTemplate();
|
||||
static const char *GetterOneofFieldNumberDeclarationTemplate();
|
||||
static const char *GetterOneofFieldNumberDefinitionTemplate();
|
||||
static const char *GetterOneofDeclarationTemplate();
|
||||
static const char *GetterOneofDefinitionTemplate();
|
||||
static const char *GetterOptionalDefinitionTemplate();
|
||||
static const char *GetterOneofMessageDeclarationTemplate();
|
||||
static const char *GetterOneofMessageDefinitionTemplate();
|
||||
static const char *GetterDeclarationTemplate();
|
||||
|
|
@ -129,12 +132,15 @@ public:
|
|||
static const char *SetterNonScriptableDefinitionTemplate();
|
||||
static const char *SetterOneofDeclarationTemplate();
|
||||
static const char *SetterOneofDefinitionTemplate();
|
||||
static const char *SetterOptionalDefinitionTemplate();
|
||||
static const char *PrivateSetterOneofDeclarationTemplate();
|
||||
static const char *PrivateSetterOneofDefinitionTemplate();
|
||||
static const char *PrivateSetterOptionalDefinitionTemplate();
|
||||
static const char *PrivateSetterOneofMessageDeclarationTemplate();
|
||||
static const char *PrivateSetterOneofMessageDefinitionTemplate();
|
||||
static const char *ClearOneofDeclarationTemplate();
|
||||
static const char *ClearOneofDefinitionTemplate();
|
||||
static const char *ClearOptionalDefinitionTemplate();
|
||||
static const char *JsonNameOffsetsUintDataTemplate();
|
||||
static const char *FieldNumbersUintDataTemplate();
|
||||
static const char *QtPropertyIndicesUintDataTemplate();
|
||||
|
|
|
|||
|
|
@ -548,6 +548,9 @@ PropertyMap common::producePropertyMap(const FieldDescriptor *field, const Descr
|
|||
propertyMap["optional_property_name"] = field->containing_oneof()->name();
|
||||
propertyMap["optional_property_name_cap"] =
|
||||
utils::capitalizeAsciiName(field->containing_oneof()->name());
|
||||
} else if (common::isOptionalField(field)) {
|
||||
propertyMap["optional_property_name"] = propertyName;
|
||||
propertyMap["optional_property_name_cap"] = propertyNameCap;
|
||||
}
|
||||
|
||||
if (field->is_map()) {
|
||||
|
|
@ -584,6 +587,17 @@ bool common::isOneofField(const FieldDescriptor *field)
|
|||
#endif
|
||||
}
|
||||
|
||||
bool common::isOptionalField(const FieldDescriptor *field)
|
||||
{
|
||||
#ifdef HAVE_PROTOBUF_SYNC_PIPER
|
||||
bool hasOptional = field->has_optional_keyword();
|
||||
#else
|
||||
bool hasOptional = file->syntax() == FileDescriptor::SYNTAX_PROTO2 && field->is_optional()
|
||||
&& !field->containing_oneof();
|
||||
#endif
|
||||
return field->type() != FieldDescriptor::TYPE_MESSAGE && hasOptional;
|
||||
}
|
||||
|
||||
bool common::isLocalEnum(const EnumDescriptor *type, const Descriptor *scope)
|
||||
{
|
||||
assert(type != nullptr);
|
||||
|
|
@ -716,6 +730,9 @@ std::string common::collectFieldFlags(const FieldDescriptor *field)
|
|||
if (common::isOneofField(field))
|
||||
writeFlag("Oneof");
|
||||
|
||||
if (common::isOptionalField(field))
|
||||
writeFlag("Optional");
|
||||
|
||||
if (flags.empty())
|
||||
writeFlag("NoFlags");
|
||||
|
||||
|
|
|
|||
|
|
@ -127,6 +127,7 @@ struct common {
|
|||
const Descriptor *scope);
|
||||
static std::string qualifiedName(const std::string &name);
|
||||
static bool isOneofField(const FieldDescriptor *field);
|
||||
static bool isOptionalField(const FieldDescriptor *field);
|
||||
static bool isLocalEnum(const EnumDescriptor *type, const google::protobuf::Descriptor *scope);
|
||||
static EnumVisibility enumVisibility(const EnumDescriptor *type, const Descriptor *scope);
|
||||
static bool hasQmlAlias(const FieldDescriptor *field);
|
||||
|
|
|
|||
|
|
@ -14,7 +14,10 @@ if(TARGET Qt6::qtprotobufgen)
|
|||
add_subdirectory(converters)
|
||||
add_subdirectory(duplicated_metatypes)
|
||||
add_subdirectory(recursive)
|
||||
add_subdirectory(optional)
|
||||
if(protoc_version VERSION_GREATER_EQUAL "3.12")
|
||||
add_subdirectory(optional)
|
||||
endif()
|
||||
|
||||
if(TARGET Qt6::ProtobufWellKnownTypes)
|
||||
add_subdirectory(wellknown)
|
||||
endif()
|
||||
|
|
|
|||
|
|
@ -19,9 +19,7 @@ qt_internal_add_test(tst_protobuf_optional
|
|||
qt_autogen_tools_initial_setup(tst_protobuf_optional)
|
||||
|
||||
get_target_property(protoc_version WrapProtoc::WrapProtoc _qt_internal_protobuf_version)
|
||||
if(protoc_version VERSION_GREATER_EQUAL "3.12")
|
||||
qt6_add_protobuf(tst_protobuf_optional
|
||||
PROTO_FILES
|
||||
../../shared/data/proto/optional.proto
|
||||
)
|
||||
endif()
|
||||
qt6_add_protobuf(tst_protobuf_optional
|
||||
PROTO_FILES
|
||||
../../shared/data/proto/optional.proto
|
||||
)
|
||||
|
|
|
|||
|
|
@ -4,11 +4,171 @@
|
|||
#include <QTest>
|
||||
#include <QObject>
|
||||
|
||||
#include <QtProtobuf/qprotobufserializer.h>
|
||||
|
||||
#include <optional.qpb.h>
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
using namespace Qt::Literals::StringLiterals;
|
||||
|
||||
class QtProtobufOptionalTest : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void init() { serializer.reset(new QProtobufSerializer); }
|
||||
|
||||
void SerializeOptionalInt();
|
||||
void SerializeOptionalBool();
|
||||
void SerializeOptionalString();
|
||||
void SerializeOptionalBytes();
|
||||
void SerializeOptionalMessage();
|
||||
|
||||
void DeserializeOptionalInt();
|
||||
void DeserializeOptionalBool();
|
||||
void DeserializeOptionalString();
|
||||
void DeserializeOptionalBytes();
|
||||
void DeserializeOptionalMessage();
|
||||
|
||||
private:
|
||||
std::unique_ptr<QProtobufSerializer> serializer;
|
||||
};
|
||||
|
||||
void QtProtobufOptionalTest::SerializeOptionalInt()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), ""_ba);
|
||||
msg.setTestFieldOpt(0);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "1000"_ba);
|
||||
msg.setTestFieldOpt(84);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "10a801"_ba);
|
||||
msg.clearTestFieldOpt();
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), ""_ba);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::SerializeOptionalBool()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.setTestFieldBoolOpt(false);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "2000"_ba);
|
||||
msg.setTestFieldBoolOpt(true);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "2001"_ba);
|
||||
msg.clearTestFieldBoolOpt();
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), ""_ba);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::SerializeOptionalString()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.setTestFieldStringOpt(""_L1);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "4200"_ba);
|
||||
msg.setTestFieldStringOpt("qwerty"_L1);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "4206717765727479"_ba);
|
||||
msg.clearTestFieldStringOpt();
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), ""_ba);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::SerializeOptionalBytes()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.setTestFieldBytesOpt(""_ba);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "3200"_ba);
|
||||
msg.setTestFieldBytesOpt("qwerty"_ba);
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "3206717765727479"_ba);
|
||||
msg.clearTestFieldBytesOpt();
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), ""_ba);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::SerializeOptionalMessage()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.setTestFieldMessageOpt({});
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "5200"_ba);
|
||||
msg.clearTestFieldMessageOpt();
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), ""_ba);
|
||||
|
||||
// Accessing the field of message type initializes it.
|
||||
msg.testFieldMessageOpt();
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), "5200"_ba);
|
||||
msg.clearTestFieldMessageOpt();
|
||||
QCOMPARE(msg.serialize(serializer.get()).toHex(), ""_ba);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::DeserializeOptionalInt()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("1000"_ba));
|
||||
QVERIFY(msg.hasTestFieldOpt());
|
||||
QCOMPARE(msg.testFieldOpt(), 0);
|
||||
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("10a801"_ba));
|
||||
QVERIFY(msg.hasTestFieldOpt());
|
||||
QCOMPARE(msg.testFieldOpt(), 84);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::DeserializeOptionalBool()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldBoolOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("2000"_ba));
|
||||
QVERIFY(msg.hasTestFieldBoolOpt());
|
||||
QCOMPARE(msg.testFieldBoolOpt(), false);
|
||||
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldBoolOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("2001"_ba));
|
||||
QVERIFY(msg.hasTestFieldBoolOpt());
|
||||
QCOMPARE(msg.testFieldBoolOpt(), true);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::DeserializeOptionalString()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldStringOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("4200"_ba));
|
||||
QVERIFY(msg.hasTestFieldStringOpt());
|
||||
QCOMPARE(msg.testFieldStringOpt(), ""_L1);
|
||||
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldStringOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("4206717765727479"_ba));
|
||||
QVERIFY(msg.hasTestFieldStringOpt());
|
||||
QCOMPARE(msg.testFieldStringOpt(), "qwerty"_L1);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::DeserializeOptionalBytes()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldBytesOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("3200"_ba));
|
||||
QVERIFY(msg.hasTestFieldBytesOpt());
|
||||
QCOMPARE(msg.testFieldBytesOpt(), ""_ba);
|
||||
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldBytesOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("3206717765727479"_ba));
|
||||
QVERIFY(msg.hasTestFieldBytesOpt());
|
||||
QCOMPARE(msg.testFieldBytesOpt(), "qwerty"_ba);
|
||||
}
|
||||
|
||||
void QtProtobufOptionalTest::DeserializeOptionalMessage()
|
||||
{
|
||||
qtprotobufnamespace::optional::tests::OptionalMessage msg;
|
||||
msg.deserialize(serializer.get(), ""_ba);
|
||||
QVERIFY(!msg.hasTestFieldMessageOpt());
|
||||
msg.deserialize(serializer.get(), QByteArray::fromHex("5200"_ba));
|
||||
QVERIFY(msg.hasTestFieldMessageOpt());
|
||||
QCOMPARE(msg.testFieldMessageOpt(), qtprotobufnamespace::optional::tests::TestStringMessage());
|
||||
}
|
||||
|
||||
QTEST_MAIN(QtProtobufOptionalTest)
|
||||
|
||||
#include "tst_protobuf_optional.moc"
|
||||
|
|
|
|||
|
|
@ -44,6 +44,7 @@ qt_add_protobuf(tst_qtprotobufgen
|
|||
../shared/data/proto/mapmessages.proto
|
||||
../shared/data/proto/oneofmessages.proto
|
||||
../shared/data/proto/repeatedmessages.proto
|
||||
../shared/data/proto/optional.proto
|
||||
GENERATE_PACKAGE_SUBFOLDERS
|
||||
OUTPUT_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/qt_protobuf_generated/folder"
|
||||
)
|
||||
|
|
|
|||
|
|
@ -338,6 +338,11 @@ SimpleStringMessage *ComplexMessage::testComplexField_p() const
|
|||
return dptr->m_testComplexField ? dptr->m_testComplexField.get() : nullptr;
|
||||
}
|
||||
|
||||
bool ComplexMessage::hasTestComplexField() const
|
||||
{
|
||||
return dptr->m_testComplexField.operator bool();
|
||||
}
|
||||
|
||||
SimpleStringMessage &ComplexMessage::testComplexField() const
|
||||
{
|
||||
return *dptr->m_testComplexField;
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ public:
|
|||
|
||||
QtProtobuf::int32 testFieldInt() const;
|
||||
|
||||
bool hasTestComplexField() const;
|
||||
SimpleStringMessage &testComplexField() const;
|
||||
void clearTestComplexField();
|
||||
void setTestFieldInt(const QtProtobuf::int32 &testFieldInt);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,572 @@
|
|||
/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */
|
||||
|
||||
#include "qtprotobufnamespace/optional/tests/optional.qpb.h"
|
||||
#include <QtProtobuf/qprotobufserializer.h>
|
||||
|
||||
namespace qtprotobufnamespace::optional::tests {
|
||||
|
||||
class TestStringMessage_QtProtobufData : public QSharedData
|
||||
{
|
||||
public:
|
||||
TestStringMessage_QtProtobufData()
|
||||
: QSharedData()
|
||||
{
|
||||
}
|
||||
|
||||
TestStringMessage_QtProtobufData(const TestStringMessage_QtProtobufData &other)
|
||||
: QSharedData(other),
|
||||
m_stringField(other.m_stringField)
|
||||
{
|
||||
}
|
||||
|
||||
QString m_stringField;
|
||||
};
|
||||
|
||||
TestStringMessage::~TestStringMessage() = default;
|
||||
|
||||
static constexpr struct {
|
||||
QtProtobufPrivate::QProtobufPropertyOrdering::Data data;
|
||||
const std::array<uint, 5> qt_protobuf_TestStringMessage_uint_data;
|
||||
const char qt_protobuf_TestStringMessage_char_data[66];
|
||||
} qt_protobuf_TestStringMessage_metadata {
|
||||
// data
|
||||
{
|
||||
0, /* = version */
|
||||
1, /* = num fields */
|
||||
2, /* = field number offset */
|
||||
3, /* = property index offset */
|
||||
4, /* = field flags offset */
|
||||
52, /* = message full name length */
|
||||
},
|
||||
// uint_data
|
||||
{
|
||||
// JSON name offsets:
|
||||
53, /* = stringField */
|
||||
65, /* = end-of-string-marker */
|
||||
// Field numbers:
|
||||
2, /* = stringField */
|
||||
// Property indices:
|
||||
0, /* = stringField */
|
||||
// Field flags:
|
||||
QtProtobufPrivate::NoFlags, /* = stringField */
|
||||
},
|
||||
// char_data
|
||||
/* metadata char_data: */
|
||||
"qtprotobufnamespace.optional.tests.TestStringMessage\0" /* = full message name */
|
||||
/* field char_data: */
|
||||
"stringField\0"
|
||||
};
|
||||
|
||||
const QtProtobufPrivate::QProtobufPropertyOrdering TestStringMessage::propertyOrdering = {
|
||||
&qt_protobuf_TestStringMessage_metadata.data
|
||||
};
|
||||
|
||||
void TestStringMessage::registerTypes()
|
||||
{
|
||||
qRegisterMetaType<TestStringMessage>();
|
||||
qRegisterMetaType<TestStringMessageRepeated>();
|
||||
}
|
||||
|
||||
TestStringMessage::TestStringMessage()
|
||||
: QProtobufMessage(&TestStringMessage::staticMetaObject),
|
||||
dptr(new TestStringMessage_QtProtobufData)
|
||||
{
|
||||
}
|
||||
|
||||
TestStringMessage::TestStringMessage(const TestStringMessage &other)
|
||||
: QProtobufMessage(other),
|
||||
dptr(other.dptr)
|
||||
{
|
||||
}
|
||||
TestStringMessage &TestStringMessage::operator =(const TestStringMessage &other)
|
||||
{
|
||||
QProtobufMessage::operator=(other);
|
||||
dptr = other.dptr;
|
||||
return *this;
|
||||
}
|
||||
TestStringMessage::TestStringMessage(TestStringMessage &&other) noexcept
|
||||
: QProtobufMessage(std::move(other)),
|
||||
dptr(std::move(other.dptr))
|
||||
{
|
||||
}
|
||||
TestStringMessage &TestStringMessage::operator =(TestStringMessage &&other) noexcept
|
||||
{
|
||||
QProtobufMessage::operator=(std::move(other));
|
||||
dptr.swap(other.dptr);
|
||||
return *this;
|
||||
}
|
||||
bool TestStringMessage::operator ==(const TestStringMessage &other) const
|
||||
{
|
||||
return QProtobufMessage::isEqual(*this, other)
|
||||
&& dptr->m_stringField == other.dptr->m_stringField;
|
||||
}
|
||||
|
||||
bool TestStringMessage::operator !=(const TestStringMessage &other) const
|
||||
{
|
||||
return !this->operator ==(other);
|
||||
}
|
||||
|
||||
QString TestStringMessage::stringField() const
|
||||
{
|
||||
return dptr->m_stringField;
|
||||
}
|
||||
|
||||
void TestStringMessage::setStringField(const QString &stringField)
|
||||
{
|
||||
if (dptr->m_stringField != stringField) {
|
||||
dptr.detach();
|
||||
dptr->m_stringField = stringField;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class OptionalMessage_QtProtobufData : public QSharedData
|
||||
{
|
||||
public:
|
||||
OptionalMessage_QtProtobufData()
|
||||
: QSharedData(),
|
||||
m_testField(0),
|
||||
m_testFieldBool(false),
|
||||
m_testFieldMessage(nullptr),
|
||||
m_testFieldMessageOpt(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
OptionalMessage_QtProtobufData(const OptionalMessage_QtProtobufData &other)
|
||||
: QSharedData(other),
|
||||
m_testField(other.m_testField),
|
||||
m_testFieldBool(other.m_testFieldBool),
|
||||
m_testFieldBytes(other.m_testFieldBytes),
|
||||
m_testFieldString(other.m_testFieldString),
|
||||
m_testFieldMessage(other.m_testFieldMessage
|
||||
? new TestStringMessage(*other.m_testFieldMessage)
|
||||
: nullptr),
|
||||
m_testFieldMessageOpt(other.m_testFieldMessageOpt
|
||||
? new TestStringMessage(*other.m_testFieldMessageOpt)
|
||||
: nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
QtProtobuf::sint32 m_testField;
|
||||
std::optional<QtProtobuf::sint32> m_testFieldOpt;
|
||||
bool m_testFieldBool;
|
||||
std::optional<bool> m_testFieldBoolOpt;
|
||||
QByteArray m_testFieldBytes;
|
||||
std::optional<QByteArray> m_testFieldBytesOpt;
|
||||
QString m_testFieldString;
|
||||
std::optional<QString> m_testFieldStringOpt;
|
||||
QtProtobufPrivate::QProtobufLazyMessagePointer<TestStringMessage> m_testFieldMessage;
|
||||
QtProtobufPrivate::QProtobufLazyMessagePointer<TestStringMessage> m_testFieldMessageOpt;
|
||||
};
|
||||
|
||||
OptionalMessage::~OptionalMessage() = default;
|
||||
|
||||
static constexpr struct {
|
||||
QtProtobufPrivate::QProtobufPropertyOrdering::Data data;
|
||||
const std::array<uint, 41> qt_protobuf_OptionalMessage_uint_data;
|
||||
const char qt_protobuf_OptionalMessage_char_data[211];
|
||||
} qt_protobuf_OptionalMessage_metadata {
|
||||
// data
|
||||
{
|
||||
0, /* = version */
|
||||
10, /* = num fields */
|
||||
11, /* = field number offset */
|
||||
21, /* = property index offset */
|
||||
31, /* = field flags offset */
|
||||
50, /* = message full name length */
|
||||
},
|
||||
// uint_data
|
||||
{
|
||||
// JSON name offsets:
|
||||
51, /* = testField */
|
||||
61, /* = testFieldOpt */
|
||||
74, /* = testFieldBool */
|
||||
88, /* = testFieldBoolOpt */
|
||||
105, /* = testFieldBytes */
|
||||
120, /* = testFieldBytesOpt */
|
||||
138, /* = testFieldString */
|
||||
154, /* = testFieldStringOpt */
|
||||
173, /* = testFieldMessage */
|
||||
190, /* = testFieldMessageOpt */
|
||||
210, /* = end-of-string-marker */
|
||||
// Field numbers:
|
||||
1, /* = testField */
|
||||
2, /* = testFieldOpt */
|
||||
3, /* = testFieldBool */
|
||||
4, /* = testFieldBoolOpt */
|
||||
5, /* = testFieldBytes */
|
||||
6, /* = testFieldBytesOpt */
|
||||
7, /* = testFieldString */
|
||||
8, /* = testFieldStringOpt */
|
||||
9, /* = testFieldMessage */
|
||||
10, /* = testFieldMessageOpt */
|
||||
// Property indices:
|
||||
0, /* = testField */
|
||||
1, /* = testFieldOpt */
|
||||
3, /* = testFieldBool */
|
||||
4, /* = testFieldBoolOpt */
|
||||
6, /* = testFieldBytes */
|
||||
7, /* = testFieldBytesOpt */
|
||||
9, /* = testFieldString */
|
||||
10, /* = testFieldStringOpt */
|
||||
12, /* = testFieldMessage */
|
||||
13, /* = testFieldMessageOpt */
|
||||
// Field flags:
|
||||
QtProtobufPrivate::NoFlags, /* = testField */
|
||||
QtProtobufPrivate::Optional, /* = testFieldOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldBool */
|
||||
QtProtobufPrivate::Optional, /* = testFieldBoolOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldBytes */
|
||||
QtProtobufPrivate::Optional, /* = testFieldBytesOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldString */
|
||||
QtProtobufPrivate::Optional, /* = testFieldStringOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldMessage */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldMessageOpt */
|
||||
},
|
||||
// char_data
|
||||
/* metadata char_data: */
|
||||
"qtprotobufnamespace.optional.tests.OptionalMessage\0" /* = full message name */
|
||||
/* field char_data: */
|
||||
"testField\0testFieldOpt\0testFieldBool\0testFieldBoolOpt\0testFieldBytes\0"
|
||||
"testFieldBytesOpt\0testFieldString\0testFieldStringOpt\0testFieldMessage\0testFieldMessageOpt\0"
|
||||
};
|
||||
|
||||
const QtProtobufPrivate::QProtobufPropertyOrdering OptionalMessage::propertyOrdering = {
|
||||
&qt_protobuf_OptionalMessage_metadata.data
|
||||
};
|
||||
|
||||
void OptionalMessage::registerTypes()
|
||||
{
|
||||
qRegisterMetaType<OptionalMessage>();
|
||||
qRegisterMetaType<OptionalMessageRepeated>();
|
||||
}
|
||||
|
||||
OptionalMessage::OptionalMessage()
|
||||
: QProtobufMessage(&OptionalMessage::staticMetaObject),
|
||||
dptr(new OptionalMessage_QtProtobufData)
|
||||
{
|
||||
}
|
||||
|
||||
OptionalMessage::OptionalMessage(const OptionalMessage &other)
|
||||
: QProtobufMessage(other),
|
||||
dptr(other.dptr)
|
||||
{
|
||||
}
|
||||
OptionalMessage &OptionalMessage::operator =(const OptionalMessage &other)
|
||||
{
|
||||
QProtobufMessage::operator=(other);
|
||||
dptr = other.dptr;
|
||||
return *this;
|
||||
}
|
||||
OptionalMessage::OptionalMessage(OptionalMessage &&other) noexcept
|
||||
: QProtobufMessage(std::move(other)),
|
||||
dptr(std::move(other.dptr))
|
||||
{
|
||||
}
|
||||
OptionalMessage &OptionalMessage::operator =(OptionalMessage &&other) noexcept
|
||||
{
|
||||
QProtobufMessage::operator=(std::move(other));
|
||||
dptr.swap(other.dptr);
|
||||
return *this;
|
||||
}
|
||||
bool OptionalMessage::operator ==(const OptionalMessage &other) const
|
||||
{
|
||||
return QProtobufMessage::isEqual(*this, other)
|
||||
&& dptr->m_testField == other.dptr->m_testField
|
||||
&& dptr->m_testFieldBool == other.dptr->m_testFieldBool
|
||||
&& dptr->m_testFieldBytes == other.dptr->m_testFieldBytes
|
||||
&& dptr->m_testFieldString == other.dptr->m_testFieldString
|
||||
&& (dptr->m_testFieldMessage == other.dptr->m_testFieldMessage
|
||||
|| *dptr->m_testFieldMessage == *other.dptr->m_testFieldMessage);
|
||||
}
|
||||
|
||||
bool OptionalMessage::operator !=(const OptionalMessage &other) const
|
||||
{
|
||||
return !this->operator ==(other);
|
||||
}
|
||||
|
||||
QtProtobuf::sint32 OptionalMessage::testField() const
|
||||
{
|
||||
return dptr->m_testField;
|
||||
}
|
||||
|
||||
QtProtobuf::sint32 OptionalMessage::testFieldOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldOpt ?
|
||||
dptr->m_testFieldOpt.value() : QtProtobuf::sint32();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldOpt() const
|
||||
{
|
||||
return dptr->m_testFieldOpt.has_value();
|
||||
}
|
||||
QtProtobuf::sint32 OptionalMessage::testFieldOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldOpt.has_value());
|
||||
return dptr->m_testFieldOpt.value();
|
||||
}
|
||||
|
||||
bool OptionalMessage::testFieldBool() const
|
||||
{
|
||||
return dptr->m_testFieldBool;
|
||||
}
|
||||
|
||||
bool OptionalMessage::testFieldBoolOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldBoolOpt ?
|
||||
dptr->m_testFieldBoolOpt.value() : bool();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldBoolOpt() const
|
||||
{
|
||||
return dptr->m_testFieldBoolOpt.has_value();
|
||||
}
|
||||
bool OptionalMessage::testFieldBoolOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldBoolOpt.has_value());
|
||||
return dptr->m_testFieldBoolOpt.value();
|
||||
}
|
||||
|
||||
QByteArray OptionalMessage::testFieldBytes() const
|
||||
{
|
||||
return dptr->m_testFieldBytes;
|
||||
}
|
||||
|
||||
QByteArray OptionalMessage::testFieldBytesOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldBytesOpt ?
|
||||
dptr->m_testFieldBytesOpt.value() : QByteArray();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldBytesOpt() const
|
||||
{
|
||||
return dptr->m_testFieldBytesOpt.has_value();
|
||||
}
|
||||
QByteArray OptionalMessage::testFieldBytesOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldBytesOpt.has_value());
|
||||
return dptr->m_testFieldBytesOpt.value();
|
||||
}
|
||||
|
||||
QString OptionalMessage::testFieldString() const
|
||||
{
|
||||
return dptr->m_testFieldString;
|
||||
}
|
||||
|
||||
QString OptionalMessage::testFieldStringOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldStringOpt ?
|
||||
dptr->m_testFieldStringOpt.value() : QString();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldStringOpt() const
|
||||
{
|
||||
return dptr->m_testFieldStringOpt.has_value();
|
||||
}
|
||||
QString OptionalMessage::testFieldStringOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldStringOpt.has_value());
|
||||
return dptr->m_testFieldStringOpt.value();
|
||||
}
|
||||
|
||||
TestStringMessage *OptionalMessage::testFieldMessage_p() const
|
||||
{
|
||||
return dptr->m_testFieldMessage ? dptr->m_testFieldMessage.get() : nullptr;
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldMessage() const
|
||||
{
|
||||
return dptr->m_testFieldMessage.operator bool();
|
||||
}
|
||||
|
||||
TestStringMessage &OptionalMessage::testFieldMessage() const
|
||||
{
|
||||
return *dptr->m_testFieldMessage;
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldMessage()
|
||||
{
|
||||
if (dptr->m_testFieldMessage) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessage.reset();
|
||||
}
|
||||
}
|
||||
|
||||
TestStringMessage *OptionalMessage::testFieldMessageOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldMessageOpt ? dptr->m_testFieldMessageOpt.get() : nullptr;
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldMessageOpt() const
|
||||
{
|
||||
return dptr->m_testFieldMessageOpt.operator bool();
|
||||
}
|
||||
|
||||
TestStringMessage &OptionalMessage::testFieldMessageOpt() const
|
||||
{
|
||||
return *dptr->m_testFieldMessageOpt;
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldMessageOpt()
|
||||
{
|
||||
if (dptr->m_testFieldMessageOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessageOpt.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestField(const QtProtobuf::sint32 &testField)
|
||||
{
|
||||
if (dptr->m_testField != testField) {
|
||||
dptr.detach();
|
||||
dptr->m_testField = testField;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldOpt(const QtProtobuf::sint32 &testFieldOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldOpt || dptr->m_testFieldOpt.value() != testFieldOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldOpt = testFieldOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldOpt_p(QtProtobuf::sint32 testFieldOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldOpt || dptr->m_testFieldOpt != testFieldOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldOpt = testFieldOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldOpt()
|
||||
{
|
||||
if (dptr->m_testFieldOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldBool(const bool &testFieldBool)
|
||||
{
|
||||
if (dptr->m_testFieldBool != testFieldBool) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBool = testFieldBool;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBoolOpt(const bool &testFieldBoolOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBoolOpt || dptr->m_testFieldBoolOpt.value() != testFieldBoolOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBoolOpt = testFieldBoolOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBoolOpt_p(bool testFieldBoolOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBoolOpt || dptr->m_testFieldBoolOpt != testFieldBoolOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBoolOpt = testFieldBoolOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldBoolOpt()
|
||||
{
|
||||
if (dptr->m_testFieldBoolOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBoolOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldBytes(const QByteArray &testFieldBytes)
|
||||
{
|
||||
if (dptr->m_testFieldBytes != testFieldBytes) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytes = testFieldBytes;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBytesOpt(const QByteArray &testFieldBytesOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBytesOpt || dptr->m_testFieldBytesOpt.value() != testFieldBytesOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytesOpt = testFieldBytesOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBytesOpt_p(QByteArray testFieldBytesOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBytesOpt || dptr->m_testFieldBytesOpt != testFieldBytesOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytesOpt = testFieldBytesOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldBytesOpt()
|
||||
{
|
||||
if (dptr->m_testFieldBytesOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytesOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldString(const QString &testFieldString)
|
||||
{
|
||||
if (dptr->m_testFieldString != testFieldString) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldString = testFieldString;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldStringOpt(const QString &testFieldStringOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldStringOpt || dptr->m_testFieldStringOpt.value() != testFieldStringOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldStringOpt = testFieldStringOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldStringOpt_p(QString testFieldStringOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldStringOpt || dptr->m_testFieldStringOpt != testFieldStringOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldStringOpt = testFieldStringOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldStringOpt()
|
||||
{
|
||||
if (dptr->m_testFieldStringOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldStringOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldMessage_p(TestStringMessage *testFieldMessage)
|
||||
{
|
||||
if (dptr->m_testFieldMessage.get() != testFieldMessage) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessage.reset(testFieldMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldMessage(const TestStringMessage &testFieldMessage)
|
||||
{
|
||||
if (*dptr->m_testFieldMessage != testFieldMessage) {
|
||||
dptr.detach();
|
||||
*dptr->m_testFieldMessage = testFieldMessage;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldMessageOpt_p(TestStringMessage *testFieldMessageOpt)
|
||||
{
|
||||
if (dptr->m_testFieldMessageOpt.get() != testFieldMessageOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessageOpt.reset(testFieldMessageOpt);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldMessageOpt(const TestStringMessage &testFieldMessageOpt)
|
||||
{
|
||||
if (*dptr->m_testFieldMessageOpt != testFieldMessageOpt) {
|
||||
dptr.detach();
|
||||
*dptr->m_testFieldMessageOpt = testFieldMessageOpt;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace qtprotobufnamespace::optional::tests
|
||||
|
||||
#include "moc_optional.qpb.cpp"
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */
|
||||
|
||||
#ifndef QPROTOBUF_OPTIONAL_H
|
||||
#define QPROTOBUF_OPTIONAL_H
|
||||
|
||||
#include <QtProtobuf/qprotobufmessage.h>
|
||||
#include <QtProtobuf/qprotobufobject.h>
|
||||
#include <QtProtobuf/qprotobuflazymessagepointer.h>
|
||||
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtProtobuf/qprotobufoneof.h>
|
||||
#include <optional>
|
||||
|
||||
#include <QtCore/qmetatype.h>
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtCore/qshareddata.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace qtprotobufnamespace::optional::tests {
|
||||
class TestStringMessage;
|
||||
using TestStringMessageRepeated = QList<TestStringMessage>;
|
||||
namespace TestStringMessage_QtProtobufNested {
|
||||
enum class QtProtobufFieldEnum;
|
||||
} // namespace TestStringMessage_QtProtobufNested
|
||||
|
||||
class OptionalMessage;
|
||||
using OptionalMessageRepeated = QList<OptionalMessage>;
|
||||
namespace OptionalMessage_QtProtobufNested {
|
||||
enum class QtProtobufFieldEnum;
|
||||
} // namespace OptionalMessage_QtProtobufNested
|
||||
|
||||
|
||||
class TestStringMessage_QtProtobufData;
|
||||
class TestStringMessage : public QProtobufMessage
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROTOBUF_OBJECT
|
||||
Q_DECLARE_PROTOBUF_SERIALIZERS(TestStringMessage)
|
||||
Q_PROPERTY(QString stringField READ stringField WRITE setStringField SCRIPTABLE true)
|
||||
|
||||
public:
|
||||
using QtProtobufFieldEnum = TestStringMessage_QtProtobufNested::QtProtobufFieldEnum;
|
||||
TestStringMessage();
|
||||
~TestStringMessage();
|
||||
TestStringMessage(const TestStringMessage &other);
|
||||
TestStringMessage &operator =(const TestStringMessage &other);
|
||||
TestStringMessage(TestStringMessage &&other) noexcept;
|
||||
TestStringMessage &operator =(TestStringMessage &&other) noexcept;
|
||||
bool operator ==(const TestStringMessage &other) const;
|
||||
bool operator !=(const TestStringMessage &other) const;
|
||||
|
||||
QString stringField() const;
|
||||
void setStringField(const QString &stringField);
|
||||
static void registerTypes();
|
||||
|
||||
private:
|
||||
QExplicitlySharedDataPointer<TestStringMessage_QtProtobufData> dptr;
|
||||
};
|
||||
namespace TestStringMessage_QtProtobufNested {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class QtProtobufFieldEnum {
|
||||
StringFieldProtoFieldNumber = 2,
|
||||
};
|
||||
Q_ENUM_NS(QtProtobufFieldEnum)
|
||||
|
||||
} // namespace TestStringMessage_QtProtobufNested
|
||||
|
||||
class OptionalMessage_QtProtobufData;
|
||||
class OptionalMessage : public QProtobufMessage
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROTOBUF_OBJECT
|
||||
Q_DECLARE_PROTOBUF_SERIALIZERS(OptionalMessage)
|
||||
Q_PROPERTY(QtProtobuf::sint32 testField READ testField WRITE setTestField SCRIPTABLE true)
|
||||
Q_PROPERTY(QtProtobuf::sint32 testFieldOpt READ testFieldOpt_p WRITE setTestFieldOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldOpt READ hasTestFieldOpt)
|
||||
Q_PROPERTY(bool testFieldBool READ testFieldBool WRITE setTestFieldBool SCRIPTABLE true)
|
||||
Q_PROPERTY(bool testFieldBoolOpt READ testFieldBoolOpt_p WRITE setTestFieldBoolOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldBoolOpt READ hasTestFieldBoolOpt)
|
||||
Q_PROPERTY(QByteArray testFieldBytes READ testFieldBytes WRITE setTestFieldBytes SCRIPTABLE true)
|
||||
Q_PROPERTY(QByteArray testFieldBytesOpt READ testFieldBytesOpt_p WRITE setTestFieldBytesOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldBytesOpt READ hasTestFieldBytesOpt)
|
||||
Q_PROPERTY(QString testFieldString READ testFieldString WRITE setTestFieldString SCRIPTABLE true)
|
||||
Q_PROPERTY(QString testFieldStringOpt READ testFieldStringOpt_p WRITE setTestFieldStringOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldStringOpt READ hasTestFieldStringOpt)
|
||||
Q_PROPERTY(qtprotobufnamespace::optional::tests::TestStringMessage *testFieldMessage_p READ testFieldMessage_p WRITE setTestFieldMessage_p)
|
||||
Q_PROPERTY(qtprotobufnamespace::optional::tests::TestStringMessage *testFieldMessageOpt_p READ testFieldMessageOpt_p WRITE setTestFieldMessageOpt_p)
|
||||
|
||||
public:
|
||||
using QtProtobufFieldEnum = OptionalMessage_QtProtobufNested::QtProtobufFieldEnum;
|
||||
OptionalMessage();
|
||||
~OptionalMessage();
|
||||
OptionalMessage(const OptionalMessage &other);
|
||||
OptionalMessage &operator =(const OptionalMessage &other);
|
||||
OptionalMessage(OptionalMessage &&other) noexcept;
|
||||
OptionalMessage &operator =(OptionalMessage &&other) noexcept;
|
||||
bool operator ==(const OptionalMessage &other) const;
|
||||
bool operator !=(const OptionalMessage &other) const;
|
||||
|
||||
QtProtobuf::sint32 testField() const;
|
||||
|
||||
bool hasTestFieldOpt() const;
|
||||
QtProtobuf::sint32 testFieldOpt() const;
|
||||
|
||||
bool testFieldBool() const;
|
||||
|
||||
bool hasTestFieldBoolOpt() const;
|
||||
bool testFieldBoolOpt() const;
|
||||
|
||||
QByteArray testFieldBytes() const;
|
||||
|
||||
bool hasTestFieldBytesOpt() const;
|
||||
QByteArray testFieldBytesOpt() const;
|
||||
|
||||
QString testFieldString() const;
|
||||
|
||||
bool hasTestFieldStringOpt() const;
|
||||
QString testFieldStringOpt() const;
|
||||
|
||||
bool hasTestFieldMessage() const;
|
||||
TestStringMessage &testFieldMessage() const;
|
||||
void clearTestFieldMessage();
|
||||
|
||||
bool hasTestFieldMessageOpt() const;
|
||||
TestStringMessage &testFieldMessageOpt() const;
|
||||
void clearTestFieldMessageOpt();
|
||||
void setTestField(const QtProtobuf::sint32 &testField);
|
||||
void setTestFieldOpt(const QtProtobuf::sint32 &testFieldOpt);
|
||||
void clearTestFieldOpt();
|
||||
void setTestFieldBool(const bool &testFieldBool);
|
||||
void setTestFieldBoolOpt(const bool &testFieldBoolOpt);
|
||||
void clearTestFieldBoolOpt();
|
||||
void setTestFieldBytes(const QByteArray &testFieldBytes);
|
||||
void setTestFieldBytesOpt(const QByteArray &testFieldBytesOpt);
|
||||
void clearTestFieldBytesOpt();
|
||||
void setTestFieldString(const QString &testFieldString);
|
||||
void setTestFieldStringOpt(const QString &testFieldStringOpt);
|
||||
void clearTestFieldStringOpt();
|
||||
void setTestFieldMessage(const TestStringMessage &testFieldMessage);
|
||||
void setTestFieldMessageOpt(const TestStringMessage &testFieldMessageOpt);
|
||||
static void registerTypes();
|
||||
|
||||
private:
|
||||
QtProtobuf::sint32 testFieldOpt_p() const;
|
||||
bool testFieldBoolOpt_p() const;
|
||||
QByteArray testFieldBytesOpt_p() const;
|
||||
QString testFieldStringOpt_p() const;
|
||||
TestStringMessage *testFieldMessage_p() const;
|
||||
TestStringMessage *testFieldMessageOpt_p() const;
|
||||
void setTestFieldOpt_p(QtProtobuf::sint32 testFieldOpt);
|
||||
void setTestFieldBoolOpt_p(bool testFieldBoolOpt);
|
||||
void setTestFieldBytesOpt_p(QByteArray testFieldBytesOpt);
|
||||
void setTestFieldStringOpt_p(QString testFieldStringOpt);
|
||||
void setTestFieldMessage_p(TestStringMessage *testFieldMessage);
|
||||
void setTestFieldMessageOpt_p(TestStringMessage *testFieldMessageOpt);
|
||||
QExplicitlySharedDataPointer<OptionalMessage_QtProtobufData> dptr;
|
||||
};
|
||||
namespace OptionalMessage_QtProtobufNested {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class QtProtobufFieldEnum {
|
||||
TestFieldProtoFieldNumber = 1,
|
||||
TestFieldOptProtoFieldNumber = 2,
|
||||
TestFieldBoolProtoFieldNumber = 3,
|
||||
TestFieldBoolOptProtoFieldNumber = 4,
|
||||
TestFieldBytesProtoFieldNumber = 5,
|
||||
TestFieldBytesOptProtoFieldNumber = 6,
|
||||
TestFieldStringProtoFieldNumber = 7,
|
||||
TestFieldStringOptProtoFieldNumber = 8,
|
||||
TestFieldMessageProtoFieldNumber = 9,
|
||||
TestFieldMessageOptProtoFieldNumber = 10,
|
||||
};
|
||||
Q_ENUM_NS(QtProtobufFieldEnum)
|
||||
|
||||
} // namespace OptionalMessage_QtProtobufNested
|
||||
} // namespace qtprotobufnamespace::optional::tests
|
||||
|
||||
Q_DECLARE_METATYPE(qtprotobufnamespace::optional::tests::TestStringMessage)
|
||||
Q_DECLARE_METATYPE(qtprotobufnamespace::optional::tests::OptionalMessage)
|
||||
#endif // QPROTOBUF_OPTIONAL_H
|
||||
|
|
@ -0,0 +1,8 @@
|
|||
#include <QtProtobuf/qprotobufserializer.h>
|
||||
#include "qtprotobufnamespace/optional/tests/optional.qpb.h"
|
||||
|
||||
namespace qtprotobufnamespace::optional::tests {
|
||||
static QtProtobuf::ProtoTypeRegistrar ProtoTypeRegistrarTestStringMessage(qRegisterProtobufType<TestStringMessage>);
|
||||
static QtProtobuf::ProtoTypeRegistrar ProtoTypeRegistrarOptionalMessage(qRegisterProtobufType<OptionalMessage>);
|
||||
} // namespace qtprotobufnamespace::optional::tests
|
||||
|
||||
|
|
@ -1959,6 +1959,11 @@ SimpleStringMessage *ComplexMessage::testComplexField_p() const
|
|||
return dptr->m_testComplexField ? dptr->m_testComplexField.get() : nullptr;
|
||||
}
|
||||
|
||||
bool ComplexMessage::hasTestComplexField() const
|
||||
{
|
||||
return dptr->m_testComplexField.operator bool();
|
||||
}
|
||||
|
||||
SimpleStringMessage &ComplexMessage::testComplexField() const
|
||||
{
|
||||
return *dptr->m_testComplexField;
|
||||
|
|
|
|||
|
|
@ -710,6 +710,7 @@ public:
|
|||
|
||||
QtProtobuf::int32 testFieldInt() const;
|
||||
|
||||
bool hasTestComplexField() const;
|
||||
SimpleStringMessage &testComplexField() const;
|
||||
void clearTestComplexField();
|
||||
void setTestFieldInt(const QtProtobuf::int32 &testFieldInt);
|
||||
|
|
|
|||
|
|
@ -1959,6 +1959,11 @@ SimpleStringMessage *ComplexMessage::testComplexField_p() const
|
|||
return dptr->m_testComplexField ? dptr->m_testComplexField.get() : nullptr;
|
||||
}
|
||||
|
||||
bool ComplexMessage::hasTestComplexField() const
|
||||
{
|
||||
return dptr->m_testComplexField.operator bool();
|
||||
}
|
||||
|
||||
SimpleStringMessage &ComplexMessage::testComplexField() const
|
||||
{
|
||||
return *dptr->m_testComplexField;
|
||||
|
|
|
|||
|
|
@ -710,6 +710,7 @@ public:
|
|||
|
||||
QtProtobuf::int32 testFieldInt() const;
|
||||
|
||||
bool hasTestComplexField() const;
|
||||
SimpleStringMessage &testComplexField() const;
|
||||
void clearTestComplexField();
|
||||
void setTestFieldInt(const QtProtobuf::int32 &testFieldInt);
|
||||
|
|
|
|||
|
|
@ -338,6 +338,11 @@ SimpleStringMessage *ComplexMessage::testComplexField_p() const
|
|||
return dptr->m_testComplexField ? dptr->m_testComplexField.get() : nullptr;
|
||||
}
|
||||
|
||||
bool ComplexMessage::hasTestComplexField() const
|
||||
{
|
||||
return dptr->m_testComplexField.operator bool();
|
||||
}
|
||||
|
||||
SimpleStringMessage &ComplexMessage::testComplexField() const
|
||||
{
|
||||
return *dptr->m_testComplexField;
|
||||
|
|
|
|||
|
|
@ -122,6 +122,7 @@ public:
|
|||
|
||||
QtProtobuf::int32 testFieldInt() const;
|
||||
|
||||
bool hasTestComplexField() const;
|
||||
SimpleStringMessage &testComplexField() const;
|
||||
void clearTestComplexField();
|
||||
void setTestFieldInt(const QtProtobuf::int32 &testFieldInt);
|
||||
|
|
|
|||
|
|
@ -0,0 +1,572 @@
|
|||
/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */
|
||||
|
||||
#include "optional.qpb.h"
|
||||
#include <QtProtobuf/qprotobufserializer.h>
|
||||
|
||||
namespace qtprotobufnamespace::optional::tests {
|
||||
|
||||
class TestStringMessage_QtProtobufData : public QSharedData
|
||||
{
|
||||
public:
|
||||
TestStringMessage_QtProtobufData()
|
||||
: QSharedData()
|
||||
{
|
||||
}
|
||||
|
||||
TestStringMessage_QtProtobufData(const TestStringMessage_QtProtobufData &other)
|
||||
: QSharedData(other),
|
||||
m_stringField(other.m_stringField)
|
||||
{
|
||||
}
|
||||
|
||||
QString m_stringField;
|
||||
};
|
||||
|
||||
TestStringMessage::~TestStringMessage() = default;
|
||||
|
||||
static constexpr struct {
|
||||
QtProtobufPrivate::QProtobufPropertyOrdering::Data data;
|
||||
const std::array<uint, 5> qt_protobuf_TestStringMessage_uint_data;
|
||||
const char qt_protobuf_TestStringMessage_char_data[66];
|
||||
} qt_protobuf_TestStringMessage_metadata {
|
||||
// data
|
||||
{
|
||||
0, /* = version */
|
||||
1, /* = num fields */
|
||||
2, /* = field number offset */
|
||||
3, /* = property index offset */
|
||||
4, /* = field flags offset */
|
||||
52, /* = message full name length */
|
||||
},
|
||||
// uint_data
|
||||
{
|
||||
// JSON name offsets:
|
||||
53, /* = stringField */
|
||||
65, /* = end-of-string-marker */
|
||||
// Field numbers:
|
||||
2, /* = stringField */
|
||||
// Property indices:
|
||||
0, /* = stringField */
|
||||
// Field flags:
|
||||
QtProtobufPrivate::NoFlags, /* = stringField */
|
||||
},
|
||||
// char_data
|
||||
/* metadata char_data: */
|
||||
"qtprotobufnamespace.optional.tests.TestStringMessage\0" /* = full message name */
|
||||
/* field char_data: */
|
||||
"stringField\0"
|
||||
};
|
||||
|
||||
const QtProtobufPrivate::QProtobufPropertyOrdering TestStringMessage::propertyOrdering = {
|
||||
&qt_protobuf_TestStringMessage_metadata.data
|
||||
};
|
||||
|
||||
void TestStringMessage::registerTypes()
|
||||
{
|
||||
qRegisterMetaType<TestStringMessage>();
|
||||
qRegisterMetaType<TestStringMessageRepeated>();
|
||||
}
|
||||
|
||||
TestStringMessage::TestStringMessage()
|
||||
: QProtobufMessage(&TestStringMessage::staticMetaObject),
|
||||
dptr(new TestStringMessage_QtProtobufData)
|
||||
{
|
||||
}
|
||||
|
||||
TestStringMessage::TestStringMessage(const TestStringMessage &other)
|
||||
: QProtobufMessage(other),
|
||||
dptr(other.dptr)
|
||||
{
|
||||
}
|
||||
TestStringMessage &TestStringMessage::operator =(const TestStringMessage &other)
|
||||
{
|
||||
QProtobufMessage::operator=(other);
|
||||
dptr = other.dptr;
|
||||
return *this;
|
||||
}
|
||||
TestStringMessage::TestStringMessage(TestStringMessage &&other) noexcept
|
||||
: QProtobufMessage(std::move(other)),
|
||||
dptr(std::move(other.dptr))
|
||||
{
|
||||
}
|
||||
TestStringMessage &TestStringMessage::operator =(TestStringMessage &&other) noexcept
|
||||
{
|
||||
QProtobufMessage::operator=(std::move(other));
|
||||
dptr.swap(other.dptr);
|
||||
return *this;
|
||||
}
|
||||
bool TestStringMessage::operator ==(const TestStringMessage &other) const
|
||||
{
|
||||
return QProtobufMessage::isEqual(*this, other)
|
||||
&& dptr->m_stringField == other.dptr->m_stringField;
|
||||
}
|
||||
|
||||
bool TestStringMessage::operator !=(const TestStringMessage &other) const
|
||||
{
|
||||
return !this->operator ==(other);
|
||||
}
|
||||
|
||||
QString TestStringMessage::stringField() const
|
||||
{
|
||||
return dptr->m_stringField;
|
||||
}
|
||||
|
||||
void TestStringMessage::setStringField(const QString &stringField)
|
||||
{
|
||||
if (dptr->m_stringField != stringField) {
|
||||
dptr.detach();
|
||||
dptr->m_stringField = stringField;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
class OptionalMessage_QtProtobufData : public QSharedData
|
||||
{
|
||||
public:
|
||||
OptionalMessage_QtProtobufData()
|
||||
: QSharedData(),
|
||||
m_testField(0),
|
||||
m_testFieldBool(false),
|
||||
m_testFieldMessage(nullptr),
|
||||
m_testFieldMessageOpt(nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
OptionalMessage_QtProtobufData(const OptionalMessage_QtProtobufData &other)
|
||||
: QSharedData(other),
|
||||
m_testField(other.m_testField),
|
||||
m_testFieldBool(other.m_testFieldBool),
|
||||
m_testFieldBytes(other.m_testFieldBytes),
|
||||
m_testFieldString(other.m_testFieldString),
|
||||
m_testFieldMessage(other.m_testFieldMessage
|
||||
? new TestStringMessage(*other.m_testFieldMessage)
|
||||
: nullptr),
|
||||
m_testFieldMessageOpt(other.m_testFieldMessageOpt
|
||||
? new TestStringMessage(*other.m_testFieldMessageOpt)
|
||||
: nullptr)
|
||||
{
|
||||
}
|
||||
|
||||
QtProtobuf::sint32 m_testField;
|
||||
std::optional<QtProtobuf::sint32> m_testFieldOpt;
|
||||
bool m_testFieldBool;
|
||||
std::optional<bool> m_testFieldBoolOpt;
|
||||
QByteArray m_testFieldBytes;
|
||||
std::optional<QByteArray> m_testFieldBytesOpt;
|
||||
QString m_testFieldString;
|
||||
std::optional<QString> m_testFieldStringOpt;
|
||||
QtProtobufPrivate::QProtobufLazyMessagePointer<TestStringMessage> m_testFieldMessage;
|
||||
QtProtobufPrivate::QProtobufLazyMessagePointer<TestStringMessage> m_testFieldMessageOpt;
|
||||
};
|
||||
|
||||
OptionalMessage::~OptionalMessage() = default;
|
||||
|
||||
static constexpr struct {
|
||||
QtProtobufPrivate::QProtobufPropertyOrdering::Data data;
|
||||
const std::array<uint, 41> qt_protobuf_OptionalMessage_uint_data;
|
||||
const char qt_protobuf_OptionalMessage_char_data[211];
|
||||
} qt_protobuf_OptionalMessage_metadata {
|
||||
// data
|
||||
{
|
||||
0, /* = version */
|
||||
10, /* = num fields */
|
||||
11, /* = field number offset */
|
||||
21, /* = property index offset */
|
||||
31, /* = field flags offset */
|
||||
50, /* = message full name length */
|
||||
},
|
||||
// uint_data
|
||||
{
|
||||
// JSON name offsets:
|
||||
51, /* = testField */
|
||||
61, /* = testFieldOpt */
|
||||
74, /* = testFieldBool */
|
||||
88, /* = testFieldBoolOpt */
|
||||
105, /* = testFieldBytes */
|
||||
120, /* = testFieldBytesOpt */
|
||||
138, /* = testFieldString */
|
||||
154, /* = testFieldStringOpt */
|
||||
173, /* = testFieldMessage */
|
||||
190, /* = testFieldMessageOpt */
|
||||
210, /* = end-of-string-marker */
|
||||
// Field numbers:
|
||||
1, /* = testField */
|
||||
2, /* = testFieldOpt */
|
||||
3, /* = testFieldBool */
|
||||
4, /* = testFieldBoolOpt */
|
||||
5, /* = testFieldBytes */
|
||||
6, /* = testFieldBytesOpt */
|
||||
7, /* = testFieldString */
|
||||
8, /* = testFieldStringOpt */
|
||||
9, /* = testFieldMessage */
|
||||
10, /* = testFieldMessageOpt */
|
||||
// Property indices:
|
||||
0, /* = testField */
|
||||
1, /* = testFieldOpt */
|
||||
3, /* = testFieldBool */
|
||||
4, /* = testFieldBoolOpt */
|
||||
6, /* = testFieldBytes */
|
||||
7, /* = testFieldBytesOpt */
|
||||
9, /* = testFieldString */
|
||||
10, /* = testFieldStringOpt */
|
||||
12, /* = testFieldMessage */
|
||||
13, /* = testFieldMessageOpt */
|
||||
// Field flags:
|
||||
QtProtobufPrivate::NoFlags, /* = testField */
|
||||
QtProtobufPrivate::Optional, /* = testFieldOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldBool */
|
||||
QtProtobufPrivate::Optional, /* = testFieldBoolOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldBytes */
|
||||
QtProtobufPrivate::Optional, /* = testFieldBytesOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldString */
|
||||
QtProtobufPrivate::Optional, /* = testFieldStringOpt */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldMessage */
|
||||
QtProtobufPrivate::NoFlags, /* = testFieldMessageOpt */
|
||||
},
|
||||
// char_data
|
||||
/* metadata char_data: */
|
||||
"qtprotobufnamespace.optional.tests.OptionalMessage\0" /* = full message name */
|
||||
/* field char_data: */
|
||||
"testField\0testFieldOpt\0testFieldBool\0testFieldBoolOpt\0testFieldBytes\0"
|
||||
"testFieldBytesOpt\0testFieldString\0testFieldStringOpt\0testFieldMessage\0testFieldMessageOpt\0"
|
||||
};
|
||||
|
||||
const QtProtobufPrivate::QProtobufPropertyOrdering OptionalMessage::propertyOrdering = {
|
||||
&qt_protobuf_OptionalMessage_metadata.data
|
||||
};
|
||||
|
||||
void OptionalMessage::registerTypes()
|
||||
{
|
||||
qRegisterMetaType<OptionalMessage>();
|
||||
qRegisterMetaType<OptionalMessageRepeated>();
|
||||
}
|
||||
|
||||
OptionalMessage::OptionalMessage()
|
||||
: QProtobufMessage(&OptionalMessage::staticMetaObject),
|
||||
dptr(new OptionalMessage_QtProtobufData)
|
||||
{
|
||||
}
|
||||
|
||||
OptionalMessage::OptionalMessage(const OptionalMessage &other)
|
||||
: QProtobufMessage(other),
|
||||
dptr(other.dptr)
|
||||
{
|
||||
}
|
||||
OptionalMessage &OptionalMessage::operator =(const OptionalMessage &other)
|
||||
{
|
||||
QProtobufMessage::operator=(other);
|
||||
dptr = other.dptr;
|
||||
return *this;
|
||||
}
|
||||
OptionalMessage::OptionalMessage(OptionalMessage &&other) noexcept
|
||||
: QProtobufMessage(std::move(other)),
|
||||
dptr(std::move(other.dptr))
|
||||
{
|
||||
}
|
||||
OptionalMessage &OptionalMessage::operator =(OptionalMessage &&other) noexcept
|
||||
{
|
||||
QProtobufMessage::operator=(std::move(other));
|
||||
dptr.swap(other.dptr);
|
||||
return *this;
|
||||
}
|
||||
bool OptionalMessage::operator ==(const OptionalMessage &other) const
|
||||
{
|
||||
return QProtobufMessage::isEqual(*this, other)
|
||||
&& dptr->m_testField == other.dptr->m_testField
|
||||
&& dptr->m_testFieldBool == other.dptr->m_testFieldBool
|
||||
&& dptr->m_testFieldBytes == other.dptr->m_testFieldBytes
|
||||
&& dptr->m_testFieldString == other.dptr->m_testFieldString
|
||||
&& (dptr->m_testFieldMessage == other.dptr->m_testFieldMessage
|
||||
|| *dptr->m_testFieldMessage == *other.dptr->m_testFieldMessage);
|
||||
}
|
||||
|
||||
bool OptionalMessage::operator !=(const OptionalMessage &other) const
|
||||
{
|
||||
return !this->operator ==(other);
|
||||
}
|
||||
|
||||
QtProtobuf::sint32 OptionalMessage::testField() const
|
||||
{
|
||||
return dptr->m_testField;
|
||||
}
|
||||
|
||||
QtProtobuf::sint32 OptionalMessage::testFieldOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldOpt ?
|
||||
dptr->m_testFieldOpt.value() : QtProtobuf::sint32();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldOpt() const
|
||||
{
|
||||
return dptr->m_testFieldOpt.has_value();
|
||||
}
|
||||
QtProtobuf::sint32 OptionalMessage::testFieldOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldOpt.has_value());
|
||||
return dptr->m_testFieldOpt.value();
|
||||
}
|
||||
|
||||
bool OptionalMessage::testFieldBool() const
|
||||
{
|
||||
return dptr->m_testFieldBool;
|
||||
}
|
||||
|
||||
bool OptionalMessage::testFieldBoolOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldBoolOpt ?
|
||||
dptr->m_testFieldBoolOpt.value() : bool();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldBoolOpt() const
|
||||
{
|
||||
return dptr->m_testFieldBoolOpt.has_value();
|
||||
}
|
||||
bool OptionalMessage::testFieldBoolOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldBoolOpt.has_value());
|
||||
return dptr->m_testFieldBoolOpt.value();
|
||||
}
|
||||
|
||||
QByteArray OptionalMessage::testFieldBytes() const
|
||||
{
|
||||
return dptr->m_testFieldBytes;
|
||||
}
|
||||
|
||||
QByteArray OptionalMessage::testFieldBytesOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldBytesOpt ?
|
||||
dptr->m_testFieldBytesOpt.value() : QByteArray();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldBytesOpt() const
|
||||
{
|
||||
return dptr->m_testFieldBytesOpt.has_value();
|
||||
}
|
||||
QByteArray OptionalMessage::testFieldBytesOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldBytesOpt.has_value());
|
||||
return dptr->m_testFieldBytesOpt.value();
|
||||
}
|
||||
|
||||
QString OptionalMessage::testFieldString() const
|
||||
{
|
||||
return dptr->m_testFieldString;
|
||||
}
|
||||
|
||||
QString OptionalMessage::testFieldStringOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldStringOpt ?
|
||||
dptr->m_testFieldStringOpt.value() : QString();
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldStringOpt() const
|
||||
{
|
||||
return dptr->m_testFieldStringOpt.has_value();
|
||||
}
|
||||
QString OptionalMessage::testFieldStringOpt() const
|
||||
{
|
||||
Q_ASSERT(dptr->m_testFieldStringOpt.has_value());
|
||||
return dptr->m_testFieldStringOpt.value();
|
||||
}
|
||||
|
||||
TestStringMessage *OptionalMessage::testFieldMessage_p() const
|
||||
{
|
||||
return dptr->m_testFieldMessage ? dptr->m_testFieldMessage.get() : nullptr;
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldMessage() const
|
||||
{
|
||||
return dptr->m_testFieldMessage.operator bool();
|
||||
}
|
||||
|
||||
TestStringMessage &OptionalMessage::testFieldMessage() const
|
||||
{
|
||||
return *dptr->m_testFieldMessage;
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldMessage()
|
||||
{
|
||||
if (dptr->m_testFieldMessage) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessage.reset();
|
||||
}
|
||||
}
|
||||
|
||||
TestStringMessage *OptionalMessage::testFieldMessageOpt_p() const
|
||||
{
|
||||
return dptr->m_testFieldMessageOpt ? dptr->m_testFieldMessageOpt.get() : nullptr;
|
||||
}
|
||||
|
||||
bool OptionalMessage::hasTestFieldMessageOpt() const
|
||||
{
|
||||
return dptr->m_testFieldMessageOpt.operator bool();
|
||||
}
|
||||
|
||||
TestStringMessage &OptionalMessage::testFieldMessageOpt() const
|
||||
{
|
||||
return *dptr->m_testFieldMessageOpt;
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldMessageOpt()
|
||||
{
|
||||
if (dptr->m_testFieldMessageOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessageOpt.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestField(const QtProtobuf::sint32 &testField)
|
||||
{
|
||||
if (dptr->m_testField != testField) {
|
||||
dptr.detach();
|
||||
dptr->m_testField = testField;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldOpt(const QtProtobuf::sint32 &testFieldOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldOpt || dptr->m_testFieldOpt.value() != testFieldOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldOpt = testFieldOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldOpt_p(QtProtobuf::sint32 testFieldOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldOpt || dptr->m_testFieldOpt != testFieldOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldOpt = testFieldOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldOpt()
|
||||
{
|
||||
if (dptr->m_testFieldOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldBool(const bool &testFieldBool)
|
||||
{
|
||||
if (dptr->m_testFieldBool != testFieldBool) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBool = testFieldBool;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBoolOpt(const bool &testFieldBoolOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBoolOpt || dptr->m_testFieldBoolOpt.value() != testFieldBoolOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBoolOpt = testFieldBoolOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBoolOpt_p(bool testFieldBoolOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBoolOpt || dptr->m_testFieldBoolOpt != testFieldBoolOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBoolOpt = testFieldBoolOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldBoolOpt()
|
||||
{
|
||||
if (dptr->m_testFieldBoolOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBoolOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldBytes(const QByteArray &testFieldBytes)
|
||||
{
|
||||
if (dptr->m_testFieldBytes != testFieldBytes) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytes = testFieldBytes;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBytesOpt(const QByteArray &testFieldBytesOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBytesOpt || dptr->m_testFieldBytesOpt.value() != testFieldBytesOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytesOpt = testFieldBytesOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldBytesOpt_p(QByteArray testFieldBytesOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldBytesOpt || dptr->m_testFieldBytesOpt != testFieldBytesOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytesOpt = testFieldBytesOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldBytesOpt()
|
||||
{
|
||||
if (dptr->m_testFieldBytesOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldBytesOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldString(const QString &testFieldString)
|
||||
{
|
||||
if (dptr->m_testFieldString != testFieldString) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldString = testFieldString;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldStringOpt(const QString &testFieldStringOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldStringOpt || dptr->m_testFieldStringOpt.value() != testFieldStringOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldStringOpt = testFieldStringOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldStringOpt_p(QString testFieldStringOpt)
|
||||
{
|
||||
if (!dptr->m_testFieldStringOpt || dptr->m_testFieldStringOpt != testFieldStringOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldStringOpt = testFieldStringOpt;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::clearTestFieldStringOpt()
|
||||
{
|
||||
if (dptr->m_testFieldStringOpt.has_value()) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldStringOpt.reset();
|
||||
}}
|
||||
void OptionalMessage::setTestFieldMessage_p(TestStringMessage *testFieldMessage)
|
||||
{
|
||||
if (dptr->m_testFieldMessage.get() != testFieldMessage) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessage.reset(testFieldMessage);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldMessage(const TestStringMessage &testFieldMessage)
|
||||
{
|
||||
if (*dptr->m_testFieldMessage != testFieldMessage) {
|
||||
dptr.detach();
|
||||
*dptr->m_testFieldMessage = testFieldMessage;
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldMessageOpt_p(TestStringMessage *testFieldMessageOpt)
|
||||
{
|
||||
if (dptr->m_testFieldMessageOpt.get() != testFieldMessageOpt) {
|
||||
dptr.detach();
|
||||
dptr->m_testFieldMessageOpt.reset(testFieldMessageOpt);
|
||||
}
|
||||
}
|
||||
|
||||
void OptionalMessage::setTestFieldMessageOpt(const TestStringMessage &testFieldMessageOpt)
|
||||
{
|
||||
if (*dptr->m_testFieldMessageOpt != testFieldMessageOpt) {
|
||||
dptr.detach();
|
||||
*dptr->m_testFieldMessageOpt = testFieldMessageOpt;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace qtprotobufnamespace::optional::tests
|
||||
|
||||
#include "moc_optional.qpb.cpp"
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
/* This file is autogenerated. DO NOT CHANGE. All changes will be lost */
|
||||
|
||||
#ifndef QPROTOBUF_OPTIONAL_H
|
||||
#define QPROTOBUF_OPTIONAL_H
|
||||
|
||||
#include <QtProtobuf/qprotobufmessage.h>
|
||||
#include <QtProtobuf/qprotobufobject.h>
|
||||
#include <QtProtobuf/qprotobuflazymessagepointer.h>
|
||||
|
||||
#include <QtCore/qbytearray.h>
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtProtobuf/qprotobufoneof.h>
|
||||
#include <optional>
|
||||
|
||||
#include <QtCore/qmetatype.h>
|
||||
#include <QtCore/qlist.h>
|
||||
#include <QtCore/qshareddata.h>
|
||||
|
||||
#include <memory>
|
||||
|
||||
|
||||
namespace qtprotobufnamespace::optional::tests {
|
||||
class TestStringMessage;
|
||||
using TestStringMessageRepeated = QList<TestStringMessage>;
|
||||
namespace TestStringMessage_QtProtobufNested {
|
||||
enum class QtProtobufFieldEnum;
|
||||
} // namespace TestStringMessage_QtProtobufNested
|
||||
|
||||
class OptionalMessage;
|
||||
using OptionalMessageRepeated = QList<OptionalMessage>;
|
||||
namespace OptionalMessage_QtProtobufNested {
|
||||
enum class QtProtobufFieldEnum;
|
||||
} // namespace OptionalMessage_QtProtobufNested
|
||||
|
||||
|
||||
class TestStringMessage_QtProtobufData;
|
||||
class TestStringMessage : public QProtobufMessage
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROTOBUF_OBJECT
|
||||
Q_DECLARE_PROTOBUF_SERIALIZERS(TestStringMessage)
|
||||
Q_PROPERTY(QString stringField READ stringField WRITE setStringField SCRIPTABLE true)
|
||||
|
||||
public:
|
||||
using QtProtobufFieldEnum = TestStringMessage_QtProtobufNested::QtProtobufFieldEnum;
|
||||
TestStringMessage();
|
||||
~TestStringMessage();
|
||||
TestStringMessage(const TestStringMessage &other);
|
||||
TestStringMessage &operator =(const TestStringMessage &other);
|
||||
TestStringMessage(TestStringMessage &&other) noexcept;
|
||||
TestStringMessage &operator =(TestStringMessage &&other) noexcept;
|
||||
bool operator ==(const TestStringMessage &other) const;
|
||||
bool operator !=(const TestStringMessage &other) const;
|
||||
|
||||
QString stringField() const;
|
||||
void setStringField(const QString &stringField);
|
||||
static void registerTypes();
|
||||
|
||||
private:
|
||||
QExplicitlySharedDataPointer<TestStringMessage_QtProtobufData> dptr;
|
||||
};
|
||||
namespace TestStringMessage_QtProtobufNested {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class QtProtobufFieldEnum {
|
||||
StringFieldProtoFieldNumber = 2,
|
||||
};
|
||||
Q_ENUM_NS(QtProtobufFieldEnum)
|
||||
|
||||
} // namespace TestStringMessage_QtProtobufNested
|
||||
|
||||
class OptionalMessage_QtProtobufData;
|
||||
class OptionalMessage : public QProtobufMessage
|
||||
{
|
||||
Q_GADGET
|
||||
Q_PROTOBUF_OBJECT
|
||||
Q_DECLARE_PROTOBUF_SERIALIZERS(OptionalMessage)
|
||||
Q_PROPERTY(QtProtobuf::sint32 testField READ testField WRITE setTestField SCRIPTABLE true)
|
||||
Q_PROPERTY(QtProtobuf::sint32 testFieldOpt READ testFieldOpt_p WRITE setTestFieldOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldOpt READ hasTestFieldOpt)
|
||||
Q_PROPERTY(bool testFieldBool READ testFieldBool WRITE setTestFieldBool SCRIPTABLE true)
|
||||
Q_PROPERTY(bool testFieldBoolOpt READ testFieldBoolOpt_p WRITE setTestFieldBoolOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldBoolOpt READ hasTestFieldBoolOpt)
|
||||
Q_PROPERTY(QByteArray testFieldBytes READ testFieldBytes WRITE setTestFieldBytes SCRIPTABLE true)
|
||||
Q_PROPERTY(QByteArray testFieldBytesOpt READ testFieldBytesOpt_p WRITE setTestFieldBytesOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldBytesOpt READ hasTestFieldBytesOpt)
|
||||
Q_PROPERTY(QString testFieldString READ testFieldString WRITE setTestFieldString SCRIPTABLE true)
|
||||
Q_PROPERTY(QString testFieldStringOpt READ testFieldStringOpt_p WRITE setTestFieldStringOpt_p)
|
||||
Q_PROPERTY(bool hasTestFieldStringOpt READ hasTestFieldStringOpt)
|
||||
Q_PROPERTY(qtprotobufnamespace::optional::tests::TestStringMessage *testFieldMessage_p READ testFieldMessage_p WRITE setTestFieldMessage_p)
|
||||
Q_PROPERTY(qtprotobufnamespace::optional::tests::TestStringMessage *testFieldMessageOpt_p READ testFieldMessageOpt_p WRITE setTestFieldMessageOpt_p)
|
||||
|
||||
public:
|
||||
using QtProtobufFieldEnum = OptionalMessage_QtProtobufNested::QtProtobufFieldEnum;
|
||||
OptionalMessage();
|
||||
~OptionalMessage();
|
||||
OptionalMessage(const OptionalMessage &other);
|
||||
OptionalMessage &operator =(const OptionalMessage &other);
|
||||
OptionalMessage(OptionalMessage &&other) noexcept;
|
||||
OptionalMessage &operator =(OptionalMessage &&other) noexcept;
|
||||
bool operator ==(const OptionalMessage &other) const;
|
||||
bool operator !=(const OptionalMessage &other) const;
|
||||
|
||||
QtProtobuf::sint32 testField() const;
|
||||
|
||||
bool hasTestFieldOpt() const;
|
||||
QtProtobuf::sint32 testFieldOpt() const;
|
||||
|
||||
bool testFieldBool() const;
|
||||
|
||||
bool hasTestFieldBoolOpt() const;
|
||||
bool testFieldBoolOpt() const;
|
||||
|
||||
QByteArray testFieldBytes() const;
|
||||
|
||||
bool hasTestFieldBytesOpt() const;
|
||||
QByteArray testFieldBytesOpt() const;
|
||||
|
||||
QString testFieldString() const;
|
||||
|
||||
bool hasTestFieldStringOpt() const;
|
||||
QString testFieldStringOpt() const;
|
||||
|
||||
bool hasTestFieldMessage() const;
|
||||
TestStringMessage &testFieldMessage() const;
|
||||
void clearTestFieldMessage();
|
||||
|
||||
bool hasTestFieldMessageOpt() const;
|
||||
TestStringMessage &testFieldMessageOpt() const;
|
||||
void clearTestFieldMessageOpt();
|
||||
void setTestField(const QtProtobuf::sint32 &testField);
|
||||
void setTestFieldOpt(const QtProtobuf::sint32 &testFieldOpt);
|
||||
void clearTestFieldOpt();
|
||||
void setTestFieldBool(const bool &testFieldBool);
|
||||
void setTestFieldBoolOpt(const bool &testFieldBoolOpt);
|
||||
void clearTestFieldBoolOpt();
|
||||
void setTestFieldBytes(const QByteArray &testFieldBytes);
|
||||
void setTestFieldBytesOpt(const QByteArray &testFieldBytesOpt);
|
||||
void clearTestFieldBytesOpt();
|
||||
void setTestFieldString(const QString &testFieldString);
|
||||
void setTestFieldStringOpt(const QString &testFieldStringOpt);
|
||||
void clearTestFieldStringOpt();
|
||||
void setTestFieldMessage(const TestStringMessage &testFieldMessage);
|
||||
void setTestFieldMessageOpt(const TestStringMessage &testFieldMessageOpt);
|
||||
static void registerTypes();
|
||||
|
||||
private:
|
||||
QtProtobuf::sint32 testFieldOpt_p() const;
|
||||
bool testFieldBoolOpt_p() const;
|
||||
QByteArray testFieldBytesOpt_p() const;
|
||||
QString testFieldStringOpt_p() const;
|
||||
TestStringMessage *testFieldMessage_p() const;
|
||||
TestStringMessage *testFieldMessageOpt_p() const;
|
||||
void setTestFieldOpt_p(QtProtobuf::sint32 testFieldOpt);
|
||||
void setTestFieldBoolOpt_p(bool testFieldBoolOpt);
|
||||
void setTestFieldBytesOpt_p(QByteArray testFieldBytesOpt);
|
||||
void setTestFieldStringOpt_p(QString testFieldStringOpt);
|
||||
void setTestFieldMessage_p(TestStringMessage *testFieldMessage);
|
||||
void setTestFieldMessageOpt_p(TestStringMessage *testFieldMessageOpt);
|
||||
QExplicitlySharedDataPointer<OptionalMessage_QtProtobufData> dptr;
|
||||
};
|
||||
namespace OptionalMessage_QtProtobufNested {
|
||||
Q_NAMESPACE
|
||||
|
||||
enum class QtProtobufFieldEnum {
|
||||
TestFieldProtoFieldNumber = 1,
|
||||
TestFieldOptProtoFieldNumber = 2,
|
||||
TestFieldBoolProtoFieldNumber = 3,
|
||||
TestFieldBoolOptProtoFieldNumber = 4,
|
||||
TestFieldBytesProtoFieldNumber = 5,
|
||||
TestFieldBytesOptProtoFieldNumber = 6,
|
||||
TestFieldStringProtoFieldNumber = 7,
|
||||
TestFieldStringOptProtoFieldNumber = 8,
|
||||
TestFieldMessageProtoFieldNumber = 9,
|
||||
TestFieldMessageOptProtoFieldNumber = 10,
|
||||
};
|
||||
Q_ENUM_NS(QtProtobufFieldEnum)
|
||||
|
||||
} // namespace OptionalMessage_QtProtobufNested
|
||||
} // namespace qtprotobufnamespace::optional::tests
|
||||
|
||||
Q_DECLARE_METATYPE(qtprotobufnamespace::optional::tests::TestStringMessage)
|
||||
Q_DECLARE_METATYPE(qtprotobufnamespace::optional::tests::OptionalMessage)
|
||||
#endif // QPROTOBUF_OPTIONAL_H
|
||||
|
|
@ -347,6 +347,11 @@ SimpleIntMessageExt *NoPackageExternalMessage::testField_p() const
|
|||
return dptr->m_testField ? dptr->m_testField.get() : nullptr;
|
||||
}
|
||||
|
||||
bool NoPackageExternalMessage::hasTestField() const
|
||||
{
|
||||
return dptr->m_testField.operator bool();
|
||||
}
|
||||
|
||||
SimpleIntMessageExt &NoPackageExternalMessage::testField() const
|
||||
{
|
||||
return *dptr->m_testField;
|
||||
|
|
@ -487,6 +492,11 @@ SimpleIntMessage *NoPackageMessage::testField_p() const
|
|||
return dptr->m_testField ? dptr->m_testField.get() : nullptr;
|
||||
}
|
||||
|
||||
bool NoPackageMessage::hasTestField() const
|
||||
{
|
||||
return dptr->m_testField.operator bool();
|
||||
}
|
||||
|
||||
SimpleIntMessage &NoPackageMessage::testField() const
|
||||
{
|
||||
return *dptr->m_testField;
|
||||
|
|
|
|||
|
|
@ -162,6 +162,7 @@ public:
|
|||
bool operator ==(const NoPackageExternalMessage &other) const;
|
||||
bool operator !=(const NoPackageExternalMessage &other) const;
|
||||
|
||||
bool hasTestField() const;
|
||||
SimpleIntMessageExt &testField() const;
|
||||
void clearTestField();
|
||||
void setTestField(const SimpleIntMessageExt &testField);
|
||||
|
|
@ -204,6 +205,7 @@ public:
|
|||
bool operator ==(const NoPackageMessage &other) const;
|
||||
bool operator !=(const NoPackageMessage &other) const;
|
||||
|
||||
bool hasTestField() const;
|
||||
SimpleIntMessage &testField() const;
|
||||
void clearTestField();
|
||||
void setTestField(const SimpleIntMessage &testField);
|
||||
|
|
|
|||
|
|
@ -2004,6 +2004,11 @@ SimpleStringMessage *ComplexMessage::testComplexField_p() const
|
|||
return dptr->m_testComplexField ? dptr->m_testComplexField.get() : nullptr;
|
||||
}
|
||||
|
||||
bool ComplexMessage::hasTestComplexField() const
|
||||
{
|
||||
return dptr->m_testComplexField.operator bool();
|
||||
}
|
||||
|
||||
SimpleStringMessage &ComplexMessage::testComplexField() const
|
||||
{
|
||||
return *dptr->m_testComplexField;
|
||||
|
|
|
|||
|
|
@ -766,6 +766,7 @@ public:
|
|||
|
||||
QtProtobuf::int32 testFieldInt() const;
|
||||
|
||||
bool hasTestComplexField() const;
|
||||
SimpleStringMessage &testComplexField() const;
|
||||
void clearTestComplexField();
|
||||
void setTestFieldInt(const QtProtobuf::int32 &testFieldInt);
|
||||
|
|
|
|||
|
|
@ -224,6 +224,11 @@ void tst_qtprotobufgen::cmakeGeneratedFile_data()
|
|||
<< "/folder/qtprotobufnamespace/tests/"
|
||||
<< QString(extension);
|
||||
|
||||
QTest::addRow("optional%s", extension.data())
|
||||
<< "optional"
|
||||
<< "/folder/qtprotobufnamespace/optional/tests/"
|
||||
<< QString(extension);
|
||||
|
||||
QTest::addRow("repeatedmessages%s", extension.data())
|
||||
<< "repeatedmessages"
|
||||
<< "/folder/qtprotobufnamespace/tests/"
|
||||
|
|
@ -331,6 +336,13 @@ void tst_qtprotobufgen::cmdLineGeneratedFile_data()
|
|||
<< QString(extension)
|
||||
<< "qtprotobufnamespace/tests/";
|
||||
|
||||
QTest::addRow("optional%s", extension.data())
|
||||
<< "optional"
|
||||
<< "GENERATE_PACKAGE_SUBFOLDERS"
|
||||
<< "/folder/"
|
||||
<< QString(extension)
|
||||
<< "qtprotobufnamespace/optional/tests/";
|
||||
|
||||
QTest::addRow("repeatedmessages%s", extension.data())
|
||||
<< "repeatedmessages"
|
||||
<< "GENERATE_PACKAGE_SUBFOLDERS"
|
||||
|
|
@ -468,6 +480,11 @@ void tst_qtprotobufgen::cmdLineGeneratedNoOptions_data()
|
|||
<< "/no-options/"
|
||||
<< QString(extension);
|
||||
|
||||
QTest::addRow("optional%s", extension.data())
|
||||
<< "optional"
|
||||
<< "/no-options/"
|
||||
<< QString(extension);
|
||||
|
||||
QTest::addRow("repeatedmessages%s", extension.data())
|
||||
<< "repeatedmessages"
|
||||
<< "/no-options/"
|
||||
|
|
|
|||
|
|
@ -4,6 +4,19 @@ syntax = "proto3";
|
|||
|
||||
package qtprotobufnamespace.optional.tests;
|
||||
|
||||
message OptionalMessage {
|
||||
optional sint32 testField = 2;
|
||||
message TestStringMessage {
|
||||
string stringField = 2;
|
||||
}
|
||||
|
||||
message OptionalMessage {
|
||||
sint32 testField = 1;
|
||||
optional sint32 testFieldOpt = 2;
|
||||
bool testFieldBool = 3;
|
||||
optional bool testFieldBoolOpt = 4;
|
||||
bytes testFieldBytes = 5;
|
||||
optional bytes testFieldBytesOpt = 6;
|
||||
string testFieldString = 7;
|
||||
optional string testFieldStringOpt = 8;
|
||||
TestStringMessage testFieldMessage = 9;
|
||||
optional TestStringMessage testFieldMessageOpt = 10;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue