mirror of
https://github.com/romixlab/qmsgpack.git
synced 2025-08-02 19:54:29 +02:00
MsgPackStream work (now working now)
This commit is contained in:
@@ -28,7 +28,6 @@ SOURCES += msgpack.cpp \
|
|||||||
private/pack_p.cpp \
|
private/pack_p.cpp \
|
||||||
private/unpack_p.cpp \
|
private/unpack_p.cpp \
|
||||||
private/qt_types_p.cpp \
|
private/qt_types_p.cpp \
|
||||||
msgpack_ext.cpp \
|
|
||||||
stream.cpp
|
stream.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
@@ -39,5 +38,4 @@ HEADERS += \
|
|||||||
msgpack_common.h \
|
msgpack_common.h \
|
||||||
msgpack_export.h \
|
msgpack_export.h \
|
||||||
private/qt_types_p.h \
|
private/qt_types_p.h \
|
||||||
msgpack_ext.h \
|
|
||||||
stream.h
|
stream.h
|
||||||
|
@@ -2,7 +2,6 @@
|
|||||||
#include "pack_p.h"
|
#include "pack_p.h"
|
||||||
#include "unpack_p.h"
|
#include "unpack_p.h"
|
||||||
#include "sysdep.h"
|
#include "sysdep.h"
|
||||||
#include "../msgpack_ext.h"
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
|
||||||
@@ -187,90 +186,90 @@ quint8 MsgPackPrivate::pack_two_integers(qint32 a, qint32 b, quint8 *to, bool wr
|
|||||||
|
|
||||||
quint32 MsgPackPrivate::pack_qpoint(const QVariant &variant, QByteArray &data, bool write)
|
quint32 MsgPackPrivate::pack_qpoint(const QVariant &variant, QByteArray &data, bool write)
|
||||||
{
|
{
|
||||||
QPoint pt = variant.toPoint();
|
// QPoint pt = variant.toPoint();
|
||||||
quint8 size = pack_two_integers(pt.x(), pt.y(), 0, false);
|
// quint8 size = pack_two_integers(pt.x(), pt.y(), 0, false);
|
||||||
if (write) {
|
// if (write) {
|
||||||
data.resize(size);
|
// data.resize(size);
|
||||||
pack_two_integers(pt.x(), pt.y(), (quint8 *)data.data(), true);
|
// pack_two_integers(pt.x(), pt.y(), (quint8 *)data.data(), true);
|
||||||
}
|
// }
|
||||||
return size;
|
// return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MsgPackPrivate::unpack_qpoint(const QByteArray &data)
|
QVariant MsgPackPrivate::unpack_qpoint(const QByteArray &data)
|
||||||
{
|
{
|
||||||
quint8 *p = (quint8 *)data.data();
|
// quint8 *p = (quint8 *)data.data();
|
||||||
qint32 x;
|
// qint32 x;
|
||||||
bool ok;
|
// bool ok;
|
||||||
p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
QPoint pt;
|
// QPoint pt;
|
||||||
pt.setX(x);
|
// pt.setX(x);
|
||||||
MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
pt.setY(x);
|
// pt.setY(x);
|
||||||
return pt;
|
// return pt;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 MsgPackPrivate::pack_qsize(const QVariant &variant, QByteArray &data, bool write)
|
quint32 MsgPackPrivate::pack_qsize(const QVariant &variant, QByteArray &data, bool write)
|
||||||
{
|
{
|
||||||
QSize sz = variant.toSize();
|
// QSize sz = variant.toSize();
|
||||||
quint8 size = pack_two_integers(sz.width(), sz.height(), 0, false);
|
// quint8 size = pack_two_integers(sz.width(), sz.height(), 0, false);
|
||||||
if (write) {
|
// if (write) {
|
||||||
data.resize(size);
|
// data.resize(size);
|
||||||
pack_two_integers(sz.width(), sz.height(), (quint8 *)data.data(), true);
|
// pack_two_integers(sz.width(), sz.height(), (quint8 *)data.data(), true);
|
||||||
}
|
// }
|
||||||
return size;
|
// return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MsgPackPrivate::unpack_qsize(const QByteArray &data)
|
QVariant MsgPackPrivate::unpack_qsize(const QByteArray &data)
|
||||||
{
|
{
|
||||||
quint8 *p = (quint8 *)data.data();
|
// quint8 *p = (quint8 *)data.data();
|
||||||
qint32 x;
|
// qint32 x;
|
||||||
bool ok;
|
// bool ok;
|
||||||
p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
QSize sz;
|
// QSize sz;
|
||||||
sz.setWidth(x);
|
// sz.setWidth(x);
|
||||||
MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
sz.setHeight(x);
|
// sz.setHeight(x);
|
||||||
return sz;
|
// return sz;
|
||||||
}
|
}
|
||||||
|
|
||||||
quint32 MsgPackPrivate::pack_qrect(const QVariant &variant, QByteArray &data, bool write)
|
quint32 MsgPackPrivate::pack_qrect(const QVariant &variant, QByteArray &data, bool write)
|
||||||
{
|
{
|
||||||
QRect rect = variant.toRect();
|
// QRect rect = variant.toRect();
|
||||||
QPoint pt1 = rect.topLeft();
|
// QPoint pt1 = rect.topLeft();
|
||||||
QPoint pt2 = rect.bottomRight();
|
// QPoint pt2 = rect.bottomRight();
|
||||||
quint8 size = pack_two_integers(pt1.x(), pt1.y(), 0, false);
|
// quint8 size = pack_two_integers(pt1.x(), pt1.y(), 0, false);
|
||||||
size += pack_two_integers(pt2.x(), pt2.y(), 0, false);
|
// size += pack_two_integers(pt2.x(), pt2.y(), 0, false);
|
||||||
if (write) {
|
// if (write) {
|
||||||
data.resize(size);
|
// data.resize(size);
|
||||||
quint8 *p = (quint8 *)data.data();
|
// quint8 *p = (quint8 *)data.data();
|
||||||
p += pack_two_integers(pt1.x(), pt1.y(), p, true);
|
// p += pack_two_integers(pt1.x(), pt1.y(), p, true);
|
||||||
pack_two_integers(pt2.x(), pt2.y(), p, true);
|
// pack_two_integers(pt2.x(), pt2.y(), p, true);
|
||||||
}
|
// }
|
||||||
return size;
|
// return size;
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant MsgPackPrivate::unpack_qrect(const QByteArray &data)
|
QVariant MsgPackPrivate::unpack_qrect(const QByteArray &data)
|
||||||
{
|
{
|
||||||
quint8 *p = (quint8 *)data.data();
|
// quint8 *p = (quint8 *)data.data();
|
||||||
qint32 x;
|
// qint32 x;
|
||||||
bool ok;
|
// bool ok;
|
||||||
|
|
||||||
p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
QPoint pt;
|
// QPoint pt;
|
||||||
pt.setX(x);
|
// pt.setX(x);
|
||||||
p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
pt.setY(x);
|
// pt.setY(x);
|
||||||
|
|
||||||
QRect rect;
|
// QRect rect;
|
||||||
rect.setTopLeft(pt);
|
// rect.setTopLeft(pt);
|
||||||
|
|
||||||
p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
pt.setX(x);
|
// pt.setX(x);
|
||||||
p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
// p = MsgPack::Ext::unpack_upto_qint32(&x, p, &ok);
|
||||||
pt.setY(x);
|
// pt.setY(x);
|
||||||
|
|
||||||
rect.setBottomRight(pt);
|
// rect.setBottomRight(pt);
|
||||||
|
|
||||||
return rect;
|
// return rect;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -1,5 +1,8 @@
|
|||||||
#include "stream.h"
|
#include "stream.h"
|
||||||
#include <QBuffer>
|
#include <QBuffer>
|
||||||
|
#include "private/sysdep.h"
|
||||||
|
#include "msgpack_common.h"
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#undef CHECK_STREAM_PRECOND
|
#undef CHECK_STREAM_PRECOND
|
||||||
#ifndef QT_NO_DEBUG
|
#ifndef QT_NO_DEBUG
|
||||||
@@ -84,15 +87,52 @@ void MsgPackStream::setStatus(Status status)
|
|||||||
q_status = status;
|
q_status = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
MsgPackStream &MsgPackStream::operator >>(quint8 &u8)
|
MsgPackStream &MsgPackStream::operator>>(bool &b)
|
||||||
{
|
{
|
||||||
u8 = 0;
|
|
||||||
CHECK_STREAM_PRECOND(*this)
|
CHECK_STREAM_PRECOND(*this)
|
||||||
char c;
|
quint8 p[1];
|
||||||
if (!dev->getChar(&c))
|
if (!dev->getChar((char *)p)) {
|
||||||
|
b = false;
|
||||||
setStatus(ReadPastEnd);
|
setStatus(ReadPastEnd);
|
||||||
else
|
} else {
|
||||||
u8 = quint8(c);
|
if (p[0] != MsgPack::FirstByte::TRUE ||
|
||||||
|
p[0] != MsgPack::FirstByte::FALSE)
|
||||||
|
setStatus(ReadCorruptData);
|
||||||
|
b = (p[0] == MsgPack::FirstByte::TRUE);
|
||||||
|
}
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MsgPackStream &MsgPackStream::operator >>(quint8 &u8)
|
||||||
|
{
|
||||||
|
CHECK_STREAM_PRECOND(*this)
|
||||||
|
char c;
|
||||||
|
if (!dev->getChar(&c)) {
|
||||||
|
u8 = 0;
|
||||||
|
setStatus(ReadPastEnd);
|
||||||
|
} else {
|
||||||
|
u8 = quint8(c);
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
MsgPackStream &MsgPackStream::operator>>(quint16 &u16)
|
||||||
|
{
|
||||||
|
CHECK_STREAM_PRECOND(*this);
|
||||||
|
quint8 p[3];
|
||||||
|
if (dev->read((char *)p, 3) != 3) {
|
||||||
|
u16 = 0;
|
||||||
|
setStatus(ReadPastEnd);
|
||||||
|
} else {
|
||||||
|
if (p[0] != MsgPack::FirstByte::UINT16)
|
||||||
|
setStatus(ReadCorruptData);
|
||||||
|
u16 = _msgpack_load16(quint16, (p + 1));
|
||||||
|
}
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
MsgPackStream &MsgPackStream::operator>>(quint32 &u32)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user