mirror of
https://github.com/romixlab/qmsgpack.git
synced 2025-08-13 17:14:26 +02:00
Merge pull request #36 from KonstantinRitt/mr/let_me_see_you_stripped
Make it possible to disable Qt type pack/unpack handlers at build time
This commit is contained in:
22
qmsgpack.pri
22
qmsgpack.pri
@@ -7,10 +7,7 @@ SOURCES += \
|
|||||||
$$PWD/src/msgpackcommon.cpp \
|
$$PWD/src/msgpackcommon.cpp \
|
||||||
$$PWD/src/private/pack_p.cpp \
|
$$PWD/src/private/pack_p.cpp \
|
||||||
$$PWD/src/private/unpack_p.cpp \
|
$$PWD/src/private/unpack_p.cpp \
|
||||||
$$PWD/src/private/qt_types_p.cpp \
|
$$PWD/src/msgpackstream.cpp
|
||||||
$$PWD/src/msgpackstream.cpp \
|
|
||||||
$$PWD/src/stream/time.cpp \
|
|
||||||
$$PWD/src/stream/geometry.cpp
|
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
$$PWD/src/msgpack.h \
|
$$PWD/src/msgpack.h \
|
||||||
@@ -19,18 +16,27 @@ HEADERS += \
|
|||||||
$$PWD/src/endianhelper.h \
|
$$PWD/src/endianhelper.h \
|
||||||
$$PWD/src/msgpackcommon.h \
|
$$PWD/src/msgpackcommon.h \
|
||||||
$$PWD/src/msgpack_export.h \
|
$$PWD/src/msgpack_export.h \
|
||||||
|
$$PWD/src/msgpackstream.h
|
||||||
|
|
||||||
|
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
|
||||||
|
SOURCES += \
|
||||||
|
$$PWD/src/private/qt_types_p.cpp \
|
||||||
|
$$PWD/src/stream/time.cpp \
|
||||||
|
$$PWD/src/stream/geometry.cpp
|
||||||
|
|
||||||
|
HEADERS += \
|
||||||
$$PWD/src/private/qt_types_p.h \
|
$$PWD/src/private/qt_types_p.h \
|
||||||
$$PWD/src/msgpackstream.h \
|
|
||||||
$$PWD/src/stream/time.h \
|
$$PWD/src/stream/time.h \
|
||||||
$$PWD/src/stream/geometry.h
|
$$PWD/src/stream/geometry.h
|
||||||
|
|
||||||
qtHaveModule(gui) {
|
qtHaveModule(gui) {
|
||||||
QT += gui
|
QT += gui
|
||||||
}
|
}
|
||||||
|
|
||||||
qtHaveModule(location) {
|
qtHaveModule(location) {
|
||||||
QT += location
|
QT += location
|
||||||
|
|
||||||
SOURCES += $$PWD/src/stream/location.cpp
|
SOURCES += $$PWD/src/stream/location.cpp
|
||||||
HEADERS += $$PWD/src/stream/location.h
|
HEADERS += $$PWD/src/stream/location.h
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@@ -3,10 +3,17 @@
|
|||||||
#include "msgpack.h"
|
#include "msgpack.h"
|
||||||
#include "private/unpack_p.h"
|
#include "private/unpack_p.h"
|
||||||
#include "private/pack_p.h"
|
#include "private/pack_p.h"
|
||||||
#include "private/qt_types_p.h"
|
|
||||||
|
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
||||||
|
#ifndef MSGPACK_NO_PACKTYPES
|
||||||
|
#include "private/qt_types_p.h"
|
||||||
|
|
||||||
|
#ifdef QT_LOCATION_LIB
|
||||||
|
#include <QGeoCoordinate>
|
||||||
|
#endif
|
||||||
|
#endif // MSGPACK_NO_PACKTYPES
|
||||||
|
|
||||||
QVariant MsgPack::unpack(const QByteArray &data)
|
QVariant MsgPack::unpack(const QByteArray &data)
|
||||||
{
|
{
|
||||||
const quint8 *p = reinterpret_cast<const quint8*>(data.data());
|
const quint8 *p = reinterpret_cast<const quint8*>(data.data());
|
||||||
@@ -48,7 +55,55 @@ qint8 MsgPack::msgpackType(int qType)
|
|||||||
|
|
||||||
bool MsgPack::registerType(QMetaType::Type qType, quint8 msgpackType)
|
bool MsgPack::registerType(QMetaType::Type qType, quint8 msgpackType)
|
||||||
{
|
{
|
||||||
return MsgPackPrivate::register_qtype(qType, msgpackType);
|
#ifndef MSGPACK_NO_PACKTYPES
|
||||||
|
switch (qType) {
|
||||||
|
#ifdef QT_GUI_LIB
|
||||||
|
case QMetaType::QColor:
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qcolor);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qcolor);
|
||||||
|
return true;
|
||||||
|
#endif // QT_GUI_LIB
|
||||||
|
case QMetaType::QTime:
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qtime);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qtime);
|
||||||
|
return true;
|
||||||
|
case QMetaType::QDate:
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qdate);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qdate);
|
||||||
|
return true;
|
||||||
|
case QMetaType::QDateTime:
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qdatetime);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qdatetime);
|
||||||
|
return true;
|
||||||
|
case QMetaType::QPoint:
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qpoint);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qpoint);
|
||||||
|
return true;
|
||||||
|
case QMetaType::QSize:
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qsize);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qsize);
|
||||||
|
return true;
|
||||||
|
case QMetaType::QRect:
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qrect);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qrect);
|
||||||
|
return true;
|
||||||
|
default:
|
||||||
|
#ifdef QT_LOCATION_LIB
|
||||||
|
if (int(qType) == qMetaTypeId<QGeoCoordinate>()) {
|
||||||
|
MsgPackPrivate::register_packer(qType, msgpackType, MsgPackPrivate::pack_qgeocoordinate);
|
||||||
|
MsgPackPrivate::register_unpacker(msgpackType, MsgPackPrivate::unpack_qgeocoordinate);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
#endif // QT_LOCATION_LIB
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
Q_UNUSED(msgpackType)
|
||||||
|
#endif // MSGPACK_NO_PACKTYPES
|
||||||
|
|
||||||
|
qWarning("qmsgpack was built without metatype %d support.", int(qType));
|
||||||
|
qWarning("Use MsgPack::registerPacker() and MsgPack::registerUnpacker() to register metatype %d manually.", int(qType));
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void MsgPack::setCompatibilityModeEnabled(bool enabled)
|
void MsgPack::setCompatibilityModeEnabled(bool enabled)
|
||||||
|
@@ -11,8 +11,6 @@
|
|||||||
|
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#else
|
|
||||||
#define NO_QTGUI_WARNING "qmsgpack was built without QtGui, hence some types are not available"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef QT_LOCATION_LIB
|
#ifdef QT_LOCATION_LIB
|
||||||
@@ -22,45 +20,6 @@
|
|||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QRect>
|
#include <QRect>
|
||||||
|
|
||||||
bool MsgPackPrivate::register_qtype(QMetaType::Type q_type, quint8 msgpack_type)
|
|
||||||
{
|
|
||||||
if (q_type == QMetaType::QColor) {
|
|
||||||
#ifdef QT_GUI_LIB
|
|
||||||
MsgPackPrivate::register_packer(q_type, msgpack_type, pack_qcolor);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qcolor);
|
|
||||||
#else
|
|
||||||
qWarning() << NO_QTGUI_WARNING;
|
|
||||||
return false;
|
|
||||||
#endif //QT_GUI_LIB
|
|
||||||
#ifdef QT_LOCATION_LIB
|
|
||||||
} else if ((int)q_type == qMetaTypeId<QGeoCoordinate>()) {
|
|
||||||
MsgPackPrivate::register_packer((QMetaType::Type)qMetaTypeId<QGeoCoordinate>(),
|
|
||||||
msgpack_type,
|
|
||||||
pack_qgeocoordinate);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qgeocoordinate);
|
|
||||||
#endif
|
|
||||||
} else if (q_type == QMetaType::QTime) {
|
|
||||||
MsgPackPrivate::register_packer(q_type, msgpack_type, pack_qtime);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qtime);
|
|
||||||
} else if (q_type == QMetaType::QDate) {
|
|
||||||
MsgPackPrivate::register_packer(q_type, msgpack_type, pack_qdate);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qdate);
|
|
||||||
} else if (q_type == QMetaType::QDateTime) {
|
|
||||||
MsgPackPrivate::register_packer(q_type, msgpack_type, pack_qdatetime);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qdatetime);
|
|
||||||
} else if (q_type == QMetaType::QPoint) {
|
|
||||||
MsgPackPrivate::register_packer(q_type, msgpack_type, pack_qpoint);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qpoint);
|
|
||||||
} else if (q_type == QMetaType::QSize) {
|
|
||||||
MsgPackPrivate::register_packer(q_type, msgpack_type, pack_qsize);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qsize);
|
|
||||||
} else if (q_type == QMetaType::QRect) {
|
|
||||||
MsgPackPrivate::register_packer(q_type, msgpack_type, pack_qrect);
|
|
||||||
MsgPackPrivate::register_unpacker(msgpack_type, unpack_qrect);
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
QByteArray MsgPackPrivate::pack_qcolor(const QVariant &variant)
|
QByteArray MsgPackPrivate::pack_qcolor(const QVariant &variant)
|
||||||
{
|
{
|
||||||
|
@@ -6,8 +6,6 @@
|
|||||||
|
|
||||||
namespace MsgPackPrivate
|
namespace MsgPackPrivate
|
||||||
{
|
{
|
||||||
bool register_qtype(QMetaType::Type q_type, quint8 msgpack_type);
|
|
||||||
|
|
||||||
#ifdef QT_GUI_LIB
|
#ifdef QT_GUI_LIB
|
||||||
QByteArray pack_qcolor(const QVariant &variant);
|
QByteArray pack_qcolor(const QVariant &variant);
|
||||||
QVariant unpack_qcolor(const QByteArray &data);
|
QVariant unpack_qcolor(const QByteArray &data);
|
||||||
|
@@ -18,12 +18,14 @@ HEADERS_INSTALL = \
|
|||||||
msgpack_export.h \
|
msgpack_export.h \
|
||||||
msgpackstream.h \
|
msgpackstream.h \
|
||||||
|
|
||||||
STREAM_HEADERS_INSTALL = \
|
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
|
||||||
|
STREAM_HEADERS_INSTALL = \
|
||||||
stream/geometry.h \
|
stream/geometry.h \
|
||||||
stream/time.h
|
stream/time.h
|
||||||
|
|
||||||
qtHaveModule(location) {
|
qtHaveModule(location) {
|
||||||
STREAM_HEADERS_INSTALL += stream/location.h
|
STREAM_HEADERS_INSTALL += stream/location.h
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unix {
|
unix {
|
||||||
|
@@ -3,6 +3,10 @@ TEMPLATE = subdirs
|
|||||||
SUBDIRS += \
|
SUBDIRS += \
|
||||||
pack \
|
pack \
|
||||||
unpack \
|
unpack \
|
||||||
mixed \
|
mixed
|
||||||
|
|
||||||
|
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
|
||||||
|
SUBDIRS += \
|
||||||
stream \
|
stream \
|
||||||
qttypes
|
qttypes
|
||||||
|
}
|
||||||
|
Reference in New Issue
Block a user