user type packing implemented

This commit is contained in:
Roman
2014-09-18 23:47:58 +04:00
parent 0e5c49f36d
commit 98cf9ff8ee
7 changed files with 97 additions and 29 deletions
+16 -22
View File
@@ -1,18 +1,19 @@
#include <QCoreApplication>
#include <msgpack.h>
#include <QDebug>
#include <QDataStream>
#include <QPoint>
#include <vector>
//int is_big_endian(void)
//{
// union {
// quint32 i;
// char c[4];
// } bint = {0x01020304};
// return bint.c[0] == 1;
//}
quint32 packQPoint(const QVariant &variant, QByteArray &data, bool write)
{
if (write) {
data.resize(8);
QDataStream out(&data, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_5_3);
out << variant.toPoint();
}
return 8;
}
int main(int argc, char *argv[])
{
@@ -20,19 +21,12 @@ int main(int argc, char *argv[])
Q_UNUSED(argv)
//QCoreApplication a(argc, argv);
// qDebug() << "MsgPack";
// qDebug() << MsgPack::deserialize(QByteArray::fromHex("dc 00 33 c2 c3 c0 00 00 00 00 00 00 00 00 00 ff ff ff ff ff 7f 7f cc ff cd ff ff ce ff ff ff ff e0 e0 d1 ff 80 d2 ff ff 80 00 d3 ff ff ff ff 80 00 00 00 00 00 01 ff a1 61 a1 61 a1 61 a0 a0 a0 91 00 91 00 91 00 90 90 90 80 80 80 81 a1 61 61 81 a1 61 61 81 a1 61 61 91 90 91 91 a1 61"));
MsgPack::registerPacker(QMetaType::QPoint, 7, packQPoint);
QVariantList l;
QVariantMap map;
map["key"] = "val";
map["key2"] = 123;
map["key3"] = 1.2;
l << map;
qDebug() << l[0].type();
QByteArray arr = MsgPack::pack(map);
l << QPoint(1, 2);
QByteArray arr = MsgPack::pack(l);
qDebug() << arr.toBase64();