forked from romixlab/qmsgpack
Compare commits
50 Commits
Author | SHA1 | Date | |
---|---|---|---|
a7d9c00b98 | |||
86dd3b1c14 | |||
8cdf333e5b | |||
14847e5a72 | |||
7e1ca5b414 | |||
1733bc7847 | |||
024d901605 | |||
a9e429a30f | |||
efc99ef590 | |||
8a4f180c00 | |||
3cafa3b006 | |||
166fd5acad | |||
538f28dc24 | |||
fc8f9d7c66 | |||
e1d8226780 | |||
1591ebddd4 | |||
0b8282d592 | |||
34afb5aba3 | |||
e3819fc5b3 | |||
639a96428e | |||
f98072b753 | |||
11888b97e7 | |||
4bc12f75e5 | |||
d9f37afe2e | |||
6455058b4f | |||
172c71b027 | |||
b15b5efdb4 | |||
ca968dbb4e | |||
a579f324d7 | |||
2c7a329c48 | |||
0cd5fd2d68 | |||
a672db294a | |||
c91993750d | |||
47128d5771 | |||
4f1c4d3d80 | |||
5ca284052c | |||
a412eedf24 | |||
b7284725e8 | |||
aa613f658f | |||
e64de7eac3 | |||
ca56d9e362 | |||
22750cf88b | |||
067c72767a | |||
bec0d71cc1 | |||
9d017281fe | |||
51932532d2 | |||
bf12914846 | |||
6e753f0669 | |||
2d8af48459 | |||
4ff4ba8448 |
@ -1,3 +0,0 @@
|
||||
TOP_SRCDIR=$$PWD
|
||||
TOP_BUILDDIR=$$shadowed($$PWD)
|
||||
|
13
.travis.yml
13
.travis.yml
@ -1,16 +1,21 @@
|
||||
language: cpp
|
||||
compiler: gcc
|
||||
|
||||
compiler:
|
||||
- gcc
|
||||
dist: trusty
|
||||
sudo: required
|
||||
|
||||
env:
|
||||
- QT4_BUILD=OFF
|
||||
|
||||
before_install:
|
||||
- sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
|
||||
- sudo add-apt-repository --yes ppa:ubuntu-sdk-team/ppa
|
||||
- sudo add-apt-repository --yes ppa:kalakris/cmake
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get install -qq cmake libqtcore4 qt4-qmake libqt5core5 qt5-qmake qt5-default qtchooser libmsgpack-dev
|
||||
|
||||
install:
|
||||
- sudo apt-get install -y --force-yes build-essential g++-4.8 -y
|
||||
- sudo apt-get install -y --force-yes qtbase5-dev qttools5-dev-tools qttools5-dev
|
||||
|
||||
|
||||
script:
|
||||
- mkdir build
|
||||
|
@ -1,11 +1,12 @@
|
||||
set(Qt5Core_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core")
|
||||
set(Qt5Test_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Test")
|
||||
set(Qt5_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core")
|
||||
set(QT_QMAKE_EXECUTABLE "/opt/Qt5.6.0/5.6/gcc_64/bin/qmake")
|
||||
#set(Qt5Core_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core")
|
||||
#set(Qt5Test_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Test")
|
||||
#set(Qt5_DIR "/opt/Qt5.6.0/5.6/gcc_64/lib/cmake/Qt5Core")
|
||||
#set(QT_QMAKE_EXECUTABLE "/opt/Qt5.6.0/5.6/gcc_64/bin/qmake")
|
||||
|
||||
project(qmsgpack)
|
||||
|
||||
cmake_minimum_required(VERSION 2.8.8)
|
||||
cmake_minimum_required(VERSION 3.1.0)
|
||||
set (CMAKE_CXX_STANDARD 11)
|
||||
|
||||
set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
|
||||
|
||||
@ -100,4 +101,4 @@ install(EXPORT qmsgpack-export DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE MsgPa
|
||||
file(RELATIVE_PATH relInstallDir ${CMAKE_INSTALL_PREFIX}/$CMAKECONFIG_INSTALL_DIR} ${CMAKE_INSTALL_PREFIX})
|
||||
|
||||
add_custom_target(uninstall
|
||||
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
|
||||
"${CMAKE_COMMAND}" -P "${CMAKE_CURRENT_BINARY_DIR}/cmake_uninstall.cmake")
|
||||
|
8
PVS_HOWTO
Normal file
8
PVS_HOWTO
Normal file
@ -0,0 +1,8 @@
|
||||
Execute following:
|
||||
cd qmsgpack
|
||||
mkdir build
|
||||
cd build
|
||||
cmake -DCMAKE_EXPORT_COMPILE_COMMANDS=On -DBUILD_TESTS=True ..
|
||||
pvs-studio-analyzer analyze -o ../qmsgpack.log
|
||||
plog-converter -a GA:1,2 -t tasklist -o ../qmsgpack.tasks ../qmsgpack.log
|
||||
See qmsgpack.tasks then
|
39
qmsgpack.pri
39
qmsgpack.pri
@ -1,6 +1,4 @@
|
||||
QT += core location
|
||||
|
||||
DEFINES += MSGPACK_MAKE_LIB
|
||||
QT += core
|
||||
|
||||
INCLUDEPATH += $$PWD/src
|
||||
|
||||
@ -9,11 +7,7 @@ SOURCES += \
|
||||
$$PWD/src/msgpackcommon.cpp \
|
||||
$$PWD/src/private/pack_p.cpp \
|
||||
$$PWD/src/private/unpack_p.cpp \
|
||||
$$PWD/src/private/qt_types_p.cpp \
|
||||
$$PWD/src/msgpackstream.cpp \
|
||||
$$PWD/src/stream/time.cpp \
|
||||
$$PWD/src/stream/geometry.cpp \
|
||||
$$PWD/src/stream/location.cpp
|
||||
$$PWD/src/msgpackstream.cpp
|
||||
|
||||
HEADERS += \
|
||||
$$PWD/src/msgpack.h \
|
||||
@ -22,8 +16,27 @@ HEADERS += \
|
||||
$$PWD/src/endianhelper.h \
|
||||
$$PWD/src/msgpackcommon.h \
|
||||
$$PWD/src/msgpack_export.h \
|
||||
$$PWD/src/private/qt_types_p.h \
|
||||
$$PWD/src/msgpackstream.h \
|
||||
$$PWD/src/stream/location.h \
|
||||
$$PWD/src/stream/time.h \
|
||||
$$PWD/src/stream/geometry.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/stream/time.h \
|
||||
$$PWD/src/stream/geometry.h
|
||||
|
||||
qtHaveModule(gui) {
|
||||
QT += gui
|
||||
}
|
||||
|
||||
qtHaveModule(location) {
|
||||
QT += location
|
||||
|
||||
SOURCES += $$PWD/src/stream/location.cpp
|
||||
HEADERS += $$PWD/src/stream/location.h
|
||||
}
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += \
|
||||
src
|
||||
src \
|
||||
tests
|
||||
|
@ -2,7 +2,11 @@ set(qmsgpack_srcs msgpack.cpp msgpackcommon.cpp msgpackstream.cpp private/pack_p
|
||||
set(qmsgpack_headers msgpack.h msgpackstream.h msgpackcommon.h msgpack_export.h endianhelper.h)
|
||||
set(qmsgpack_stream_headers stream/location.h stream/time.h stream/geometry.h)
|
||||
|
||||
add_library(qmsgpack SHARED ${qmsgpack_srcs} ${qmsgpack_headers})
|
||||
if(NOT DEFINED COMPILE_TYPE)
|
||||
set(COMPILE_TYPE SHARED)
|
||||
endif(NOT DEFINED COMPILE_TYPE)
|
||||
|
||||
add_library(qmsgpack ${COMPILE_TYPE} ${qmsgpack_srcs} ${qmsgpack_headers})
|
||||
|
||||
if (Qt5Core_FOUND)
|
||||
target_link_libraries(qmsgpack Qt5::Core)
|
||||
|
@ -15,8 +15,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MSGPACK_SYSDEP_H__
|
||||
#define MSGPACK_SYSDEP_H__
|
||||
#ifndef MSGPACK_ENDIAN_HELPER_H
|
||||
#define MSGPACK_ENDIAN_HELPER_H
|
||||
#include <qglobal.h>
|
||||
|
||||
#if defined(_WIN32) && defined(_MSC_VER) && _MSC_VER >= 1600
|
||||
@ -44,11 +44,12 @@
|
||||
# if defined(ntohs)
|
||||
# define _msgpack_be16(x) ntohs(x)
|
||||
# elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x))
|
||||
# define _msgpack_be16(x) ( \
|
||||
static_cast<uint16_t>(_byteswap_ushort(static_cast<unsigned short>(x))) )
|
||||
# else
|
||||
# define _msgpack_be16(x) ( \
|
||||
((((quint16)x) << 8) ) | \
|
||||
((((quint16)x) >> 8) ) )
|
||||
(((static_cast<quint16>(x)) << 8) ) | \
|
||||
(((static_cast<quint16>(x)) >> 8) ) )
|
||||
# endif
|
||||
#else
|
||||
# define _msgpack_be16(x) ntohs(x)
|
||||
@ -58,13 +59,14 @@
|
||||
# if defined(ntohl)
|
||||
# define _msgpack_be32(x) ntohl(x)
|
||||
# elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400)
|
||||
# define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x))
|
||||
# define _msgpack_be32(x) ( \
|
||||
static_cast<uint32_t>(_byteswap_ulong(static_cast<unsigned long>(x))) )
|
||||
# else
|
||||
# define _msgpack_be32(x) \
|
||||
( ((((quint32)x) << 24) ) | \
|
||||
((((quint32)x) << 8) & 0x00ff0000U ) | \
|
||||
((((quint32)x) >> 8) & 0x0000ff00U ) | \
|
||||
((((quint32)x) >> 24) ) )
|
||||
( (((static_cast<quint32>(x)) << 24) ) | \
|
||||
(((static_cast<quint32>(x)) << 8) & 0x00ff0000U ) | \
|
||||
(((static_cast<quint32>(x)) >> 8) & 0x0000ff00U ) | \
|
||||
(((static_cast<quint32>(x)) >> 24) ) )
|
||||
# endif
|
||||
#else
|
||||
# define _msgpack_be32(x) ntohl(x)
|
||||
@ -78,35 +80,35 @@
|
||||
# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x)
|
||||
#else
|
||||
#define _msgpack_be64(x) \
|
||||
( ((((quint64)x) << 56) ) | \
|
||||
((((quint64)x) << 40) & 0x00ff000000000000ULL ) | \
|
||||
((((quint64)x) << 24) & 0x0000ff0000000000ULL ) | \
|
||||
((((quint64)x) << 8) & 0x000000ff00000000ULL ) | \
|
||||
((((quint64)x) >> 8) & 0x00000000ff000000ULL ) | \
|
||||
((((quint64)x) >> 24) & 0x0000000000ff0000ULL ) | \
|
||||
((((quint64)x) >> 40) & 0x000000000000ff00ULL ) | \
|
||||
((((quint64)x) >> 56) ) )
|
||||
( (((static_cast<quint64>(x)) << 56) ) | \
|
||||
(((static_cast<quint64>(x)) << 40) & 0x00ff000000000000ULL ) | \
|
||||
(((static_cast<quint64>(x)) << 24) & 0x0000ff0000000000ULL ) | \
|
||||
(((static_cast<quint64>(x)) << 8) & 0x000000ff00000000ULL ) | \
|
||||
(((static_cast<quint64>(x)) >> 8) & 0x00000000ff000000ULL ) | \
|
||||
(((static_cast<quint64>(x)) >> 24) & 0x0000000000ff0000ULL ) | \
|
||||
(((static_cast<quint64>(x)) >> 40) & 0x000000000000ff00ULL ) | \
|
||||
(((static_cast<quint64>(x)) >> 56) ) )
|
||||
#endif
|
||||
|
||||
#define _msgpack_load16(cast, from) ((cast)( \
|
||||
(((quint16)((quint8*)(from))[0]) << 8) | \
|
||||
(((quint16)((quint8*)(from))[1]) ) ))
|
||||
#define _msgpack_load16(type, from) ((static_cast<type>( \
|
||||
((static_cast<quint16>(static_cast<quint8*>(from)[0])) << 8) | \
|
||||
((static_cast<quint16>(static_cast<quint8*>(from)[1])) ) )))
|
||||
|
||||
#define _msgpack_load32(cast, from) ((cast)( \
|
||||
(((quint32)((quint8*)(from))[0]) << 24) | \
|
||||
(((quint32)((quint8*)(from))[1]) << 16) | \
|
||||
(((quint32)((quint8*)(from))[2]) << 8) | \
|
||||
(((quint32)((quint8*)(from))[3]) ) ))
|
||||
#define _msgpack_load32(type, from) ((static_cast<type>( \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from)[0])) << 24) | \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from)[1])) << 16) | \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from)[2])) << 8) | \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from)[3])) ) )))
|
||||
|
||||
#define _msgpack_load64(cast, from) ((cast)( \
|
||||
(((quint64)((quint8*)(from))[0]) << 56) | \
|
||||
(((quint64)((quint8*)(from))[1]) << 48) | \
|
||||
(((quint64)((quint8*)(from))[2]) << 40) | \
|
||||
(((quint64)((quint8*)(from))[3]) << 32) | \
|
||||
(((quint64)((quint8*)(from))[4]) << 24) | \
|
||||
(((quint64)((quint8*)(from))[5]) << 16) | \
|
||||
(((quint64)((quint8*)(from))[6]) << 8) | \
|
||||
(((quint64)((quint8*)(from))[7]) ) ))
|
||||
#define _msgpack_load64(type, from) ((static_cast<type>( \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[0])) << 56) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[1])) << 48) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[2])) << 40) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[3])) << 32) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[4])) << 24) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[5])) << 16) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[6])) << 8) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from)[7])) ) )))
|
||||
|
||||
#else
|
||||
|
||||
@ -114,25 +116,25 @@
|
||||
#define _msgpack_be32(x) (x)
|
||||
#define _msgpack_be64(x) (x)
|
||||
|
||||
#define _msgpack_load16(cast, from) ((cast)( \
|
||||
(((quint16)((quint8*)from)[0]) << 8) | \
|
||||
(((quint16)((quint8*)from)[1]) ) ))
|
||||
#define _msgpack_load16(type, from) (static_cast<type>( \
|
||||
((static_cast<quint16>(static_cast<quint8*>(from))[0]) << 8) | \
|
||||
((static_cast<quint16>(static_cast<quint8*>(from))[1]) ) ))
|
||||
|
||||
#define _msgpack_load32(cast, from) ((cast)( \
|
||||
(((quint32)((quint8*)from)[0]) << 24) | \
|
||||
(((quint32)((quint8*)from)[1]) << 16) | \
|
||||
(((quint32)((quint8*)from)[2]) << 8) | \
|
||||
(((quint32)((quint8*)from)[3]) ) ))
|
||||
#define _msgpack_load32(type, from) (static_cast<type>( \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from))[0]) << 24) | \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from))[1]) << 16) | \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from))[2]) << 8) | \
|
||||
((static_cast<quint32>(static_cast<quint8*>(from))[3]) ) ))
|
||||
|
||||
#define _msgpack_load64(cast, from) ((cast)( \
|
||||
(((quint64)((quint8*)from)[0]) << 56) | \
|
||||
(((quint64)((quint8*)from)[1]) << 48) | \
|
||||
(((quint64)((quint8*)from)[2]) << 40) | \
|
||||
(((quint64)((quint8*)from)[3]) << 32) | \
|
||||
(((quint64)((quint8*)from)[4]) << 24) | \
|
||||
(((quint64)((quint8*)from)[5]) << 16) | \
|
||||
(((quint64)((quint8*)from)[6]) << 8) | \
|
||||
(((quint64)((quint8*)from)[7]) ) ))
|
||||
#define _msgpack_load64(type, from) ((static_cast<type>( \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[0]) << 56) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[1]) << 48) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[2]) << 40) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[3]) << 32) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[4]) << 24) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[5]) << 16) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[6]) << 8) | \
|
||||
((static_cast<quint64>(static_cast<quint8*>(from))[7]) ) )))
|
||||
#endif
|
||||
|
||||
|
||||
@ -144,13 +146,13 @@
|
||||
do { quint64 val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0)
|
||||
|
||||
/*
|
||||
#define _msgpack_load16(cast, from) \
|
||||
({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); })
|
||||
#define _msgpack_load32(cast, from) \
|
||||
({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); })
|
||||
#define _msgpack_load64(cast, from) \
|
||||
({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); })
|
||||
#define _msgpack_load16(type, from) \
|
||||
({ type val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); })
|
||||
#define _msgpack_load32(type, from) \
|
||||
({ type val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); })
|
||||
#define _msgpack_load64(type, from) \
|
||||
({ type val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); })
|
||||
*/
|
||||
|
||||
#endif /* msgpack/sysdep.h */
|
||||
#endif /* msgpack/endianhelper.h */
|
||||
|
||||
|
@ -1,29 +1,39 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "msgpack.h"
|
||||
#include "private/unpack_p.h"
|
||||
#include "private/pack_p.h"
|
||||
#include "private/qt_types_p.h"
|
||||
|
||||
#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)
|
||||
{
|
||||
quint8 *p = (quint8 *)data.data();
|
||||
quint8 *end = p + data.size() - 1;
|
||||
const quint8 *p = reinterpret_cast<const quint8*>(data.data());
|
||||
const quint8 *end = p + data.size() - 1;
|
||||
|
||||
return MsgPackPrivate::unpack(p, end);
|
||||
}
|
||||
|
||||
QByteArray MsgPack::pack(const QVariant &variant)
|
||||
{
|
||||
quint8 *p = 0;
|
||||
QVector<QByteArray> user_data;
|
||||
quint8 *end = MsgPackPrivate::pack(variant, p, false, user_data);
|
||||
quint32 size = end - p;
|
||||
//qDebug() << "size probe:" << size;
|
||||
|
||||
// first run, calculate size
|
||||
ptrdiff_t size = MsgPackPrivate::pack(variant, nullptr, false, user_data) -
|
||||
static_cast<quint8 *>(nullptr);
|
||||
QByteArray arr;
|
||||
arr.resize(size);
|
||||
end = MsgPackPrivate::pack(variant, (quint8 *)arr.data(), true, user_data);
|
||||
arr.resize(static_cast<int>(size));
|
||||
|
||||
// second run, pack it
|
||||
MsgPackPrivate::pack(variant, reinterpret_cast<quint8*>(arr.data()), true,
|
||||
user_data);
|
||||
|
||||
return arr;
|
||||
}
|
||||
@ -40,12 +50,60 @@ bool MsgPack::registerUnpacker(qint8 msgpackType, MsgPack::unpack_user_f unpacke
|
||||
|
||||
qint8 MsgPack::msgpackType(int qType)
|
||||
{
|
||||
return MsgPackPrivate::msgpack_type((QMetaType::Type)qType);
|
||||
return MsgPackPrivate::msgpack_type(static_cast<QMetaType::Type>(qType));
|
||||
}
|
||||
|
||||
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)
|
||||
|
@ -3,10 +3,14 @@
|
||||
|
||||
#include <QtCore/qglobal.h>
|
||||
|
||||
#if defined(MSGPACK_MAKE_LIB) // building lib
|
||||
#define MSGPACK_EXPORT Q_DECL_EXPORT
|
||||
#else // using lib
|
||||
#define MSGPACK_EXPORT Q_DECL_IMPORT
|
||||
#ifndef MSGPACK_STATIC
|
||||
# if defined(MSGPACK_MAKE_LIB)
|
||||
# define MSGPACK_EXPORT Q_DECL_EXPORT
|
||||
# else
|
||||
# define MSGPACK_EXPORT Q_DECL_IMPORT
|
||||
# endif
|
||||
#else
|
||||
# define MSGPACK_EXPORT
|
||||
#endif
|
||||
|
||||
#endif // MSGPACK_EXPORT_H
|
||||
|
@ -1,8 +1,10 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "msgpackcommon.h"
|
||||
|
||||
QString MsgPack::version()
|
||||
{
|
||||
return QString("%1.%2.%3")
|
||||
return QString::fromLatin1("%1.%2.%3")
|
||||
.arg(MSGPACK_MAJOR)
|
||||
.arg(MSGPACK_MINOR)
|
||||
.arg(MSGPACK_VERSION);
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "msgpackstream.h"
|
||||
#include "private/pack_p.h"
|
||||
|
||||
@ -24,15 +26,15 @@
|
||||
return retVal;
|
||||
|
||||
MsgPackStream::MsgPackStream() :
|
||||
dev(0), owndev(false), q_status(Ok)
|
||||
dev(0), owndev(false), q_status(Ok), flushWrites(false)
|
||||
{ }
|
||||
|
||||
MsgPackStream::MsgPackStream(QIODevice *d) :
|
||||
dev(d), owndev(false)
|
||||
dev(d), owndev(false), q_status(Ok), flushWrites(false)
|
||||
{ }
|
||||
|
||||
MsgPackStream::MsgPackStream(QByteArray *a, QIODevice::OpenMode mode) :
|
||||
owndev(true), q_status(Ok)
|
||||
owndev(true), q_status(Ok), flushWrites(false)
|
||||
{
|
||||
QBuffer *buf = new QBuffer(a);
|
||||
buf->open(mode);
|
||||
@ -40,7 +42,7 @@ MsgPackStream::MsgPackStream(QByteArray *a, QIODevice::OpenMode mode) :
|
||||
}
|
||||
|
||||
MsgPackStream::MsgPackStream(const QByteArray &a) :
|
||||
owndev(true), q_status(Ok)
|
||||
owndev(true), q_status(Ok), flushWrites(false)
|
||||
{
|
||||
QBuffer *buf = new QBuffer();
|
||||
buf->setData(a);
|
||||
@ -87,15 +89,25 @@ void MsgPackStream::setStatus(Status status)
|
||||
q_status = status;
|
||||
}
|
||||
|
||||
void MsgPackStream::setFlushWrites(bool flush)
|
||||
{
|
||||
flushWrites = flush;
|
||||
}
|
||||
|
||||
bool MsgPackStream::willFlushWrites()
|
||||
{
|
||||
return flushWrites;
|
||||
}
|
||||
|
||||
MsgPackStream &MsgPackStream::operator>>(bool &b)
|
||||
{
|
||||
CHECK_STREAM_PRECOND(*this)
|
||||
quint8 p[1];
|
||||
if (!dev->getChar((char *)p)) {
|
||||
if (!readBytes((char *)p, 1)) {
|
||||
b = false;
|
||||
setStatus(ReadPastEnd);
|
||||
} else {
|
||||
if (p[0] != MsgPack::FirstByte::MTRUE ||
|
||||
if (p[0] != MsgPack::FirstByte::MTRUE &&
|
||||
p[0] != MsgPack::FirstByte::MFALSE)
|
||||
setStatus(ReadCorruptData);
|
||||
b = (p[0] == MsgPack::FirstByte::MTRUE);
|
||||
@ -197,7 +209,7 @@ MsgPackStream &MsgPackStream::operator>>(float &f)
|
||||
CHECK_STREAM_PRECOND(*this);
|
||||
quint8 *fp = (quint8 *)&f;
|
||||
quint8 p[5];
|
||||
if (dev->read((char *)p, 1) != 1) {
|
||||
if (!readBytes((char *)p, 1)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
@ -205,7 +217,7 @@ MsgPackStream &MsgPackStream::operator>>(float &f)
|
||||
setStatus(ReadCorruptData);
|
||||
return *this;
|
||||
}
|
||||
if (dev->read((char *)p + 1, 4) != 4) {
|
||||
if (!readBytes((char *)p + 1, 4)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
@ -224,7 +236,7 @@ MsgPackStream &MsgPackStream::operator>>(double &d)
|
||||
CHECK_STREAM_PRECOND(*this);
|
||||
quint8 *fp = (quint8 *)&d;
|
||||
quint8 p[9];
|
||||
if (dev->read((char *)p, 1) != 1) {
|
||||
if (!readBytes((char *)p, 1)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
@ -232,7 +244,7 @@ MsgPackStream &MsgPackStream::operator>>(double &d)
|
||||
setStatus(ReadCorruptData);
|
||||
return *this;
|
||||
}
|
||||
if (dev->read((char *)p + 1, 8) != 8) {
|
||||
if (!readBytes((char *)p + 1, 8)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
@ -250,7 +262,7 @@ MsgPackStream &MsgPackStream::operator>>(QString &str)
|
||||
{
|
||||
CHECK_STREAM_PRECOND(*this);
|
||||
quint8 p[5];
|
||||
if (dev->read((char *)p, 1) != 1) {
|
||||
if (!readBytes((char *)p, 1)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
@ -259,20 +271,20 @@ MsgPackStream &MsgPackStream::operator>>(QString &str)
|
||||
if (*p >= 0xa0 && *p <= 0xbf) { // fixstr
|
||||
len = (*p) & 0x1f; // 0b00011111
|
||||
} else if (*p == MsgPack::FirstByte::STR8) {
|
||||
if (dev->read((char *)p + 1, 1) == 1)
|
||||
if (readBytes((char *)p + 1, 1))
|
||||
len = p[1];
|
||||
} else if (*p == MsgPack::FirstByte::STR16) {
|
||||
if (dev->read((char *)p + 1, 2) == 2)
|
||||
if (readBytes((char *)p + 1, 2))
|
||||
len = _msgpack_load16(int, &p[1]);
|
||||
} else if (*p == MsgPack::FirstByte::STR32) {
|
||||
if (dev->read((char *)p + 1, 4) == 4)
|
||||
if (readBytes((char *)p + 1, 4))
|
||||
len = _msgpack_load32(int, &p[1]);
|
||||
} else {
|
||||
setStatus(ReadCorruptData);
|
||||
return *this;
|
||||
}
|
||||
quint8 *data = new quint8[len];
|
||||
if (dev->read((char *)data, len) != len) {
|
||||
if (!readBytes((char *)data, len)) {
|
||||
setStatus(ReadPastEnd);
|
||||
delete[] data;
|
||||
return *this;
|
||||
@ -286,25 +298,25 @@ MsgPackStream &MsgPackStream::operator>>(QByteArray &array)
|
||||
{
|
||||
CHECK_STREAM_PRECOND(*this);
|
||||
quint8 p[5];
|
||||
if (dev->read((char *)p, 1) != 1) {
|
||||
if (!readBytes((char *)p, 1)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
quint32 len;
|
||||
if (p[0] == MsgPack::FirstByte::BIN8) {
|
||||
if (dev->read((char *)p + 1, 1) != 1) {
|
||||
if (!readBytes((char *)p + 1, 1)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
len = p[1];
|
||||
} else if (p[0] == MsgPack::FirstByte::BIN16) {
|
||||
if (dev->read((char *)p + 1, 2) != 2) {
|
||||
if (!readBytes((char *)p + 1, 2)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
len = _msgpack_load16(quint16, &p[1]);
|
||||
} else if (p[0] == MsgPack::FirstByte::BIN32) {
|
||||
if (dev->read((char *)p + 1, 4) != 4) {
|
||||
if (!readBytes((char *)p + 1, 4)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
@ -314,16 +326,31 @@ MsgPackStream &MsgPackStream::operator>>(QByteArray &array)
|
||||
return *this;
|
||||
}
|
||||
array.resize(len);
|
||||
if (dev->read(array.data(), len) != len)
|
||||
if (!readBytes(array.data(), len))
|
||||
setStatus(ReadPastEnd);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool MsgPackStream::readBytes(char *data, uint len)
|
||||
bool MsgPackStream::readBytes(char *data, qint64 len)
|
||||
{
|
||||
CHECK_STREAM_PRECOND(false);
|
||||
uint readed = dev->read(data, len);
|
||||
if (readed != len) {
|
||||
qint64 readed = 0;
|
||||
qint64 thisRead = 0;
|
||||
while (readed < len)
|
||||
{
|
||||
thisRead = dev->read(data, (len - readed));
|
||||
if (thisRead < 0)
|
||||
break;
|
||||
/* Advance the read pointer */
|
||||
data += thisRead;
|
||||
readed += thisRead;
|
||||
/* Data might not be available for a bit, so wait before reading again. */
|
||||
if (readed < len) {
|
||||
dev->waitForReadyRead(-1);
|
||||
}
|
||||
}
|
||||
if (thisRead < 0) {
|
||||
/* FIXME: There are actual errors that can happen here. */
|
||||
setStatus(ReadPastEnd);
|
||||
return false;
|
||||
}
|
||||
@ -334,7 +361,7 @@ bool MsgPackStream::readExtHeader(quint32 &len)
|
||||
{
|
||||
CHECK_STREAM_PRECOND(false);
|
||||
quint8 d[6];
|
||||
if (dev->read((char*)d, 2) != 2) {
|
||||
if (!readBytes((char*)d, 2)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return false;
|
||||
}
|
||||
@ -347,7 +374,7 @@ bool MsgPackStream::readExtHeader(quint32 &len)
|
||||
|
||||
quint8 toRead = 1;
|
||||
toRead <<= d[0] - MsgPack::FirstByte::EXT8;
|
||||
if (dev->read((char*)&d[2], toRead) != toRead) {
|
||||
if (!readBytes((char*)&d[2], toRead)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return false;
|
||||
}
|
||||
@ -370,7 +397,7 @@ MsgPackStream &MsgPackStream::operator<<(bool b)
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 m = b == true ?
|
||||
MsgPack::FirstByte::MTRUE : MsgPack::FirstByte::MFALSE;
|
||||
if (dev->write((char *)&m, 1) != 1)
|
||||
if (!writeBytes((char *)&m, 1))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
@ -380,7 +407,7 @@ MsgPackStream &MsgPackStream::operator<<(quint32 u32)
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 p[5];
|
||||
quint8 sz = MsgPackPrivate::pack_uint(u32, p, true) - p;
|
||||
if (dev->write((char *)p, sz) != sz)
|
||||
if (!writeBytes((char *)p, sz))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
@ -390,7 +417,7 @@ MsgPackStream &MsgPackStream::operator<<(quint64 u64)
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 p[9];
|
||||
quint8 sz = MsgPackPrivate::pack_ulonglong(u64, p, true) - p;
|
||||
if (dev->write((char *)p, sz) != sz)
|
||||
if (!writeBytes((char *)p, sz))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
@ -400,7 +427,7 @@ MsgPackStream &MsgPackStream::operator<<(qint32 i32)
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 p[5];
|
||||
quint8 sz = MsgPackPrivate::pack_int(i32, p, true) - p;
|
||||
if (dev->write((char *)p, sz) != sz)
|
||||
if (!writeBytes((char *)p, sz))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
@ -410,7 +437,7 @@ MsgPackStream &MsgPackStream::operator<<(qint64 i64)
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 p[9];
|
||||
quint8 sz = MsgPackPrivate::pack_longlong(i64, p, true) - p;
|
||||
if (dev->write((char *)p, sz) != sz)
|
||||
if (!writeBytes((char *)p, sz))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
@ -420,7 +447,7 @@ MsgPackStream &MsgPackStream::operator<<(float f)
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 p[5];
|
||||
quint8 sz = MsgPackPrivate::pack_float(f, p, true) - p;
|
||||
if (dev->write((char *)p, sz) != sz)
|
||||
if (!writeBytes((char *)p, sz))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
@ -430,7 +457,7 @@ MsgPackStream &MsgPackStream::operator<<(double d)
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 p[9];
|
||||
quint8 sz = MsgPackPrivate::pack_double(d, p, true) - p;
|
||||
if (dev->write((char *)p, sz) != sz)
|
||||
if (!writeBytes((char *)p, sz))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
@ -438,11 +465,11 @@ MsgPackStream &MsgPackStream::operator<<(double d)
|
||||
MsgPackStream &MsgPackStream::operator<<(QString str)
|
||||
{
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 *p = (quint8 *)0;
|
||||
quint32 sz = MsgPackPrivate::pack_string(str, p, false) - p;
|
||||
ptrdiff_t sz = MsgPackPrivate::pack_string(str, nullptr, false) -
|
||||
static_cast<quint8 *>(nullptr);
|
||||
quint8 *data = new quint8[sz];
|
||||
MsgPackPrivate::pack_string(str, data, true);
|
||||
if (dev->write((char *)data, sz) != sz)
|
||||
if (!writeBytes((char *)data, sz))
|
||||
setStatus(WriteFailed);
|
||||
delete[] data;
|
||||
return *this;
|
||||
@ -451,12 +478,12 @@ MsgPackStream &MsgPackStream::operator<<(QString str)
|
||||
MsgPackStream &MsgPackStream::operator<<(const char *str)
|
||||
{
|
||||
CHECK_STREAM_WRITE_PRECOND(*this);
|
||||
quint8 *p = (quint8 *)0;
|
||||
quint32 str_len = strlen(str);
|
||||
quint32 sz = MsgPackPrivate::pack_string_raw(str, str_len, p, false) - p;
|
||||
ptrdiff_t sz = MsgPackPrivate::pack_string_raw(str, str_len, nullptr, false) -
|
||||
static_cast<quint8 *>(nullptr);
|
||||
quint8 *data = new quint8[sz];
|
||||
MsgPackPrivate::pack_string_raw(str, str_len, data, true);
|
||||
if (dev->write((char *)data, sz) != sz)
|
||||
if (!writeBytes((char *)data, sz))
|
||||
setStatus(WriteFailed);
|
||||
delete[] data;
|
||||
return *this;
|
||||
@ -468,21 +495,40 @@ MsgPackStream &MsgPackStream::operator<<(QByteArray array)
|
||||
quint8 p[5];
|
||||
quint32 len = array.length();
|
||||
quint8 header_len = MsgPackPrivate::pack_bin_header(len, p, true) - p;
|
||||
if (dev->write((char *)p, header_len) != header_len) {
|
||||
if (!writeBytes((char *)p, header_len)) {
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
if (dev->write(array.data(), len) != len)
|
||||
if (!writeBytes(array.data(), len))
|
||||
setStatus(WriteFailed);
|
||||
return *this;
|
||||
}
|
||||
|
||||
bool MsgPackStream::writeBytes(const char *data, uint len)
|
||||
bool MsgPackStream::writeBytes(const char *data, qint64 len)
|
||||
{
|
||||
CHECK_STREAM_WRITE_PRECOND(false);
|
||||
if (dev->write(data, len) != len) {
|
||||
setStatus(WriteFailed);
|
||||
return false;
|
||||
qint64 written = 0;
|
||||
qint64 thisWrite;
|
||||
while (written < len) {
|
||||
thisWrite = dev->write(data, len - written);
|
||||
if (thisWrite < 0) {
|
||||
setStatus(WriteFailed);
|
||||
return false;
|
||||
}
|
||||
/* Apparently on Windows, the buffer size for named pipes is 0, and
|
||||
* any data that is written before the remote end reads it is
|
||||
* dropped (!!) without error (see https://bugreports.qt.io/browse/QTBUG-18385).
|
||||
* We must be very sure that the data has been written before we try
|
||||
* another write. This degrades performance in other cases, so callers
|
||||
* must enable this behavior explicitly.
|
||||
*/
|
||||
if (this->flushWrites) {
|
||||
dev->waitForBytesWritten(-1);
|
||||
}
|
||||
|
||||
/* Increment the write pointer and the total byte count. */
|
||||
data += thisWrite;
|
||||
written += thisWrite;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -519,7 +565,7 @@ bool MsgPackStream::writeExtHeader(quint32 len, qint8 msgpackType)
|
||||
d[5] = msgpackType;
|
||||
sz = 6;
|
||||
}
|
||||
if (dev->write((const char *)d, sz) != sz) {
|
||||
if (!writeBytes((const char *)d, sz)) {
|
||||
setStatus(WriteFailed);
|
||||
return false;
|
||||
}
|
||||
@ -529,7 +575,7 @@ bool MsgPackStream::writeExtHeader(quint32 len, qint8 msgpackType)
|
||||
bool MsgPackStream::unpack_longlong(qint64 &i64)
|
||||
{
|
||||
quint8 p[9];
|
||||
if (dev->read((char *)p, 1) != 1) {
|
||||
if (!readBytes((char *)p, 1)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return false;
|
||||
}
|
||||
@ -544,7 +590,7 @@ bool MsgPackStream::unpack_longlong(qint64 &i64)
|
||||
|
||||
static int typeLengths[] = {1, 2, 4, 8, 1, 2, 4, 8};
|
||||
int typeLength = typeLengths[p[0] - MsgPack::FirstByte::UINT8];
|
||||
if (dev->read((char *)p + 1, typeLength) != typeLength) {
|
||||
if (!readBytes((char *)p + 1, typeLength)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return false;
|
||||
}
|
||||
@ -577,7 +623,7 @@ bool MsgPackStream::unpack_longlong(qint64 &i64)
|
||||
bool MsgPackStream::unpack_ulonglong(quint64 &u64)
|
||||
{
|
||||
quint8 p[9];
|
||||
if (dev->read((char *)p, 1) != 1) {
|
||||
if (!readBytes((char *)p, 1)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return false;
|
||||
}
|
||||
@ -591,7 +637,7 @@ bool MsgPackStream::unpack_ulonglong(quint64 &u64)
|
||||
|
||||
static int typeLengths[] = {1, 2, 4, 8, 1, 2, 4, 8};
|
||||
int typeLength = typeLengths[p[0] - MsgPack::FirstByte::UINT8];
|
||||
if (dev->read((char *)p + 1, typeLength) != typeLength) {
|
||||
if (!readBytes((char *)p + 1, typeLength)) {
|
||||
setStatus(ReadPastEnd);
|
||||
return false;
|
||||
}
|
||||
@ -602,8 +648,8 @@ bool MsgPackStream::unpack_ulonglong(quint64 &u64)
|
||||
u64 = _msgpack_load16(quint64, p + 1);
|
||||
return true;
|
||||
} else if (p[0] == MsgPack::FirstByte::UINT32) {
|
||||
u64 = _msgpack_load32(quint64, p + 1);
|
||||
return true;
|
||||
u64 = _msgpack_load32(quint64, p + 1);
|
||||
return true;
|
||||
} else if (p[0] == MsgPack::FirstByte::UINT64) {
|
||||
u64 = _msgpack_load64(quint64, p + 1);
|
||||
return true;
|
||||
|
@ -26,6 +26,8 @@ public:
|
||||
Status status() const;
|
||||
void resetStatus();
|
||||
void setStatus(Status status);
|
||||
void setFlushWrites(bool flushWrites);
|
||||
bool willFlushWrites();
|
||||
|
||||
MsgPackStream &operator>>(bool &b);
|
||||
MsgPackStream &operator>>(quint8 &u8);
|
||||
@ -40,7 +42,7 @@ public:
|
||||
MsgPackStream &operator>>(double &d);
|
||||
MsgPackStream &operator>>(QString &str);
|
||||
MsgPackStream &operator>>(QByteArray &array);
|
||||
bool readBytes(char *data, uint len);
|
||||
bool readBytes(char *data, qint64 len);
|
||||
bool readExtHeader(quint32 &len);
|
||||
|
||||
MsgPackStream &operator<<(bool b);
|
||||
@ -53,13 +55,14 @@ public:
|
||||
MsgPackStream &operator<<(QString str);
|
||||
MsgPackStream &operator<<(const char *str);
|
||||
MsgPackStream &operator<<(QByteArray array);
|
||||
bool writeBytes(const char *data, uint len);
|
||||
bool writeBytes(const char *data, qint64 len);
|
||||
bool writeExtHeader(quint32 len, qint8 msgpackType);
|
||||
|
||||
private:
|
||||
QIODevice *dev;
|
||||
bool owndev;
|
||||
Status q_status;
|
||||
bool flushWrites;
|
||||
|
||||
bool unpack_longlong(qint64 &i64);
|
||||
bool unpack_ulonglong(quint64 &u64);
|
||||
@ -94,7 +97,7 @@ MsgPackStream& operator>>(MsgPackStream& s, QList<T> &list)
|
||||
{
|
||||
list.clear();
|
||||
quint8 p[5];
|
||||
quint32 len;
|
||||
quint32 len = 0;
|
||||
s.readBytes((char *)p, 1);
|
||||
if (p[0] >= 0x90 && p[0] <= 0x9f) {
|
||||
len = p[0] & 0xf;
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "pack_p.h"
|
||||
#include "../endianhelper.h"
|
||||
|
||||
@ -18,7 +20,11 @@ QReadWriteLock MsgPackPrivate::packers_lock;
|
||||
quint8 *MsgPackPrivate::pack(const QVariant &v, quint8 *p, bool wr, QVector<QByteArray> &user_data)
|
||||
{
|
||||
QMetaType::Type t = (QMetaType::Type)v.type();
|
||||
#if QT_VERSION > QT_VERSION_CHECK(5, 8, 0)
|
||||
if ((v.isNull() && !v.isValid()) || t == QMetaType::Nullptr)
|
||||
#else
|
||||
if (v.isNull() && !v.isValid())
|
||||
#endif
|
||||
p = pack_nil(p, wr);
|
||||
else if (t == QMetaType::Int)
|
||||
p = pack_int(v.toInt(), p, wr);
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "qt_types_p.h"
|
||||
#include "pack_p.h"
|
||||
#include "unpack_p.h"
|
||||
@ -9,8 +11,6 @@
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
#include <QColor>
|
||||
#else
|
||||
#define NO_QTGUI_WARNING "qmsgpack was built without QtGui, hence some types are not available"
|
||||
#endif
|
||||
|
||||
#ifdef QT_LOCATION_LIB
|
||||
@ -20,45 +20,6 @@
|
||||
#include <QTime>
|
||||
#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
|
||||
QByteArray MsgPackPrivate::pack_qcolor(const QVariant &variant)
|
||||
{
|
||||
|
@ -6,8 +6,6 @@
|
||||
|
||||
namespace MsgPackPrivate
|
||||
{
|
||||
bool register_qtype(QMetaType::Type q_type, quint8 msgpack_type);
|
||||
|
||||
#ifdef QT_GUI_LIB
|
||||
QByteArray pack_qcolor(const QVariant &variant);
|
||||
QVariant unpack_qcolor(const QByteArray &data);
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "unpack_p.h"
|
||||
#include "../endianhelper.h"
|
||||
|
||||
@ -45,17 +47,18 @@ MsgPackPrivate::type_parser_f MsgPackPrivate::unpackers[32] = {
|
||||
QHash<qint8, MsgPack::unpack_user_f> MsgPackPrivate::user_unpackers;
|
||||
QReadWriteLock MsgPackPrivate::unpackers_lock;
|
||||
|
||||
QVariant MsgPackPrivate::unpack(quint8 *p, quint8 *end)
|
||||
QVariant MsgPackPrivate::unpack(const quint8 *p, const quint8 *end)
|
||||
{
|
||||
QVariantList d;
|
||||
|
||||
QVariant v;
|
||||
while (p <= end) {
|
||||
p = unpack_type(v, p);
|
||||
quint8* pos = const_cast<quint8*>(p); // FIXME
|
||||
while (pos <= end) {
|
||||
pos = unpack_type(v, pos);
|
||||
d.append(v);
|
||||
}
|
||||
|
||||
if (p - end > 1)
|
||||
if (pos - end > 1)
|
||||
return QVariant();
|
||||
|
||||
if (d.length() == 1)
|
||||
@ -115,26 +118,26 @@ quint8 * MsgPackPrivate::unpack_true(QVariant &v, quint8 *p)
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_positive_fixint(QVariant &v, quint8 *p)
|
||||
{
|
||||
v = (quint32)*p;
|
||||
v = static_cast<quint32>(*p);
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_negative_fixint(QVariant &v, quint8 *p)
|
||||
{
|
||||
v = (qint8)*p;
|
||||
v = static_cast<qint8>(*p);
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_uint8(QVariant &v, quint8 *p)
|
||||
{
|
||||
v = (quint8)*(++p);
|
||||
v = static_cast<quint32>(*(++p));
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_uint16(QVariant &v, quint8 *p)
|
||||
{
|
||||
p++;
|
||||
v = _msgpack_load16(quint16, p);
|
||||
v = static_cast<quint32>(_msgpack_load16(quint16, p));
|
||||
return p + 2;
|
||||
}
|
||||
|
||||
@ -154,7 +157,7 @@ quint8 * MsgPackPrivate::unpack_uint64(QVariant &v, quint8 *p)
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_int8(QVariant &v, quint8 *p)
|
||||
{
|
||||
v = (qint8)*(++p);
|
||||
v = static_cast<qint8>(*(++p));
|
||||
return p + 1;
|
||||
}
|
||||
|
||||
@ -182,7 +185,7 @@ quint8 * MsgPackPrivate::unpack_int64(QVariant &v, quint8 *p)
|
||||
quint8 * MsgPackPrivate::unpack_float32(QVariant &v, quint8 *p)
|
||||
{
|
||||
float f;
|
||||
quint8 *fp = (quint8 *)&f;
|
||||
quint8 *fp = reinterpret_cast<quint8 *>(&f);
|
||||
p++;
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
for (int i = 0; i < 4; ++i)
|
||||
@ -198,7 +201,7 @@ quint8 * MsgPackPrivate::unpack_float32(QVariant &v, quint8 *p)
|
||||
quint8 * MsgPackPrivate::unpack_float64(QVariant &v, quint8 *p)
|
||||
{
|
||||
double d;
|
||||
quint8 *fd = (quint8 *)&d;
|
||||
quint8 *fd = reinterpret_cast<quint8 *>(&d);
|
||||
p++;
|
||||
#ifdef __LITTLE_ENDIAN__
|
||||
for (int i = 0; i < 8; ++i)
|
||||
@ -215,14 +218,14 @@ quint8 * MsgPackPrivate::unpack_fixstr(QVariant &v, quint8 *p)
|
||||
{
|
||||
int len = (*p) & 0x1f; // 0b00011111
|
||||
p++;
|
||||
v = QString::fromUtf8((char*)p, len);
|
||||
v = QString::fromUtf8(reinterpret_cast<char*>(p), len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_str8(QVariant &v, quint8 *p)
|
||||
{
|
||||
int len = *(++p);
|
||||
v = QString::fromUtf8((char*)(++p), len);
|
||||
v = QString::fromUtf8(reinterpret_cast<char*>((++p)), len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
@ -231,7 +234,7 @@ quint8 * MsgPackPrivate::unpack_str16(QVariant &v, quint8 *p)
|
||||
p++;
|
||||
int len = _msgpack_load16(int, p);
|
||||
p += 2;
|
||||
v = QString::fromUtf8((char*)p, len);
|
||||
v = QString::fromUtf8(reinterpret_cast<char*>(p), len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
@ -240,14 +243,14 @@ quint8 * MsgPackPrivate::unpack_str32(QVariant &v, quint8 *p)
|
||||
p++;
|
||||
int len = _msgpack_load32(int, p);
|
||||
p += 4;
|
||||
v = QString::fromUtf8((char*)p, len);
|
||||
v = QString::fromUtf8(reinterpret_cast<char*>(p), len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_bin8(QVariant &v, quint8 *p)
|
||||
{
|
||||
int len = *(++p);
|
||||
v = QByteArray((char*)(++p), len);
|
||||
v = QByteArray(reinterpret_cast<char*>((++p)), len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
@ -256,7 +259,7 @@ quint8 * MsgPackPrivate::unpack_bin16(QVariant &v, quint8 *p)
|
||||
p++;
|
||||
int len = _msgpack_load16(int, p);
|
||||
p += 2;
|
||||
v = QByteArray((char*)p, len);
|
||||
v = QByteArray(reinterpret_cast<char*>(p), len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
@ -265,7 +268,7 @@ quint8 * MsgPackPrivate::unpack_bin32(QVariant &v, quint8 *p)
|
||||
p++;
|
||||
int len = _msgpack_load32(int, p);
|
||||
p += 4;
|
||||
v = QByteArray((char*)p, len);
|
||||
v = QByteArray(reinterpret_cast<char*>(p), len);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
@ -344,38 +347,38 @@ quint8 *MsgPackPrivate::unpack_ext(QVariant &v, quint8 *p, qint8 type, quint32 l
|
||||
qWarning() << "MsgPack::unpack() unpacker for type" << type << "doesn't exist";
|
||||
return p + len;
|
||||
}
|
||||
QByteArray data((char *)p, len);
|
||||
QByteArray data(reinterpret_cast<char*>(p), static_cast<int>(len));
|
||||
v = user_unpackers[type](data);
|
||||
return p + len;
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_fixext1(QVariant &v, quint8 *p)
|
||||
{
|
||||
qint8 type = *(++p);
|
||||
qint8 type = static_cast<qint8>(*(++p));
|
||||
return unpack_ext(v, p + 1, type, 1);
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_fixext2(QVariant &v, quint8 *p)
|
||||
{
|
||||
qint8 type = *(++p);
|
||||
qint8 type = static_cast<qint8>(*(++p));
|
||||
return unpack_ext(v, p + 1, type, 2);
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_fixext4(QVariant &v, quint8 *p)
|
||||
{
|
||||
qint8 type = *(++p);
|
||||
qint8 type = static_cast<qint8>(*(++p));
|
||||
return unpack_ext(v, p + 1, type, 4);
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_fixext8(QVariant &v, quint8 *p)
|
||||
{
|
||||
qint8 type = *(++p);
|
||||
qint8 type = static_cast<qint8>(*(++p));
|
||||
return unpack_ext(v, p + 1, type, 8);
|
||||
}
|
||||
|
||||
quint8 * MsgPackPrivate::unpack_fixext16(QVariant &v, quint8 *p)
|
||||
{
|
||||
qint8 type = *(++p);
|
||||
qint8 type = static_cast<qint8>(*(++p));
|
||||
return unpack_ext(v, p + 1, type, 16);
|
||||
}
|
||||
|
||||
@ -384,7 +387,7 @@ quint8 * MsgPackPrivate::unpack_ext8(QVariant &v, quint8 *p)
|
||||
p++;
|
||||
quint32 len = *(p);
|
||||
p += 1;
|
||||
qint8 type = *(p);
|
||||
qint8 type = static_cast<qint8>(*p);
|
||||
return unpack_ext(v, p + 1, type, len);
|
||||
}
|
||||
|
||||
@ -393,7 +396,7 @@ quint8 * MsgPackPrivate::unpack_ext16(QVariant &v, quint8 *p)
|
||||
p++;
|
||||
quint32 len = _msgpack_load16(quint32, p);
|
||||
p += 2;
|
||||
qint8 type = *(p);
|
||||
qint8 type = static_cast<qint8>(*p);
|
||||
return unpack_ext(v, p + 1, type, len);
|
||||
}
|
||||
|
||||
@ -402,13 +405,13 @@ quint8 * MsgPackPrivate::unpack_ext32(QVariant &v, quint8 *p)
|
||||
p++;
|
||||
quint32 len = _msgpack_load32(quint32, p);
|
||||
p += 4;
|
||||
qint8 type = *(p);
|
||||
qint8 type = static_cast<qint8>(*p);
|
||||
return unpack_ext(v, p + 1, type, len);
|
||||
}
|
||||
|
||||
bool MsgPackPrivate::register_unpacker(qint8 msgpack_type, MsgPack::unpack_user_f unpacker)
|
||||
{
|
||||
if (unpacker == 0) {
|
||||
if (unpacker == nullptr) {
|
||||
qWarning() << "MsgPack::unpacker for type" << msgpack_type << "is invalid";
|
||||
return false;
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ extern QHash<qint8, MsgPack::unpack_user_f> user_unpackers;
|
||||
extern QReadWriteLock unpackers_lock;
|
||||
|
||||
// goes from p to end unpacking types with unpack_type function below
|
||||
QVariant unpack(quint8 *p, quint8 *end);
|
||||
QVariant unpack(const quint8 *p, const quint8 *end);
|
||||
// unpack some type, can be called recursively from other unpack functions
|
||||
quint8 * unpack_type(QVariant &v, quint8 *p);
|
||||
|
||||
|
52
src/src.pro
52
src/src.pro
@ -1,41 +1,15 @@
|
||||
QT += core gui location
|
||||
|
||||
TARGET = qmsgpack
|
||||
CONFIG -= app_bundle
|
||||
VER_MAJ = 0
|
||||
VER_MIN = 1
|
||||
VER_PAT = 0
|
||||
|
||||
TEMPLATE = lib
|
||||
DEFINES += MSGPACK_MAKE_LIB
|
||||
DESTDIR = $$TOP_SRCDIR/bin
|
||||
QMAKE_CXXFLAGS += -fPIC
|
||||
DESTDIR = $$shadowed($$PWD/../bin)
|
||||
TARGET = $$qtLibraryTarget($$TARGET)
|
||||
VERSION = $$join($$list($$VER_MAJ $$VER_MIN $$VER_PAT), .)
|
||||
|
||||
CONFIG += debug_and_release
|
||||
CONFIG(debug, debug|release) {
|
||||
TARGET = $$join(TARGET,,,d)
|
||||
}
|
||||
|
||||
|
||||
SOURCES += msgpack.cpp \
|
||||
msgpackcommon.cpp \
|
||||
private/pack_p.cpp \
|
||||
private/unpack_p.cpp \
|
||||
private/qt_types_p.cpp \
|
||||
msgpackstream.cpp \
|
||||
stream/time.cpp \
|
||||
stream/geometry.cpp \
|
||||
stream/location.cpp
|
||||
|
||||
HEADERS += \
|
||||
msgpack.h \
|
||||
private/pack_p.h \
|
||||
private/unpack_p.h \
|
||||
endianhelper.h \
|
||||
msgpackcommon.h \
|
||||
msgpack_export.h \
|
||||
private/qt_types_p.h \
|
||||
msgpackstream.h \
|
||||
stream/location.h \
|
||||
stream/time.h \
|
||||
stream/geometry.h
|
||||
include(../qmsgpack.pri)
|
||||
|
||||
HEADERS_INSTALL = \
|
||||
msgpack.h \
|
||||
@ -44,9 +18,15 @@ HEADERS_INSTALL = \
|
||||
msgpack_export.h \
|
||||
msgpackstream.h \
|
||||
|
||||
STREAM_HEADERS_INSTALL = \
|
||||
stream/location.h \
|
||||
stream/time.h
|
||||
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
|
||||
STREAM_HEADERS_INSTALL = \
|
||||
stream/geometry.h \
|
||||
stream/time.h
|
||||
|
||||
qtHaveModule(location) {
|
||||
STREAM_HEADERS_INSTALL += stream/location.h
|
||||
}
|
||||
}
|
||||
|
||||
unix {
|
||||
header_files.files = $$HEADERS_INSTALL
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "geometry.h"
|
||||
#include "../msgpack.h"
|
||||
#include "../msgpackstream.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#ifdef QT_LOCATION_LIB
|
||||
|
||||
#include "location.h"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include "time.h"
|
||||
#include "../msgpack.h"
|
||||
|
||||
@ -79,7 +81,7 @@ MsgPackStream& operator>>(MsgPackStream& s, QTime &t)
|
||||
return s;
|
||||
}
|
||||
if (len == 1) {
|
||||
t == QTime();
|
||||
t = QTime();
|
||||
return s;
|
||||
}
|
||||
quint8 p[4];
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
#include <QDebug>
|
||||
|
@ -1,22 +1,7 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-09-26T19:10:31
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += testlib
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = mixed_test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
INCLUDEPATH += ../../src
|
||||
LIBS += -lqmsgpack
|
||||
QT += testlib
|
||||
CONFIG += testcase
|
||||
|
||||
include(../tests.pri)
|
||||
|
||||
SOURCES += mixed_test.cpp
|
||||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
#include <msgpack.h>
|
||||
@ -8,6 +10,7 @@ class MixedTest : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void test_uint();
|
||||
void test_float();
|
||||
void test_double();
|
||||
void test_map();
|
||||
@ -15,6 +18,19 @@ private Q_SLOTS:
|
||||
void test_mixed();
|
||||
};
|
||||
|
||||
void MixedTest::test_uint()
|
||||
{
|
||||
for (int i = 0; i <= 32; ++i) {
|
||||
const quint32 u = (0x1UL<<i) - 1;
|
||||
QByteArray packed = MsgPack::pack(u);
|
||||
QVariant unpacked = MsgPack::unpack(packed);
|
||||
QVERIFY2(unpacked.type() == QVariant::Type::UInt,
|
||||
qPrintable(QString("Unpack failed for value %1. Type is %2").arg(u).arg(unpacked.type())));
|
||||
QVERIFY2(unpacked.toUInt() == u,
|
||||
qPrintable(QString("Unpack failed for value %1. Type is %2").arg(u).arg(unpacked.type())));
|
||||
}
|
||||
}
|
||||
|
||||
void MixedTest::test_float()
|
||||
{
|
||||
float f;
|
||||
@ -126,7 +142,7 @@ void MixedTest::test_map()
|
||||
class CustomType
|
||||
{
|
||||
public:
|
||||
CustomType() {}
|
||||
CustomType() : m_size(777) {}
|
||||
CustomType(const CustomType &other) { m_size = other.m_size; }
|
||||
~CustomType() {}
|
||||
|
||||
|
@ -1,22 +0,0 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-09-20T15:17:37
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += testlib
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = pack_test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
|
||||
LIBS += -lqmsgpack
|
||||
INCLUDEPATH += ../../src
|
||||
|
||||
|
||||
SOURCES += pack_test.cpp
|
||||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
7
tests/pack/pack.pro
Normal file
7
tests/pack/pack.pro
Normal file
@ -0,0 +1,7 @@
|
||||
TARGET = pack_test
|
||||
QT += testlib
|
||||
CONFIG += testcase
|
||||
|
||||
include(../tests.pri)
|
||||
|
||||
SOURCES += pack_test.cpp
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <QString>
|
||||
#include <QByteArray>
|
||||
#include <QtTest>
|
||||
@ -9,6 +11,7 @@ class PackTest : public QObject
|
||||
Q_OBJECT
|
||||
|
||||
private Q_SLOTS:
|
||||
void test_nil();
|
||||
void test_bool();
|
||||
void test_fixint();
|
||||
void test_integer8();
|
||||
@ -21,6 +24,24 @@ private Q_SLOTS:
|
||||
void test_array();
|
||||
};
|
||||
|
||||
void PackTest::test_nil()
|
||||
{
|
||||
QVariant v;
|
||||
QByteArray arr = MsgPack::pack(v);
|
||||
quint8 *p = (quint8 *)arr.data();
|
||||
QVERIFY(arr.size() == 1);
|
||||
QVERIFY(p[0] == 0xc0);
|
||||
|
||||
#if QT_VERSION > QT_VERSION_CHECK(5, 8, 0)
|
||||
v.setValue(nullptr);
|
||||
QVERIFY((QMetaType::Type)v.type() == QMetaType::Nullptr);
|
||||
arr = MsgPack::pack(v);
|
||||
p = (quint8 *)arr.data();
|
||||
QVERIFY(arr.size() == 1);
|
||||
QVERIFY(p[0] == 0xc0);
|
||||
#endif
|
||||
}
|
||||
|
||||
void PackTest::test_bool()
|
||||
{
|
||||
QByteArray arr = MsgPack::pack(false);
|
||||
|
7
tests/qttypes/qttypes.pro
Normal file
7
tests/qttypes/qttypes.pro
Normal file
@ -0,0 +1,7 @@
|
||||
TARGET = qttypes_test
|
||||
QT += testlib
|
||||
CONFIG += testcase
|
||||
|
||||
include(../tests.pri)
|
||||
|
||||
SOURCES += qttypes_test.cpp
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
#include <QDebug>
|
||||
|
7
tests/stream/stream.pro
Normal file
7
tests/stream/stream.pro
Normal file
@ -0,0 +1,7 @@
|
||||
TARGET = stream_test
|
||||
QT += testlib
|
||||
CONFIG += testcase
|
||||
|
||||
include(../tests.pri)
|
||||
|
||||
SOURCES += stream_test.cpp
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
#include <QDebug>
|
||||
|
2
tests/tests.pri
Normal file
2
tests/tests.pri
Normal file
@ -0,0 +1,2 @@
|
||||
INCLUDEPATH += ../../src
|
||||
LIBS += -L$$shadowed($$PWD/../bin) -l$$qtLibraryTarget(qmsgpack)
|
12
tests/tests.pro
Normal file
12
tests/tests.pro
Normal file
@ -0,0 +1,12 @@
|
||||
TEMPLATE = subdirs
|
||||
|
||||
SUBDIRS += \
|
||||
pack \
|
||||
unpack \
|
||||
mixed
|
||||
|
||||
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
|
||||
SUBDIRS += \
|
||||
stream \
|
||||
qttypes
|
||||
}
|
@ -1,21 +1,7 @@
|
||||
#-------------------------------------------------
|
||||
#
|
||||
# Project created by QtCreator 2014-09-25T10:25:22
|
||||
#
|
||||
#-------------------------------------------------
|
||||
|
||||
QT += testlib
|
||||
|
||||
QT -= gui
|
||||
|
||||
TARGET = unpack_test
|
||||
CONFIG += console
|
||||
CONFIG -= app_bundle
|
||||
|
||||
TEMPLATE = app
|
||||
include($$PWD/../../qmsgpack.pri)
|
||||
INCLUDEPATH += ../../src
|
||||
QT += testlib
|
||||
CONFIG += testcase
|
||||
|
||||
include(../tests.pri)
|
||||
|
||||
SOURCES += unpack_test.cpp
|
||||
DEFINES += SRCDIR=\\\"$$PWD/\\\"
|
||||
|
@ -1,3 +1,5 @@
|
||||
// This is an open source non-commercial project. Dear PVS-Studio, please check it.
|
||||
// PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com
|
||||
#include <QString>
|
||||
#include <QtTest>
|
||||
#include <QDebug>
|
||||
|
Reference in New Issue
Block a user