Merge pull request #12 from anton-dutov/nil-pack

Nil pack
This commit is contained in:
Roman
2015-06-29 20:36:29 +03:00
5 changed files with 30 additions and 2 deletions
+11 -1
View File
@@ -19,7 +19,10 @@ 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())
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);
@@ -49,6 +52,13 @@ 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 = 0xc0;
return p + 1;
}
quint8 *MsgPackPrivate::pack_int(qint32 i, quint8 *p, bool wr)
{
if (i >= -32 && i <= 127) {