mirror of
https://github.com/romixlab/qmsgpack.git
synced 2025-07-29 18:07:16 +02:00
Pack QMetaType::Nullptr QVariant's as nil.
This commit is contained in:
@ -20,7 +20,7 @@ QReadWriteLock MsgPackPrivate::packers_lock;
|
|||||||
quint8 *MsgPackPrivate::pack(const QVariant &v, quint8 *p, bool wr, QVector<QByteArray> &user_data)
|
quint8 *MsgPackPrivate::pack(const QVariant &v, quint8 *p, bool wr, QVector<QByteArray> &user_data)
|
||||||
{
|
{
|
||||||
QMetaType::Type t = (QMetaType::Type)v.type();
|
QMetaType::Type t = (QMetaType::Type)v.type();
|
||||||
if (v.isNull() && !v.isValid())
|
if ((v.isNull() && !v.isValid()) || t == QMetaType::Nullptr)
|
||||||
p = pack_nil(p, wr);
|
p = pack_nil(p, wr);
|
||||||
else if (t == QMetaType::Int)
|
else if (t == QMetaType::Int)
|
||||||
p = pack_int(v.toInt(), p, wr);
|
p = pack_int(v.toInt(), p, wr);
|
||||||
|
@ -5,12 +5,14 @@
|
|||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
#include "msgpack.h"
|
#include "msgpack.h"
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
#include <QJsonObject>
|
||||||
|
|
||||||
class PackTest : public QObject
|
class PackTest : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
private Q_SLOTS:
|
private Q_SLOTS:
|
||||||
|
void test_nil();
|
||||||
void test_bool();
|
void test_bool();
|
||||||
void test_fixint();
|
void test_fixint();
|
||||||
void test_integer8();
|
void test_integer8();
|
||||||
@ -23,6 +25,18 @@ private Q_SLOTS:
|
|||||||
void test_array();
|
void test_array();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void PackTest::test_nil()
|
||||||
|
{
|
||||||
|
QJsonObject j;
|
||||||
|
j.insert("nil", QJsonValue::Null);
|
||||||
|
QVariant v = j.toVariantMap()["nil"];
|
||||||
|
QVERIFY((QMetaType::Type)v.type() == QMetaType::Nullptr);
|
||||||
|
QByteArray arr = MsgPack::pack(v);
|
||||||
|
quint8 *p = (quint8 *)arr.data();
|
||||||
|
QVERIFY(arr.size() == 1);
|
||||||
|
QVERIFY(p[0] == 0xc0);
|
||||||
|
}
|
||||||
|
|
||||||
void PackTest::test_bool()
|
void PackTest::test_bool()
|
||||||
{
|
{
|
||||||
QByteArray arr = MsgPack::pack(false);
|
QByteArray arr = MsgPack::pack(false);
|
||||||
|
Reference in New Issue
Block a user