54 Commits

Author SHA1 Message Date
cd3fcec745 Fix install on windows 2024-10-24 10:46:16 +02:00
0117422339 Fix include problems with incorrect install step 2024-07-05 23:59:46 +02:00
8f92d3c389 More patches to get it really working with Qt6 and android 2024-06-30 11:33:10 +02:00
e24b73a8d6 Patches to get it working with Qt6 2024-06-29 16:33:25 +02:00
a7d9c00b98 Merge pull request #39 from georgerb/master
Added COMPILE_TYPE cmake command line variable
2020-04-16 19:53:39 +02:00
86dd3b1c14 Merge pull request #43 from mincequi/master
Fix unpack for uint values 127 < x < 65536
2020-04-16 19:52:38 +02:00
8cdf333e5b Fix unpack for uint values 127 < x < 65536 2020-04-09 13:01:53 +02:00
14847e5a72 Added COMPILE_TYPE cmake command line variable to support static or shared compilation 2019-09-20 15:38:18 -04:00
7e1ca5b414 Fix CI build. 2019-06-30 10:14:39 +03:00
1733bc7847 Fix CI build. 2019-06-30 09:15:59 +03:00
024d901605 Fix CI build. 2019-06-30 09:12:01 +03:00
a9e429a30f Pack QMetaType::Nullptr QVariant's as nil. 2019-06-30 09:03:04 +03:00
efc99ef590 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
2019-05-04 10:16:13 +03:00
8a4f180c00 Merge pull request #37 from antis81/fix/data_types
Fixes type and type cast compiler warnings.
2019-05-04 10:14:38 +03:00
3cafa3b006 fix type casts in msgpack 2019-02-20 14:02:05 +01:00
166fd5acad interim fix for the "const QByteArray&" casts
Did not dive much into the address logic here, but I think we would
be better of with index counting instead of addresses.
2019-02-20 14:01:32 +01:00
538f28dc24 fix pointer comparison warning 2019-02-20 13:57:13 +01:00
fc8f9d7c66 fix msgpack private type casts 2019-02-20 13:51:15 +01:00
e1d8226780 rename endianhelper.h include guard
Also fixes "reserved macro" warning.
2019-02-20 13:47:37 +01:00
1591ebddd4 fix type casts in endian helper macros 2019-02-20 13:46:18 +01:00
0b8282d592 Make it possible to disable Qt type pack handlers at build time
usable with either
  qmake DEFINES+=MSGPACK_NO_PACKTYPES
or
  DEFINES += MSGPACK_STATIC MSGPACK_NO_PACKTYPES
  include(path/to/qmsgpack/qmsgpack.pri)
2018-12-02 14:25:14 +03:00
34afb5aba3 Refactor MsgPack::registerType() a little bit
move MsgPackPrivate::register_qtype() impl to MsgPack::registerType();
warn and return false when the requested type is not known to qmsgpack
2018-12-02 14:25:14 +03:00
e3819fc5b3 Fix Travis build. 2018-12-02 00:33:11 +03:00
639a96428e Update CMakeLists.txt 2018-12-02 00:31:33 +03:00
f98072b753 Fix Travis build, again. 2018-12-02 00:24:44 +03:00
11888b97e7 Merge pull request #34 from KonstantinRitt/mr/symbols_visibility
Improve symbols visibility control
2018-12-02 00:19:49 +03:00
4bc12f75e5 Merge pull request #35 from KonstantinRitt/mr/pri
Modernize qmake project files and fix some build issues
2018-12-02 00:19:14 +03:00
d9f37afe2e Build and run tests with qmake
as of now, running tests is as simple as just typing
  qmake && make check
2018-11-20 21:21:07 +03:00
6455058b4f Do not override user configs and flags
the default ones from Qt should be fine
2018-11-20 21:21:05 +03:00
172c71b027 Consolidate target lib name, path and version across platforms and configs 2018-11-20 21:19:30 +03:00
b15b5efdb4 Re-use qmsgpack.pri in library builds
Deduplicates the build rules and ensures no differences in
source-in and library build rules
2018-11-20 21:14:04 +03:00
ca968dbb4e Make the QtGui module an optional dependency
detect and link with it, if found
2018-11-20 21:13:55 +03:00
a579f324d7 Install missing stream header 2018-11-20 20:29:10 +03:00
2c7a329c48 Improve symbols visibility control
visibility 'hidden' should be normally preferred for static builds,
which is also true for source-in builds as well
2018-11-20 15:12:43 +03:00
0cd5fd2d68 Comment out paths to Qt installation. 2018-10-26 22:49:01 +03:00
a672db294a Update .travis.yml 2018-10-26 22:44:29 +03:00
c91993750d Remove broken cmake package from TravisCI. 2018-10-26 22:28:54 +03:00
47128d5771 Update to TravisCI Qt5.9. 2018-10-26 22:25:22 +03:00
4f1c4d3d80 Merge pull request #30 from KonstantinRitt/fixes/build
build fixes
2018-03-03 22:27:20 +03:00
5ca284052c Fix build when including qmsgpack.pri from another project
presence of .qmake.conf file in an included sub-project
overrides the root project thus breaking the build
2018-03-02 16:01:00 +03:00
a412eedf24 Fix build with QT_NO_CAST_FROM_ASCII 2018-03-02 16:01:00 +03:00
b7284725e8 Fix bugs in msgpackstream.cpp, add PVS Studio headers and how to, add stream test to Qt project. 2017-07-10 16:02:38 +03:00
aa613f658f Merge pull request #26 from arturo182/master
Fix location module detection
2017-03-02 11:52:33 +03:00
e64de7eac3 Merge pull request #27 from mtstickney/stream_partial_writes
Stream partial writes
2017-03-02 11:52:18 +03:00
ca56d9e362 Add an option to flush writes.
There is a bug with QLocalSockets on Windows where data will be silently
dropped if two consecutive writes are performed without flushing and the
remote end hasn't read all the data between the two (see
https://bugreports.qt.io/browse/QTBUG-18385). Since qmsgpack performs
several write operations as part of a single stream output, it must allow
callers to specify whether to flush writes in order to work around this
bug.
2017-02-27 17:32:49 -05:00
22750cf88b Fix location module detection 2017-02-20 10:20:18 +01:00
067c72767a Handle partial writes correctly.
QIODevice::write() can theoretically write any number of bytes less than
the amount that was requested. If the result was >= 0, we haven't hit EOF
or an actual error yet and should continue attempting to write. Note that
the docs[1] for QIODevice::writeData() specify that writeData should write
all available data before returning or else QDataStream won't work, but
that's no guarantee that all implementors of QIODevice will actually do so.

Also note that this does not call QIODevice::waitForBytesWritten after
writing, which would negate the benefits of buffering for buffered devices.
As a side-effect, that means this will spin if the writes don't complete.

[1] http://doc.qt.io/qt-5/qiodevice.html#writeData
2017-02-16 16:24:13 -05:00
bec0d71cc1 Initialize the stream status to OK in the QIODevice constructor.
Without this, the status is an an uninitialize state, which causes the
precondition checks to fail on writes.
2017-02-16 16:24:04 -05:00
9d017281fe Update .travis.yml 2017-02-16 23:06:59 +03:00
51932532d2 Merge pull request #24 from arturo182/master
Improvement and a fix
2017-02-16 23:02:49 +03:00
bf12914846 Merge pull request #23 from mtstickney/stream_partial_reads
Handle partial reads correctly.
2017-02-16 22:59:24 +03:00
6e753f0669 Fix erroneous comparison instead of assignment 2017-02-15 10:20:25 +01:00
2d8af48459 Make the qtlocation module an optional dependency 2017-02-15 10:13:28 +01:00
4ff4ba8448 Handle partial reads correctly.
QIODevice::read() can read any number of bytes less than the amount
requested if there wasn't that much data available. If the result is >= 0,
we haven't actually hit EOF yet and should continue trying to read data.
Since QIODevice::read() doesn't block, we use QIODevice::waitForReadyRead()
to avoid spinning waiting for input to arrive.

If we encounter EOF or another error during a read, we set the ReadPastEnd
status and walk away as normal.
2017-02-08 18:46:31 -05:00
37 changed files with 506 additions and 408 deletions

View File

@ -1,3 +0,0 @@
TOP_SRCDIR=$$PWD
TOP_BUILDDIR=$$shadowed($$PWD)

View File

@ -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

View File

@ -1,13 +1,15 @@
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(Qt6Core_DIR "/opt/Qt6.6.0/5.6/gcc_64/lib/cmake/Qt6Core")
#set(Qt6Test_DIR "/opt/Qt6.6.0/5.6/gcc_64/lib/cmake/Qt6Test")
#set(Qt6_DIR "/opt/Qt6.6.0/5.6/gcc_64/lib/cmake/Qt6Core")
#set(QT_QMAKE_EXECUTABLE "/opt/Qt6.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 20)
set(CMAKE_INSTALL_NAME_DIR ${LIB_INSTALL_DIR})
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# build type
if ("${CMAKE_BUILD_TYPE}" MATCHES "^Rel.*")
@ -21,49 +23,49 @@ endif (WIN32)
option (QT4_BUILD "BUild with Qt4")
if (NOT QT4_BUILD)
find_package(Qt5Core QUIET)
find_package(Qt6Core QUIET)
endif ()
if (Qt5Core_FOUND)
message("Qt5 found")
include_directories(${Qt5Core_INCLUDE_DIRS})
add_definitions(${Qt5Core_DEFINITIONS})
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(PC_Requires "Qt5Core")
if (Qt6Core_FOUND)
message("Qt6 found")
include_directories(${Qt6Core_INCLUDE_DIRS})
add_definitions(${Qt6Core_DEFINITIONS})
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(PC_Requires "Qt6Core")
else ()
message("Qt5 not found, searching for Qt4")
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(PC_Requires "QtCore")
message("Qt6 not found, searching for Qt4")
find_package(Qt4 REQUIRED)
include(${QT_USE_FILE})
# Find includes in corresponding build directories
set(CMAKE_INCLUDE_CURRENT_DIR ON)
# Instruct CMake to run moc automatically when needed.
set(CMAKE_AUTOMOC ON)
set(PC_Requires "QtCore")
endif ()
option (WITH_GUI_TYPES "Build with support for QtGui types")
if (WITH_GUI_TYPES)
if (QT4_BUILD)
find_package(Qt4 QTGUI)
else ()
find_package(Qt5Gui QUIET)
endif ()
if (QT4_BUILD)
find_package(Qt4 QTGUI)
else ()
find_package(Qt6Gui QUIET)
endif ()
endif ()
option (WITH_LOCATION_TYPES "Build with support for QtLocation types")
if (WITH_LOCATION_TYPES)
find_package(Qt5Location QUIET)
find_package(Qt6Location QUIET)
endif ()
if (Qt5Location_FOUND)
message("Qt5Location found")
include_directories(${Qt5Location_INCLUDE_DIRS})
add_definitions(${Qt5Location_DEFINITIONS})
if (Qt6Location_FOUND)
message("Qt6Location found")
include_directories(${Qt6Location_INCLUDE_DIRS})
add_definitions(${Qt6Location_DEFINITIONS})
else ()
message("Qt5Location not found")
message("Qt6Location not found")
endif ()
if (NOT WIN32)
@ -95,9 +97,9 @@ if (BUILD_TESTS)
add_subdirectory(tests)
endif ()
install(EXPORT qmsgpack-export DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE MsgPackQtTargets.cmake)
# install(EXPORT qmsgpack-export DESTINATION ${CMAKECONFIG_INSTALL_DIR} FILE MsgPackQtTargets.cmake)
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
View 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

View File

@ -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
}
}

View File

@ -1,4 +1,5 @@
TEMPLATE = subdirs
SUBDIRS += \
src
src \
tests

View File

@ -2,17 +2,21 @@ 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)
if (Qt5Core_FOUND)
target_link_libraries(qmsgpack Qt5::Core)
else ()
target_link_libraries(qmsgpack ${QT_LIBRARIES})
endif ()
find_package(Qt6 REQUIRED COMPONENTS Core Gui Quick)
if (Qt5Gui_FOUND)
target_link_libraries(qmsgpack Qt5::Gui)
endif ()
add_library(qmsgpack ${COMPILE_TYPE} ${qmsgpack_srcs} ${qmsgpack_headers})
target_include_directories(qmsgpack PUBLIC .)
target_link_libraries(qmsgpack PUBLIC
Qt6::Core
Qt6::Gui
Qt6::Quick
)
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/msgpackcommon.h.in"
@ -20,19 +24,23 @@ configure_file(
IMMEDIATE @ONLY)
if (NOT android)
set_target_properties(qmsgpack PROPERTIES
VERSION ${QMSGPACK_MAJOR}.${QMSGPACK_MINOR}.${QMSGPACK_VERSION}
SOVERSION ${QMSGPACK_MAJOR})
set_target_properties(qmsgpack PROPERTIES
VERSION ${QMSGPACK_MAJOR}.${QMSGPACK_MINOR}.${QMSGPACK_VERSION}
SOVERSION ${QMSGPACK_MAJOR}
)
endif ()
set_target_properties(qmsgpack PROPERTIES
DEFINE_SYMBOL MSGPACK_MAKE_LIB
PUBLIC_HEADER "${qmsgpack_headers}")
DEFINE_SYMBOL MSGPACK_MAKE_LIB
PUBLIC_HEADER "${qmsgpack_headers}")
install(TARGETS qmsgpack EXPORT qmsgpack-export
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/qmsgpack)
install(TARGETS qmsgpack)
# install(TARGETS qmsgpack EXPORT qmsgpack-export
# LIBRARY DESTINATION ${LIB_INSTALL_DIR}
# RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
# ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
# PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/qmsgpack)
install(FILES ${qmsgpack_stream_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/qmsgpack/stream)
# install(FILES ${qmsgpack_stream_headers} DESTINATION ${INCLUDE_INSTALL_DIR}/qmsgpack/stream)

View File

@ -1,34 +0,0 @@
set(qmsgpack_srcs msgpack.cpp msgpack_common.cpp stream.cpp private/pack_p.cpp private/unpack_p.cpp private/qt_types_p.cpp)
set(qmsgpack_headers msgpack.h stream.h msgpack_common.h msgpack_export.h endianhelper.h)
add_library(qmsgpack SHARED ${qmsgpack_srcs} ${qmsgpack_headers})
if (Qt5Core_FOUND)
target_link_libraries(qmsgpack Qt5::Core)
else ()
target_link_libraries(qmsgpack ${QT_LIBRARIES})
endif ()
if (Qt5Gui_FOUND)
target_link_libraries(qmsgpack Qt5::Gui)
endif ()
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/msgpack_common.h.in"
"${CMAKE_CURRENT_SOURCE_DIR}/msgpack_common.h"
IMMEDIATE @ONLY)
if (NOT android)
set_target_properties(qmsgpack PROPERTIES
VERSION ${QMSGPACK_MAJOR}.${QMSGPACK_MINOR}.${QMSGPACK_VERSION}
SOVERSION ${QMSGPACK_MAJOR})
endif ()
set_target_properties(qmsgpack PROPERTIES
DEFINE_SYMBOL MSGPACK_MAKE_LIB
PUBLIC_HEADER "${qmsgpack_headers}")
install(TARGETS qmsgpack EXPORT qmsgpack-export
LIBRARY DESTINATION ${LIB_INSTALL_DIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
ARCHIVE DESTINATION ${LIB_INSTALL_DIR}
PUBLIC_HEADER DESTINATION ${INCLUDE_INSTALL_DIR}/qmsgpack)

View File

@ -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 */

View File

@ -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)

View File

@ -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

View File

@ -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);

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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)
{

View File

@ -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);

View File

@ -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;
}

View File

@ -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);

View File

@ -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

View File

@ -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"

View File

@ -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"

View File

@ -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];

View File

@ -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>

View File

@ -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/\\\"

View File

@ -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() {}

View File

@ -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
View File

@ -0,0 +1,7 @@
TARGET = pack_test
QT += testlib
CONFIG += testcase
include(../tests.pri)
SOURCES += pack_test.cpp

View File

@ -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);

View File

@ -0,0 +1,7 @@
TARGET = qttypes_test
QT += testlib
CONFIG += testcase
include(../tests.pri)
SOURCES += qttypes_test.cpp

View File

@ -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
View File

@ -0,0 +1,7 @@
TARGET = stream_test
QT += testlib
CONFIG += testcase
include(../tests.pri)
SOURCES += stream_test.cpp

View File

@ -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
View File

@ -0,0 +1,2 @@
INCLUDEPATH += ../../src
LIBS += -L$$shadowed($$PWD/../bin) -l$$qtLibraryTarget(qmsgpack)

12
tests/tests.pro Normal file
View File

@ -0,0 +1,12 @@
TEMPLATE = subdirs
SUBDIRS += \
pack \
unpack \
mixed
!contains(DEFINES, MSGPACK_NO_PACKTYPES) {
SUBDIRS += \
stream \
qttypes
}

View File

@ -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/\\\"

View File

@ -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>