Nil packing and unpacking fix

This commit is contained in:
Roman Isaikin
2015-12-31 10:36:25 +03:00
parent 349c5051d6
commit b23c76ddf0
8 changed files with 31 additions and 5 deletions
+9 -1
View File
@@ -18,7 +18,9 @@ QReadWriteLock MsgPackPrivate::packers_lock;
quint8 *MsgPackPrivate::pack(const QVariant &v, quint8 *p, bool wr, QVector<QByteArray> &user_data)
{
QMetaType::Type t = (QMetaType::Type)v.type();
if (t == QMetaType::Int)
if (v.isNull() && !v.isValid())
p = pack_nil(p, wr);
else if (t == QMetaType::Int)
p = pack_int(v.toInt(), p, wr);
else if (t == QMetaType::UInt)
p = pack_uint(v.toUInt(), p, wr);
@@ -59,6 +61,12 @@ quint8 *MsgPackPrivate::pack(const QVariant &v, quint8 *p, bool wr, QVector<QByt
return p;
}
quint8 *MsgPackPrivate::pack_nil(quint8 *p, bool wr)
{
if (wr) *p = MsgPack::FirstByte::NIL;
return p + 1;
}
quint8 *MsgPackPrivate::pack_int(qint32 i, quint8 *p, bool wr)
{
if (i >= -32 && i <= 127) {