|
@@ -67,12 +67,14 @@ namespace {
|
|
static const char *sfint64ListTypeName = "sfint64List";
|
|
static const char *sfint64ListTypeName = "sfint64List";
|
|
}
|
|
}
|
|
|
|
|
|
-QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue, int fieldIndex, const QLatin1Literal &typeName) const
|
|
|
|
|
|
+QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue, int fieldIndex, const QMetaProperty &metaProperty) const
|
|
{
|
|
{
|
|
- qProtoDebug() << __func__ << "propertyValue" << propertyValue << "fieldIndex" << fieldIndex << "typeName" << typeName;
|
|
|
|
|
|
+ QLatin1Literal typeName(metaProperty.typeName());
|
|
QByteArray result;
|
|
QByteArray result;
|
|
WireTypes type = UnknownWireType;
|
|
WireTypes type = UnknownWireType;
|
|
- int resultSize = result.size();
|
|
|
|
|
|
+ qProtoDebug() << __func__ << "propertyValue" << propertyValue << "fieldIndex" << fieldIndex << "typeName"
|
|
|
|
+ << typeName << static_cast<QMetaType::Type>(propertyValue.type());
|
|
|
|
+
|
|
switch (static_cast<QMetaType::Type>(propertyValue.type())) {
|
|
switch (static_cast<QMetaType::Type>(propertyValue.type())) {
|
|
case QMetaType::Int:
|
|
case QMetaType::Int:
|
|
type = Varint;
|
|
type = Varint;
|
|
@@ -86,7 +88,7 @@ QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue,
|
|
} else {
|
|
} else {
|
|
result.append(serializeVarint(propertyValue.toLongLong()));
|
|
result.append(serializeVarint(propertyValue.toLongLong()));
|
|
}
|
|
}
|
|
- if (resultSize == result.size()) {
|
|
|
|
|
|
+ if (0 == result.size()) {
|
|
fieldIndex = NotUsedFieldIndex;
|
|
fieldIndex = NotUsedFieldIndex;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -102,7 +104,7 @@ QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue,
|
|
} else {
|
|
} else {
|
|
result.append(serializeVarint(propertyValue.toLongLong()));
|
|
result.append(serializeVarint(propertyValue.toLongLong()));
|
|
}
|
|
}
|
|
- if (resultSize == result.size()) {
|
|
|
|
|
|
+ if (0 == result.size()) {
|
|
fieldIndex = NotUsedFieldIndex;
|
|
fieldIndex = NotUsedFieldIndex;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -116,7 +118,7 @@ QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue,
|
|
break;
|
|
break;
|
|
case QMetaType::QString:
|
|
case QMetaType::QString:
|
|
type = LengthDelimited;
|
|
type = LengthDelimited;
|
|
- result.append(serializeLengthDelimited(propertyValue.toString().toUtf8()));
|
|
|
|
|
|
+ result.append(serializeLengthDelimited(propertyValue.toString()));
|
|
break;
|
|
break;
|
|
case QMetaType::QByteArray:
|
|
case QMetaType::QByteArray:
|
|
type = LengthDelimited;
|
|
type = LengthDelimited;
|
|
@@ -131,8 +133,13 @@ QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue,
|
|
result.append(serializeListType(propertyValue.value<QByteArrayList>(), fieldIndex));
|
|
result.append(serializeListType(propertyValue.value<QByteArrayList>(), fieldIndex));
|
|
break;
|
|
break;
|
|
case QMetaType::User:
|
|
case QMetaType::User:
|
|
- type = LengthDelimited;
|
|
|
|
- result.append(serializeUserType(propertyValue, fieldIndex, typeName));
|
|
|
|
|
|
+ if(metaProperty.isEnumType()) {
|
|
|
|
+ type = Varint;
|
|
|
|
+ result.append(serializeVarint(propertyValue.toLongLong()));
|
|
|
|
+ } else {
|
|
|
|
+ type = LengthDelimited;
|
|
|
|
+ result.append(serializeUserType(propertyValue, fieldIndex, typeName));
|
|
|
|
+ }
|
|
break;
|
|
break;
|
|
case QMetaType::UInt:
|
|
case QMetaType::UInt:
|
|
if (typeName == fint32TypeNameP
|
|
if (typeName == fint32TypeNameP
|
|
@@ -143,7 +150,7 @@ QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue,
|
|
type = Varint;
|
|
type = Varint;
|
|
result.append(serializeVarint(propertyValue.toUInt()));
|
|
result.append(serializeVarint(propertyValue.toUInt()));
|
|
}
|
|
}
|
|
- if (resultSize == result.size()) {
|
|
|
|
|
|
+ if (0 == result.size()) {
|
|
fieldIndex = NotUsedFieldIndex;
|
|
fieldIndex = NotUsedFieldIndex;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
@@ -156,14 +163,14 @@ QByteArray ProtobufObjectPrivate::serializeValue(const QVariant &propertyValue,
|
|
type = Varint;
|
|
type = Varint;
|
|
result.append(serializeVarint(propertyValue.toULongLong()));
|
|
result.append(serializeVarint(propertyValue.toULongLong()));
|
|
}
|
|
}
|
|
- if (resultSize == result.size()) {
|
|
|
|
|
|
+ if (0 == result.size()) {
|
|
fieldIndex = NotUsedFieldIndex;
|
|
fieldIndex = NotUsedFieldIndex;
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
case QMetaType::Bool:
|
|
case QMetaType::Bool:
|
|
type = Varint;
|
|
type = Varint;
|
|
result.append(serializeVarint(propertyValue.toUInt()));
|
|
result.append(serializeVarint(propertyValue.toUInt()));
|
|
- if (resultSize == result.size()) {
|
|
|
|
|
|
+ if (0 == result.size()) {
|
|
fieldIndex = NotUsedFieldIndex;
|
|
fieldIndex = NotUsedFieldIndex;
|
|
}
|
|
}
|
|
break;
|
|
break;
|