mirror of
https://github.com/romixlab/qmsgpack.git
synced 2025-07-31 19:04:26 +02:00
work in progress...
This commit is contained in:
17
main.cpp
Normal file
17
main.cpp
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
#include <QCoreApplication>
|
||||||
|
#include <msgpack.h>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
void test(quint8 *p) {
|
||||||
|
p++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char *argv[])
|
||||||
|
{
|
||||||
|
QCoreApplication a(argc, argv);
|
||||||
|
|
||||||
|
qDebug() << "MsgPack";
|
||||||
|
qDebug() << MsgPack::deserialize(QByteArray::fromHex("fffeece1e0"));
|
||||||
|
|
||||||
|
return a.exec();
|
||||||
|
}
|
29
msgpack.cpp
Normal file
29
msgpack.cpp
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#include "msgpack.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
|
QVariantList MsgPack::deserialize(const QByteArray &data)
|
||||||
|
{
|
||||||
|
QVariantList d;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
quint8 *p = (quint8 *)data.data();
|
||||||
|
while (i < data.size()) {
|
||||||
|
if (p[i] <= 127) { // positive fixint 0x00 - 0x7f
|
||||||
|
quint32 val = (quint32)p[i];
|
||||||
|
d.append(QVariant(val));
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
if (p[i] >= 0xe0) { // negative fixint 0xe0 - 0xff
|
||||||
|
quint8 val8 = (quint8)p[i];
|
||||||
|
val8 &= ~((1 << 7) | (1 << 6) | (1 << 5));
|
||||||
|
qint32 val = 31 - val8;
|
||||||
|
val ^= 0xffffffff;
|
||||||
|
d.append(QVariant((qint32)val));
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return d;
|
||||||
|
}
|
12
msgpack.h
Normal file
12
msgpack.h
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
#ifndef MSGPACK_H
|
||||||
|
#define MSGPACK_H
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QVariantList>
|
||||||
|
|
||||||
|
namespace MsgPack
|
||||||
|
{
|
||||||
|
|
||||||
|
QVariantList deserialize(const QByteArray &data);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MSGPACK_H
|
6
private/msgpack_p.cpp
Normal file
6
private/msgpack_p.cpp
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
#include "msgpack_p.h"
|
||||||
|
|
||||||
|
static quint8 MsgPackPrivate::data_sizes[] = {
|
||||||
|
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // fixmap upto 15 elements
|
||||||
|
|
||||||
|
};
|
33
private/msgpack_p.h
Normal file
33
private/msgpack_p.h
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
#ifndef MSGPACK_P_H
|
||||||
|
#define MSGPACK_P_H
|
||||||
|
#include <QVariant>
|
||||||
|
|
||||||
|
/* parser functions:
|
||||||
|
* QVariant _type_(quint8 *p, int &i);
|
||||||
|
* parses some type, which data is stored at p
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace MsgPackPrivate
|
||||||
|
{
|
||||||
|
/* data sizes for types from 0x7f to 0xe0
|
||||||
|
* (without positive and negative fixint)
|
||||||
|
** fixed size types:
|
||||||
|
* possible values: 1, 2, 3, 4, 5, 6, 9, 10, 18 - bytes
|
||||||
|
* 254 - size is in next 1 byte
|
||||||
|
* 253 - 2
|
||||||
|
* 251 - 4
|
||||||
|
** ext formats:
|
||||||
|
* 126 - size is in next byte + 1 type byte
|
||||||
|
* 125 - 2 byte size + 1 type byte
|
||||||
|
* 123 - 4 byte size + 1 type byte
|
||||||
|
*/
|
||||||
|
|
||||||
|
static quint8 data_sizes[96];
|
||||||
|
|
||||||
|
QVariant positive_fixint(quint8 *p);
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // MSGPACK_P_H
|
BIN
private/types.gnumeric
Normal file
BIN
private/types.gnumeric
Normal file
Binary file not shown.
24
qmsgpack.pro
Normal file
24
qmsgpack.pro
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#-------------------------------------------------
|
||||||
|
#
|
||||||
|
# Project created by QtCreator 2014-09-07T17:43:05
|
||||||
|
#
|
||||||
|
#-------------------------------------------------
|
||||||
|
|
||||||
|
QT += core
|
||||||
|
|
||||||
|
QT -= gui
|
||||||
|
|
||||||
|
TARGET = qmsgpack
|
||||||
|
#CONFIG += console
|
||||||
|
CONFIG -= app_bundle
|
||||||
|
|
||||||
|
TEMPLATE = app
|
||||||
|
|
||||||
|
|
||||||
|
SOURCES += main.cpp \
|
||||||
|
msgpack.cpp \
|
||||||
|
private/msgpack_p.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
|
msgpack.h \
|
||||||
|
private/msgpack_p.h
|
Reference in New Issue
Block a user