mirror of
https://github.com/msgpack/msgpack-c
synced 2026-06-08 16:11:40 +00:00
+173
-42
@@ -1,75 +1,206 @@
|
||||
language: cpp
|
||||
cache:
|
||||
- apt
|
||||
before_install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:h-rayflood/llvm-upper; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update; fi
|
||||
sudo: false
|
||||
|
||||
install:
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-4.8-multilib g++-4.8-multilib; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.6; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 90; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32gcc1; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y libc6-i386; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32z1-dev; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32stdc++6; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y bzip2; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y libc6-dbg; fi
|
||||
- wget https://github.com/google/googletest/archive/release-1.7.0.zip -O googletest-release-1.7.0.zip
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then wget http://valgrind.org/downloads/valgrind-3.12.0.tar.bz2 && tar xjf valgrind-3.12.0.tar.bz2 && cd valgrind-3.12.0 && ./configure && make && sudo make install && cd ..; fi
|
||||
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew unlink boost; fi
|
||||
- if [ "$BOOST" == "boost" ]; then wget http://sourceforge.net/projects/boost/files/boost/1.62.0/boost_1_62_0.zip && unzip -q boost_1_62_0.zip && cd boost_1_62_0 && ./bootstrap.sh && ./b2 --with-timer --with-chrono address-model="$ARCH" > /dev/null && sudo ./b2 --with-timer --with-chrono address-model="$ARCH" install > /dev/null && cd ..; fi
|
||||
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then unzip -q googletest-release-1.7.0.zip && cd googletest-release-1.7.0 && sudo cp -r include/gtest /usr/local/include && g++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && g++ -m32 src/gtest-all.cc -I. -Iinclude -c && g++ -m32 src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mkdir /usr/local/lib32 && sudo mv *.a /usr/local/lib32 && cd ..; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "osx" ]; then unzip -q googletest-release-1.7.0.zip && cd googletest-release-1.7.0 && sudo cp -r include/gtest /usr/local/include && clang++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && cd ..; fi
|
||||
|
||||
before_script:
|
||||
- export PATH=/usr/local/bin:$PATH && rm -rf install
|
||||
- export BASE=`pwd`
|
||||
- mkdir ${BASE}/usr
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then wget --no-check-certificate https://cmake.org/files/v3.7/cmake-3.7.1-Linux-x86_64.sh -O cmake-3.7.1-Linux-x86_64.sh; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then chmod a+x cmake-3.7.1-Linux-x86_64.sh; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then ./cmake-3.7.1-Linux-x86_64.sh --prefix=${BASE}/usr --skip-license; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then export PATH="${BASE}/usr/bin:$PATH"; fi
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then export LD_LIBRARY_PATH="${BASE}/usr/lib:$LD_LIBRARY_PATH"; fi
|
||||
- if [ "$CXX" = "g++" ]; then export CXX="g++-6" CC="gcc-6"; fi
|
||||
- if [ "$CXX" = "clang++" ] && [ "$TRAVIS_OS_NAME" == "linux" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi
|
||||
#gtest
|
||||
- wget https://github.com/google/googletest/archive/release-1.7.0.zip -O googletest-release-1.7.0.zip
|
||||
- unzip -q googletest-release-1.7.0.zip
|
||||
- cd googletest-release-1.7.0
|
||||
- $CXX -m${ARCH} src/gtest-all.cc -I. -Iinclude -c
|
||||
- $CXX -m${ARCH} src/gtest_main.cc -I. -Iinclude -c
|
||||
- ar -rv libgtest.a gtest-all.o
|
||||
- ar -rv libgtest_main.a gtest_main.o
|
||||
- mkdir -p ${BASE}/usr/include
|
||||
- cp -r include/gtest ${BASE}/usr/include
|
||||
- mkdir -p ${BASE}/usr/lib
|
||||
- mv *.a ${BASE}/usr/lib
|
||||
- cd ..
|
||||
# valgrind
|
||||
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then wget http://valgrind.org/downloads/valgrind-3.12.0.tar.bz2 && tar xjf valgrind-3.12.0.tar.bz2 && cd valgrind-3.12.0 && ./configure --prefix=${BASE}/usr > /dev/null && make -j3 > /dev/null && make install > /dev/null && cd ..; fi
|
||||
# boost
|
||||
- if [ "$BOOST" == "ON" ]; then wget http://sourceforge.net/projects/boost/files/boost/1.63.0/boost_1_63_0.zip && unzip -q boost_1_63_0.zip && cd boost_1_63_0 && ./bootstrap.sh && ./b2 -j3 --prefix=${BASE}/usr --with-timer --with-chrono address-model=${ARCH} install > /dev/null && cd ..; fi
|
||||
|
||||
matrix:
|
||||
include:
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="1"
|
||||
env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="1"
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="signed" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2" X3_PARSE="ON"
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2"
|
||||
- os: osx
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" ARCH="64" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="1"
|
||||
env: ACTION="ci/build_cmake.sh" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="1"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
- llvm-toolchain-precise
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-5-multilib
|
||||
- g++-5-multilib
|
||||
- bzip2
|
||||
- clang-3.7
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" ARCH="32" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
- llvm-toolchain-precise
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-5-multilib
|
||||
- g++-5-multilib
|
||||
- lib32stdc++6-6-dbg
|
||||
- lib32gcc1
|
||||
- libc6-i386
|
||||
- lib32z1-dev
|
||||
- bzip2
|
||||
- clang-3.7
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="signed" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2" X3_PARSE="ON"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
- llvm-toolchain-precise
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-5-multilib
|
||||
- g++-5-multilib
|
||||
- bzip2
|
||||
- clang-3.7
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: clang
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="" BOOST_INC="" SHARED="OFF" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="32" SHARED="OFF" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
- llvm-toolchain-precise-3.7
|
||||
- llvm-toolchain-precise
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-5-multilib
|
||||
- g++-5-multilib
|
||||
- lib32stdc++6-6-dbg
|
||||
- lib32gcc1
|
||||
- libc6-i386
|
||||
- lib32z1-dev
|
||||
- bzip2
|
||||
- clang-3.7
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="signed" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-6-multilib
|
||||
- g++-6-multilib
|
||||
- bzip2
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="32" BOOST="ON" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="2" X3_PARSE="ON"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-6-multilib
|
||||
- g++-6-multilib
|
||||
- lib32stdc++6-6-dbg
|
||||
- lib32gcc1
|
||||
- libc6-i386
|
||||
- lib32z1-dev
|
||||
- bzip2
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib" BOOST="" BOOST_INC="" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" ARCH="64" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="2"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-6-multilib
|
||||
- g++-6-multilib
|
||||
- bzip2
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="1"
|
||||
env: ACTION="ci/build_cmake.sh" ARCH="32" BOOST="ON" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="1"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-6-multilib
|
||||
- g++-6-multilib
|
||||
- lib32stdc++6-6-dbg
|
||||
- lib32gcc1
|
||||
- libc6-i386
|
||||
- lib32z1-dev
|
||||
- bzip2
|
||||
- libc6-dbg
|
||||
- os: linux
|
||||
compiler: gcc
|
||||
env: ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32" BOOST="boost" BOOST_INC="/usr/local/boost" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="2"
|
||||
env: ACTION="ci/build_cmake.sh" ARCH="32" BOOST="ON" SHARED="OFF" CHAR_SIGN="signed" API_VERSION="2"
|
||||
addons:
|
||||
apt:
|
||||
sources:
|
||||
- ubuntu-toolchain-r-test
|
||||
packages:
|
||||
- g++-multilib
|
||||
- gcc-multilib
|
||||
- gcc-6-multilib
|
||||
- g++-6-multilib
|
||||
- lib32stdc++6-6-dbg
|
||||
- lib32gcc1
|
||||
- libc6-i386
|
||||
- lib32z1-dev
|
||||
- bzip2
|
||||
- libc6-dbg
|
||||
|
||||
script:
|
||||
- git clean -xdf && CMAKE_LIBRARY_PATH=${LIBPATH} ${ACTION} ${VERSION} ${ARCH} ${BOOST} ${BOOST_INC} ${CHAR_SIGN}
|
||||
- CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" CMAKE_LIBRARY_PATH="${BASE}/usr/lib:${BASE}/build" GTEST_ROOT="${BASE}/usr" BOOST_ROOT="${BASE}/usr" ${ACTION}
|
||||
|
||||
+43
-21
@@ -38,27 +38,40 @@ IF (APPLE)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_CXX11)
|
||||
IF (MSGPACK_USE_X3_PARSE)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_X3_PARSE -std=c++14 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_X3_PARSE -std=c++14 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_X3_PARSE ${CMAKE_CXX_FLAGS}")
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
|
||||
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++11.")
|
||||
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++14.")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ELSE ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
IF ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER ${GNUCXX_STD_SUPPORT_VERSION}) OR
|
||||
(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${GNUCXX_STD_SUPPORT_VERSION}))
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++98 ${CMAKE_CXX_FLAGS}")
|
||||
IF (MSGPACK_CXX11)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
|
||||
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++11.")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++98 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 18)
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_CPP03 ${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
IF ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER ${GNUCXX_STD_SUPPORT_VERSION}) OR
|
||||
(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${GNUCXX_STD_SUPPORT_VERSION}))
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++98 ${CMAKE_CXX_FLAGS}")
|
||||
ENDIF ()
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++98 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 18)
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_CPP03 ${CMAKE_CXX_FLAGS}")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
@@ -75,15 +88,25 @@ IF (MSGPACK_32BIT)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples." ON)
|
||||
|
||||
IF (MSGPACK_BOOST)
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_BOOST ${CMAKE_CXX_FLAGS}")
|
||||
SET (Boost_USE_STATIC_LIBS ON) # only find static libs
|
||||
SET (Boost_USE_MULTITHREADED ON)
|
||||
SET (Boost_USE_STATIC_RUNTIME OFF)
|
||||
FIND_PACKAGE (Boost COMPONENTS chrono timer system)
|
||||
INCLUDE_DIRECTORIES (
|
||||
${MSGPACK_BOOST_DIR}
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
SET (Boost_USE_STATIC_LIBS ON) # only find static libs
|
||||
SET (Boost_USE_MULTITHREADED ON)
|
||||
SET (Boost_USE_STATIC_RUNTIME OFF)
|
||||
FIND_PACKAGE (Boost COMPONENTS chrono context timer system)
|
||||
IF (Boost_INCLUDE_DIRS)
|
||||
INCLUDE_DIRECTORIES (
|
||||
${Boost_INCLUDE_DIRS}
|
||||
)
|
||||
ENDIF ()
|
||||
IF (MSGPACK_BOOST_DIR)
|
||||
INCLUDE_DIRECTORIES (
|
||||
${MSGPACK_BOOST_DIR}
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_CHAR_SIGN)
|
||||
@@ -123,7 +146,6 @@ FIND_PACKAGE (Threads)
|
||||
IF (GTEST_FOUND AND ZLIB_FOUND AND THREADS_FOUND)
|
||||
OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON)
|
||||
ENDIF ()
|
||||
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples." ON)
|
||||
|
||||
OPTION (MSGPACK_ENABLE_CXX "Enable C++ interface." ON)
|
||||
OPTION (MSGPACK_ENABLE_SHARED "Build shared libaries in addition to static libraries." ON)
|
||||
|
||||
+10
@@ -226,6 +226,7 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/object_fwd_decl.hpp
|
||||
include/msgpack/pack.hpp
|
||||
include/msgpack/pack_decl.hpp
|
||||
include/msgpack/parse_return.hpp
|
||||
include/msgpack/preprocessor.hpp
|
||||
include/msgpack/preprocessor/arithmetic.hpp
|
||||
include/msgpack/preprocessor/arithmetic/add.hpp
|
||||
@@ -500,6 +501,7 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/type.hpp
|
||||
include/msgpack/unpack.hpp
|
||||
include/msgpack/unpack_decl.hpp
|
||||
include/msgpack/unpack_exception.hpp
|
||||
include/msgpack/v1/adaptor/adaptor_base.hpp
|
||||
include/msgpack/v1/adaptor/adaptor_base_decl.hpp
|
||||
include/msgpack/v1/adaptor/array_ref.hpp
|
||||
@@ -586,11 +588,13 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/v1/object_fwd_decl.hpp
|
||||
include/msgpack/v1/pack.hpp
|
||||
include/msgpack/v1/pack_decl.hpp
|
||||
include/msgpack/v1/parse_return.hpp
|
||||
include/msgpack/v1/preprocessor.hpp
|
||||
include/msgpack/v1/sbuffer.hpp
|
||||
include/msgpack/v1/sbuffer_decl.hpp
|
||||
include/msgpack/v1/unpack.hpp
|
||||
include/msgpack/v1/unpack_decl.hpp
|
||||
include/msgpack/v1/unpack_exception.hpp
|
||||
include/msgpack/v1/version.hpp
|
||||
include/msgpack/v1/versioning.hpp
|
||||
include/msgpack/v1/vrefbuffer.hpp
|
||||
@@ -621,20 +625,26 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/v2/adaptor/size_equal_only_decl.hpp
|
||||
include/msgpack/v2/adaptor/v4raw_decl.hpp
|
||||
include/msgpack/v2/cpp_config_decl.hpp
|
||||
include/msgpack/v2/create_object_visitor.hpp
|
||||
include/msgpack/v2/detail/cpp03_zone_decl.hpp
|
||||
include/msgpack/v2/detail/cpp11_zone_decl.hpp
|
||||
include/msgpack/v2/fbuffer_decl.hpp
|
||||
include/msgpack/v2/iterator_decl.hpp
|
||||
include/msgpack/v2/meta_decl.hpp
|
||||
include/msgpack/v2/null_visitor.hpp
|
||||
include/msgpack/v2/object.hpp
|
||||
include/msgpack/v2/object_decl.hpp
|
||||
include/msgpack/v2/object_fwd.hpp
|
||||
include/msgpack/v2/object_fwd_decl.hpp
|
||||
include/msgpack/v2/pack_decl.hpp
|
||||
include/msgpack/v2/parse.hpp
|
||||
include/msgpack/v2/parse_return.hpp
|
||||
include/msgpack/v2/sbuffer_decl.hpp
|
||||
include/msgpack/v2/unpack.hpp
|
||||
include/msgpack/v2/unpack_decl.hpp
|
||||
include/msgpack/v2/vrefbuffer_decl.hpp
|
||||
include/msgpack/v2/x3_parse.hpp
|
||||
include/msgpack/v2/x3_unpack.hpp
|
||||
include/msgpack/v2/zbuffer_decl.hpp
|
||||
include/msgpack/v2/zone_decl.hpp
|
||||
include/msgpack/version.hpp
|
||||
|
||||
+6
-6
@@ -33,10 +33,10 @@ build_script:
|
||||
- cmake --build . --config Release
|
||||
- cd ..
|
||||
- cd ..
|
||||
- appveyor DownloadFile http://zlib.net/zlib-1.2.9.tar.gz -FileName zlib-1.2.9.tar.gz
|
||||
- 7z x zlib-1.2.9.tar.gz > NUL
|
||||
- 7z x zlib-1.2.9.tar > NUL
|
||||
- cd zlib-1.2.9
|
||||
- appveyor DownloadFile http://zlib.net/zlib-1.2.10.tar.gz -FileName zlib-1.2.10.tar.gz
|
||||
- 7z x zlib-1.2.10.tar.gz > NUL
|
||||
- 7z x zlib-1.2.10.tar > NUL
|
||||
- cd zlib-1.2.10
|
||||
- md build
|
||||
- cd build
|
||||
- cmake -G %msvc% ..
|
||||
@@ -46,9 +46,9 @@ build_script:
|
||||
- cd ..
|
||||
- md build
|
||||
- cd build
|
||||
- cmake -G %msvc% %cpp11% %boost% -DMSGPACK_BOOST_DIR=C:\Libraries\\boost_1_60_0 -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.9\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.9 -DCMAKE_CXX_FLAGS='"/D_VARIADIC_MAX=10 /EHsc"' ..
|
||||
- cmake -G %msvc% %cpp11% %boost% %x3_parse% -DMSGPACK_BOOST_DIR=C:\Libraries\\boost_1_60_0 -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.10\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.10 -DCMAKE_CXX_FLAGS='"/D_VARIADIC_MAX=10 /EHsc"' ..
|
||||
- cmake --build . --config Release
|
||||
|
||||
test_script:
|
||||
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.9\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release
|
||||
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.10\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release
|
||||
- ctest -V
|
||||
|
||||
+5
-33
@@ -16,42 +16,14 @@ then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
if [ $1 = "cpp11" ]
|
||||
if [ "${ARCH}" == "32" ]
|
||||
then
|
||||
cpp11="-DMSGPACK_CXX11=ON"
|
||||
export BIT32="ON"
|
||||
else
|
||||
cpp11=""
|
||||
export BIT32="OFF"
|
||||
fi
|
||||
|
||||
if [ $2 = "32" ]
|
||||
then
|
||||
bit32="-DMSGPACK_32BIT=ON"
|
||||
else
|
||||
bit32=""
|
||||
fi
|
||||
|
||||
if [ $3 = "boost" ]
|
||||
then
|
||||
boost="-DMSGPACK_BOOST=ON"
|
||||
else
|
||||
boost=""
|
||||
fi
|
||||
|
||||
if [ "$4" != "" ]
|
||||
then
|
||||
boost_dir="-DMSGPACK_BOOST_DIR=$4"
|
||||
else
|
||||
boost_dir=""
|
||||
fi
|
||||
|
||||
if [ "$5" = "OFF" ]
|
||||
then
|
||||
shared="-DMSGPACK_ENABLE_SHARED=OFF"
|
||||
else
|
||||
shared=""
|
||||
fi
|
||||
|
||||
cmake $cpp11 $bit32 $boost $boost_dir $shared -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DMSGPACK_DEFAULT_API_VERSION=${API_VERSION} ..
|
||||
cmake -DMSGPACK_CXX11=${CXX11} -DMSGPACK_32BIT=${BIT32} -DMSGPACK_BOOST=${BOOST} -DMSGPACK_ENABLE_SHARED=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DMSGPACK_DEFAULT_API_VERSION=${API_VERSION} -DMSGPACK_USE_X3_PARSE=${X3_PARSE} ..
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
@@ -83,7 +55,7 @@ then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
if [ "$2" != "32" ] && [ `uname` = "Linux" ]
|
||||
if [ "${ARCH}" != "32" ] && [ `uname` = "Linux" ]
|
||||
then
|
||||
ctest -T memcheck | tee memcheck.log
|
||||
|
||||
|
||||
@@ -2,3 +2,4 @@ ADD_SUBDIRECTORY (c)
|
||||
ADD_SUBDIRECTORY (cpp03)
|
||||
ADD_SUBDIRECTORY (cpp11)
|
||||
ADD_SUBDIRECTORY (boost)
|
||||
ADD_SUBDIRECTORY (x3)
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
INCLUDE_DIRECTORIES (
|
||||
../include
|
||||
)
|
||||
IF (MSGPACK_ENABLE_SHARED)
|
||||
SET (MSGPACK_LIB msgpackc)
|
||||
ELSE ()
|
||||
SET (MSGPACK_LIB msgpackc-static)
|
||||
ENDIF ()
|
||||
|
||||
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
lib_buffer_unpack.c
|
||||
@@ -17,7 +20,7 @@ FOREACH (source_file ${exec_PROGRAMS})
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
msgpackc
|
||||
${MSGPACK_LIB}
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -g -O3")
|
||||
|
||||
@@ -22,13 +22,11 @@ IF (NOT MSVC)
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_BOOST)
|
||||
IF (NOT MSVC)
|
||||
LIST (APPEND with_boost_lib_PROGRAMS
|
||||
speed_test.cpp
|
||||
speed_test_nested_array.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
IF (Boost_TIMER_LIBRARY AND Boost_CHRONO_LIBRARY AND Boost_SYSTEM_LIBRARY)
|
||||
LIST (APPEND with_boost_lib_PROGRAMS
|
||||
speed_test.cpp
|
||||
speed_test_nested_array.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
FOREACH (source_file ${exec_PROGRAMS})
|
||||
@@ -56,10 +54,10 @@ FOREACH (source_file ${with_pthread_PROGRAMS})
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
pthread
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -g -O3 -pthread")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -g -O3")
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
|
||||
@@ -6,9 +6,14 @@ IF (MSGPACK_CXX11)
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
container.cpp
|
||||
non_def_con_class.cpp
|
||||
socket_stream_example.cpp
|
||||
)
|
||||
|
||||
IF ("${MSGPACK_DEFAULT_API_VERSION}" GREATER "1")
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
socket_stream_example.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
FOREACH (source_file ${exec_PROGRAMS})
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
IF (MSGPACK_USE_X3_PARSE)
|
||||
INCLUDE_DIRECTORIES (
|
||||
../include
|
||||
)
|
||||
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
unpack.cpp
|
||||
parse.cpp
|
||||
)
|
||||
IF (Boost_CONTEXT_LIBRARY AND Boost_SYSTEM_LIBRARY AND CMAKE_THREAD_LIBS_INIT)
|
||||
LIST (APPEND with_boost_PROGRAMS
|
||||
stream_unpack.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
FOREACH (source_file ${exec_PROGRAMS})
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -g ")
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDFOREACH ()
|
||||
FOREACH (source_file ${with_boost_PROGRAMS})
|
||||
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
|
||||
ADD_EXECUTABLE (
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
${Boost_CONTEXT_LIBRARY}
|
||||
${Boost_SYSTEM_LIBRARY}
|
||||
${CMAKE_THREAD_LIBS_INIT}
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Werror -g ")
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
ENDFOREACH ()
|
||||
ENDIF ()
|
||||
@@ -0,0 +1,119 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
// MSGPACK_USE_X3_PARSE should be defined before including msgpack.hpp
|
||||
// It usually defined as a compiler option as -DMSGPACK_USE_X3_PARSE.
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
struct json_like_visitor : msgpack::v2::null_visitor {
|
||||
json_like_visitor(std::string& s):m_s(s) {}
|
||||
|
||||
bool visit_nil() {
|
||||
m_s += "null";
|
||||
return true;
|
||||
}
|
||||
bool visit_boolean(bool v) {
|
||||
if (v) m_s += "true";
|
||||
else m_s += "false";
|
||||
return true;
|
||||
}
|
||||
bool visit_positive_integer(uint64_t v) {
|
||||
std::stringstream ss;
|
||||
ss << v;
|
||||
m_s += ss.str();
|
||||
return true;
|
||||
}
|
||||
bool visit_negative_integer(int64_t v) {
|
||||
std::stringstream ss;
|
||||
ss << v;
|
||||
m_s += ss.str();
|
||||
return true;
|
||||
}
|
||||
bool visit_float(double v) {
|
||||
std::stringstream ss;
|
||||
ss << v;
|
||||
m_s += ss.str();
|
||||
return true;
|
||||
}
|
||||
bool visit_str(const char* v, uint32_t size) {
|
||||
m_s += '"' + std::string(v, size) + '"';
|
||||
return true;
|
||||
}
|
||||
bool start_array(uint32_t /*num_elements*/) {
|
||||
m_s += "[";
|
||||
return true;
|
||||
}
|
||||
bool end_array_item() {
|
||||
m_s += ",";
|
||||
return true;
|
||||
}
|
||||
bool end_array() {
|
||||
m_s.erase(m_s.size() - 1, 1); // remove the last ','
|
||||
m_s += "]";
|
||||
return true;
|
||||
}
|
||||
bool start_map(uint32_t /*num_kv_pairs*/) {
|
||||
m_s += "{";
|
||||
return true;
|
||||
}
|
||||
bool end_map_key() {
|
||||
m_s += ":";
|
||||
return true;
|
||||
}
|
||||
bool end_map_value() {
|
||||
m_s += ",";
|
||||
return true;
|
||||
}
|
||||
bool end_map() {
|
||||
m_s.erase(m_s.size() - 1, 1); // remove the last ','
|
||||
m_s += "}";
|
||||
return true;
|
||||
}
|
||||
void parse_error(size_t /*parsed_offset*/, size_t /*error_offset*/) {
|
||||
}
|
||||
void insufficient_bytes(size_t /*parsed_offset*/, size_t /*error_offset*/) {
|
||||
}
|
||||
std::string& m_s;
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::stringstream ss;
|
||||
std::map<std::string, std::vector<int>> v1 {
|
||||
{ "ABC", { 1, 2, 3 } },
|
||||
{ "DEFG", { 4, 5 } }
|
||||
};
|
||||
std::vector<std::string> v2 {
|
||||
"HIJ", "KLM", "NOP"
|
||||
};
|
||||
msgpack::pack(ss, v1);
|
||||
msgpack::pack(ss, v2);
|
||||
|
||||
std::string const& buf = ss.str();
|
||||
auto it = buf.begin();
|
||||
auto end = buf.end();
|
||||
{
|
||||
std::string str;
|
||||
bool ret = msgpack::parse(it, end, json_like_visitor(str));
|
||||
// it is updated here.
|
||||
assert(ret);
|
||||
std::cout << str << std::endl;
|
||||
}
|
||||
{
|
||||
std::string str;
|
||||
bool ret = msgpack::parse(it, end, json_like_visitor(str));
|
||||
// it is updated here.
|
||||
assert(ret);
|
||||
std::cout << str << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,239 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
#include <thread>
|
||||
|
||||
// MSGPACK_USE_X3_PARSE should be defined before including msgpack.hpp
|
||||
// It usually defined as a compiler option as -DMSGPACK_USE_X3_PARSE.
|
||||
|
||||
//#define MSGPACK_USE_X3_PARSE
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
#include <boost/asio.hpp>
|
||||
#include <boost/coroutine2/all.hpp>
|
||||
#include <boost/spirit/home/support/multi_pass.hpp>
|
||||
|
||||
|
||||
namespace as = boost::asio;
|
||||
namespace x3 = boost::spirit::x3;
|
||||
namespace coro2 = boost::coroutines2;
|
||||
|
||||
using pull_type = coro2::asymmetric_coroutine<std::shared_ptr<std::vector<char>>>::pull_type;
|
||||
|
||||
// iterator fetching data from coroutine2.
|
||||
class buffered_iterator : public std::iterator<std::input_iterator_tag, char> {
|
||||
public:
|
||||
using pointer_t = typename iterator::pointer;
|
||||
using reference_t = typename iterator::reference;
|
||||
|
||||
explicit buffered_iterator(pull_type& source) noexcept
|
||||
: source_{ &source } {
|
||||
fetch_();
|
||||
}
|
||||
buffered_iterator() = default;
|
||||
|
||||
bool operator==(buffered_iterator const& other) const noexcept {
|
||||
if (!other.source_ && !source_ && !other.buf_ && !buf_) return true;
|
||||
return other.it_ == it_;
|
||||
}
|
||||
|
||||
bool operator!=(buffered_iterator const& other) const noexcept {
|
||||
return !(other == *this);
|
||||
}
|
||||
|
||||
buffered_iterator & operator++() {
|
||||
increment_();
|
||||
return * this;
|
||||
}
|
||||
|
||||
buffered_iterator operator++(int) = delete;
|
||||
|
||||
reference_t operator*() noexcept {
|
||||
return *it_;
|
||||
}
|
||||
|
||||
pointer_t operator->() noexcept {
|
||||
return std::addressof(*it_);
|
||||
}
|
||||
|
||||
private:
|
||||
void fetch_() noexcept {
|
||||
BOOST_ASSERT( nullptr != source_);
|
||||
if (*source_) {
|
||||
buf_ = source_->get();
|
||||
it_ = buf_->begin();
|
||||
}
|
||||
else {
|
||||
source_ = nullptr;
|
||||
buf_.reset();
|
||||
}
|
||||
}
|
||||
|
||||
void increment_() {
|
||||
BOOST_ASSERT( nullptr != source_);
|
||||
BOOST_ASSERT(*source_);
|
||||
if (++it_ == buf_->end()) {
|
||||
(*source_)();
|
||||
fetch_();
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
pull_type* source_{ nullptr };
|
||||
std::shared_ptr<std::vector<char>> buf_;
|
||||
std::vector<char>::iterator it_;
|
||||
};
|
||||
|
||||
// session class that corresponding to each client
|
||||
class session : public std::enable_shared_from_this<session> {
|
||||
public:
|
||||
session(as::ip::tcp::socket socket)
|
||||
: socket_(std::move(socket)) {
|
||||
}
|
||||
|
||||
void start() {
|
||||
sink_ = std::make_shared<coro2::asymmetric_coroutine<std::shared_ptr<std::vector<char>>>::push_type>(
|
||||
[&, this](pull_type& source) {
|
||||
// *1 is started when the first sink is called.
|
||||
|
||||
std::cout << "session started" << std::endl;
|
||||
do_read();
|
||||
source();
|
||||
|
||||
// use buffered_iterator here
|
||||
// b is incremented in msgpack::unpack() and fetch data from sink
|
||||
// via coroutine2 mechanism
|
||||
auto b = boost::spirit::make_default_multi_pass(buffered_iterator(source));
|
||||
auto e = boost::spirit::make_default_multi_pass(buffered_iterator());
|
||||
|
||||
// This is usually an infinity look, but for test, loop is finished when
|
||||
// two message pack data is processed.
|
||||
for (int i = 0; i != 2; ++i) {
|
||||
auto oh = msgpack::unpack(b, e);
|
||||
std::cout << oh.get() << std::endl;
|
||||
}
|
||||
}
|
||||
);
|
||||
// send dummy data to start *1
|
||||
(*sink_)({});
|
||||
}
|
||||
|
||||
private:
|
||||
void do_read() {
|
||||
std::cout << "session do_read() is called" << std::endl;
|
||||
auto self(shared_from_this());
|
||||
auto data = std::make_shared<std::vector<char>>(static_cast<std::size_t>(max_length));
|
||||
socket_.async_read_some(
|
||||
boost::asio::buffer(*data),
|
||||
[this, self, data]
|
||||
(boost::system::error_code ec, std::size_t length) {
|
||||
if (!ec) {
|
||||
data->resize(length);
|
||||
(*sink_)(data);
|
||||
do_read();
|
||||
}
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
as::ip::tcp::socket socket_;
|
||||
static constexpr std::size_t const max_length = 1024;
|
||||
std::shared_ptr<coro2::asymmetric_coroutine<std::shared_ptr<std::vector<char>>>::push_type> sink_;
|
||||
};
|
||||
|
||||
class server {
|
||||
public:
|
||||
server(
|
||||
as::io_service& ios,
|
||||
std::uint16_t port)
|
||||
: acceptor_(ios, as::ip::tcp::endpoint(as::ip::tcp::v4(), port)),
|
||||
socket_(ios) {
|
||||
do_accept();
|
||||
std::cout << "server start accept" << std::endl;
|
||||
ios.run();
|
||||
}
|
||||
|
||||
private:
|
||||
void do_accept() {
|
||||
acceptor_.async_accept(
|
||||
socket_,
|
||||
[this](boost::system::error_code ec) {
|
||||
if (!ec) {
|
||||
std::make_shared<session>(std::move(socket_))->start();
|
||||
}
|
||||
// for test, only one session is accepted.
|
||||
// do_accept();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
as::ip::tcp::acceptor acceptor_;
|
||||
as::ip::tcp::socket socket_;
|
||||
};
|
||||
|
||||
int main() {
|
||||
std::thread srv(
|
||||
[]{
|
||||
boost::asio::io_service ios;
|
||||
server s(ios, 12345);
|
||||
}
|
||||
);
|
||||
|
||||
std::thread cli(
|
||||
[]{
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
std::cout << "client start" << std::endl;
|
||||
|
||||
std::stringstream ss;
|
||||
std::map<std::string, std::vector<int>> v1 {
|
||||
{ "ABC", { 1, 2, 3 } },
|
||||
{ "DEFG", { 4, 5 } }
|
||||
};
|
||||
std::vector<std::string> v2 {
|
||||
"HIJ", "KLM", "NOP"
|
||||
};
|
||||
msgpack::pack(ss, v1);
|
||||
msgpack::pack(ss, v2);
|
||||
|
||||
auto send_data = ss.str();
|
||||
|
||||
boost::asio::io_service ios;
|
||||
as::ip::tcp::resolver::query q("127.0.0.1", "12345");
|
||||
as::ip::tcp::resolver r(ios);
|
||||
auto it = r.resolve(q);
|
||||
|
||||
std::cout << "client connect" << std::endl;
|
||||
as::ip::tcp::socket s(ios);
|
||||
as::connect(s, it);
|
||||
|
||||
|
||||
std::size_t const size = 5;
|
||||
std::size_t rest = send_data.size();
|
||||
std::size_t index = 0;
|
||||
while (rest != 0) {
|
||||
std::cout << "client send data" << std::endl;
|
||||
auto send_size = size < rest ? size : rest;
|
||||
as::write(s, as::buffer(&send_data[index], send_size));
|
||||
rest -= send_size;
|
||||
index += send_size;
|
||||
std::cout << "client wait" << std::endl;
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
cli.join();
|
||||
std::cout << "client joinded" << std::endl;
|
||||
srv.join();
|
||||
std::cout << "server joinded" << std::endl;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
// MSGPACK_USE_X3_PARSE should be defined before including msgpack.hpp
|
||||
// It usually defined as a compiler option as -DMSGPACK_USE_X3_PARSE.
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
int main() {
|
||||
std::stringstream ss;
|
||||
std::map<std::string, std::vector<int>> v1 {
|
||||
{ "ABC", { 1, 2, 3 } },
|
||||
{ "DEFG", { 4, 5 } }
|
||||
};
|
||||
std::vector<std::string> v2 {
|
||||
"HIJ", "KLM", "NOP"
|
||||
};
|
||||
msgpack::pack(ss, v1);
|
||||
msgpack::pack(ss, v2);
|
||||
|
||||
std::string const& buf = ss.str();
|
||||
auto it = buf.begin();
|
||||
auto end = buf.end();
|
||||
{
|
||||
auto oh = msgpack::unpack(it, end);
|
||||
// it is updated here.
|
||||
assert(v1 == (oh.get().as<std::map<std::string, std::vector<int>>>()));
|
||||
}
|
||||
{
|
||||
auto oh = msgpack::unpack(it, end);
|
||||
assert(v2 == oh.get().as<std::vector<std::string>>());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_PARSE_RETURN_HPP
|
||||
#define MSGPACK_PARSE_RETURN_HPP
|
||||
|
||||
#include "msgpack/v1/parse_return.hpp"
|
||||
#include "msgpack/v2/parse_return.hpp"
|
||||
|
||||
#endif // MSGPACK_PARSE_RETURN_HPP
|
||||
@@ -14,5 +14,6 @@
|
||||
|
||||
#include "msgpack/v1/unpack.hpp"
|
||||
#include "msgpack/v2/unpack.hpp"
|
||||
#include "msgpack/v2/x3_unpack.hpp"
|
||||
|
||||
#endif // MSGPACK_UNPACK_HPP
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_UNPACK_EXCEPTION_HPP
|
||||
#define MSGPACK_UNPACK_EXCEPTION_HPP
|
||||
|
||||
#include "msgpack/v1/unpack_exception.hpp"
|
||||
|
||||
#endif // MSGPACK_UNPACK_EXCEPTION_HPP
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_V1_PARSE_RETURN_HPP
|
||||
#define MSGPACK_V1_PARSE_RETURN_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
|
||||
// for internal use
|
||||
typedef enum {
|
||||
PARSE_SUCCESS = 2,
|
||||
PARSE_EXTRA_BYTES = 1,
|
||||
PARSE_CONTINUE = 0,
|
||||
PARSE_PARSE_ERROR = -1
|
||||
} parse_return;
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_PARSE_RETURN_HPP
|
||||
+22
-112
@@ -14,12 +14,12 @@
|
||||
#include "msgpack/unpack_decl.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/zone.hpp"
|
||||
#include "msgpack/unpack_exception.hpp"
|
||||
#include "msgpack/unpack_define.h"
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
#include "msgpack/sysdep.h"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
#include <atomic>
|
||||
@@ -39,96 +39,6 @@ namespace msgpack {
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
struct unpack_error : public std::runtime_error {
|
||||
explicit unpack_error(const std::string& msg)
|
||||
:std::runtime_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit unpack_error(const char* msg):
|
||||
std::runtime_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
struct parse_error : public unpack_error {
|
||||
explicit parse_error(const std::string& msg)
|
||||
:unpack_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit parse_error(const char* msg)
|
||||
:unpack_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
struct insufficient_bytes : public unpack_error {
|
||||
explicit insufficient_bytes(const std::string& msg)
|
||||
:unpack_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit insufficient_bytes(const char* msg)
|
||||
:unpack_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
struct size_overflow : public unpack_error {
|
||||
explicit size_overflow(const std::string& msg)
|
||||
:unpack_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit size_overflow(const char* msg)
|
||||
:unpack_error(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct array_size_overflow : public size_overflow {
|
||||
array_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
array_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct map_size_overflow : public size_overflow {
|
||||
map_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
map_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct str_size_overflow : public size_overflow {
|
||||
str_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
str_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct bin_size_overflow : public size_overflow {
|
||||
bin_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
bin_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct ext_size_overflow : public size_overflow {
|
||||
ext_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
ext_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct depth_size_overflow : public size_overflow {
|
||||
depth_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
depth_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
class unpack_user {
|
||||
@@ -1425,7 +1335,7 @@ inline void unpacker::remove_nonparsed_buffer()
|
||||
|
||||
namespace detail {
|
||||
|
||||
inline unpack_return
|
||||
inline parse_return
|
||||
unpack_imp(const char* data, std::size_t len, std::size_t& off,
|
||||
msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
|
||||
unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR,
|
||||
@@ -1435,7 +1345,7 @@ unpack_imp(const char* data, std::size_t len, std::size_t& off,
|
||||
|
||||
if(len <= noff) {
|
||||
// FIXME
|
||||
return UNPACK_CONTINUE;
|
||||
return PARSE_CONTINUE;
|
||||
}
|
||||
|
||||
detail::context ctx(f, user_data, limit);
|
||||
@@ -1447,23 +1357,23 @@ unpack_imp(const char* data, std::size_t len, std::size_t& off,
|
||||
|
||||
int e = ctx.execute(data, len, noff);
|
||||
if(e < 0) {
|
||||
return UNPACK_PARSE_ERROR;
|
||||
return PARSE_PARSE_ERROR;
|
||||
}
|
||||
|
||||
referenced = ctx.user().referenced();
|
||||
off = noff;
|
||||
|
||||
if(e == 0) {
|
||||
return UNPACK_CONTINUE;
|
||||
return PARSE_CONTINUE;
|
||||
}
|
||||
|
||||
result = ctx.data();
|
||||
|
||||
if(noff < len) {
|
||||
return UNPACK_EXTRA_BYTES;
|
||||
return PARSE_EXTRA_BYTES;
|
||||
}
|
||||
|
||||
return UNPACK_SUCCESS;
|
||||
return PARSE_SUCCESS;
|
||||
}
|
||||
|
||||
} // detail
|
||||
@@ -1480,19 +1390,19 @@ inline msgpack::object_handle unpack(
|
||||
msgpack::unique_ptr<msgpack::zone> z(new msgpack::zone);
|
||||
referenced = false;
|
||||
std::size_t noff = off;
|
||||
unpack_return ret = detail::unpack_imp(
|
||||
parse_return ret = detail::unpack_imp(
|
||||
data, len, noff, *z, obj, referenced, f, user_data, limit);
|
||||
|
||||
switch(ret) {
|
||||
case UNPACK_SUCCESS:
|
||||
case PARSE_SUCCESS:
|
||||
off = noff;
|
||||
return msgpack::object_handle(obj, msgpack::move(z));
|
||||
case UNPACK_EXTRA_BYTES:
|
||||
case PARSE_EXTRA_BYTES:
|
||||
off = noff;
|
||||
return msgpack::object_handle(obj, msgpack::move(z));
|
||||
case UNPACK_CONTINUE:
|
||||
case PARSE_CONTINUE:
|
||||
throw msgpack::insufficient_bytes("insufficient bytes");
|
||||
case UNPACK_PARSE_ERROR:
|
||||
case PARSE_PARSE_ERROR:
|
||||
default:
|
||||
throw msgpack::parse_error("parse error");
|
||||
}
|
||||
@@ -1537,23 +1447,23 @@ inline void unpack(
|
||||
msgpack::unique_ptr<msgpack::zone> z(new msgpack::zone);
|
||||
referenced = false;
|
||||
std::size_t noff = off;
|
||||
unpack_return ret = detail::unpack_imp(
|
||||
parse_return ret = detail::unpack_imp(
|
||||
data, len, noff, *z, obj, referenced, f, user_data, limit);
|
||||
|
||||
switch(ret) {
|
||||
case UNPACK_SUCCESS:
|
||||
case PARSE_SUCCESS:
|
||||
off = noff;
|
||||
result.set(obj);
|
||||
result.zone() = msgpack::move(z);
|
||||
return;
|
||||
case UNPACK_EXTRA_BYTES:
|
||||
case PARSE_EXTRA_BYTES:
|
||||
off = noff;
|
||||
result.set(obj);
|
||||
result.zone() = msgpack::move(z);
|
||||
return;
|
||||
case UNPACK_CONTINUE:
|
||||
case PARSE_CONTINUE:
|
||||
throw msgpack::insufficient_bytes("insufficient bytes");
|
||||
case UNPACK_PARSE_ERROR:
|
||||
case PARSE_PARSE_ERROR:
|
||||
default:
|
||||
throw msgpack::parse_error("parse error");
|
||||
}
|
||||
@@ -1600,19 +1510,19 @@ inline msgpack::object unpack(
|
||||
msgpack::object obj;
|
||||
std::size_t noff = off;
|
||||
referenced = false;
|
||||
unpack_return ret = detail::unpack_imp(
|
||||
parse_return ret = detail::unpack_imp(
|
||||
data, len, noff, z, obj, referenced, f, user_data, limit);
|
||||
|
||||
switch(ret) {
|
||||
case UNPACK_SUCCESS:
|
||||
case PARSE_SUCCESS:
|
||||
off = noff;
|
||||
return obj;
|
||||
case UNPACK_EXTRA_BYTES:
|
||||
case PARSE_EXTRA_BYTES:
|
||||
off = noff;
|
||||
return obj;
|
||||
case UNPACK_CONTINUE:
|
||||
case PARSE_CONTINUE:
|
||||
throw msgpack::insufficient_bytes("insufficient bytes");
|
||||
case UNPACK_PARSE_ERROR:
|
||||
case PARSE_PARSE_ERROR:
|
||||
default:
|
||||
throw msgpack::parse_error("parse error");
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
#include "msgpack/zone.hpp"
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
#include "msgpack/sysdep.h"
|
||||
#include "msgpack/parse_return.hpp"
|
||||
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
@@ -433,17 +434,9 @@ void unpack(
|
||||
unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR, unpack_limit const& limit = unpack_limit());
|
||||
|
||||
|
||||
// for internal use
|
||||
typedef enum {
|
||||
UNPACK_SUCCESS = 2,
|
||||
UNPACK_EXTRA_BYTES = 1,
|
||||
UNPACK_CONTINUE = 0,
|
||||
UNPACK_PARSE_ERROR = -1
|
||||
} unpack_return;
|
||||
|
||||
namespace detail {
|
||||
|
||||
unpack_return
|
||||
parse_return
|
||||
unpack_imp(const char* data, std::size_t len, std::size_t& off,
|
||||
msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
|
||||
unpack_reference_func f, void* user_data,
|
||||
|
||||
@@ -0,0 +1,122 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_V1_UNPACK_EXCEPTION_HPP
|
||||
#define MSGPACK_V1_UNPACK_EXCEPTION_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
#include <string>
|
||||
#include <stdexcept>
|
||||
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
struct unpack_error : public std::runtime_error {
|
||||
explicit unpack_error(const std::string& msg)
|
||||
:std::runtime_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit unpack_error(const char* msg):
|
||||
std::runtime_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
struct parse_error : public unpack_error {
|
||||
explicit parse_error(const std::string& msg)
|
||||
:unpack_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit parse_error(const char* msg)
|
||||
:unpack_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
struct insufficient_bytes : public unpack_error {
|
||||
explicit insufficient_bytes(const std::string& msg)
|
||||
:unpack_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit insufficient_bytes(const char* msg)
|
||||
:unpack_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
struct size_overflow : public unpack_error {
|
||||
explicit size_overflow(const std::string& msg)
|
||||
:unpack_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit size_overflow(const char* msg)
|
||||
:unpack_error(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct array_size_overflow : public size_overflow {
|
||||
array_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
array_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct map_size_overflow : public size_overflow {
|
||||
map_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
map_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct str_size_overflow : public size_overflow {
|
||||
str_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
str_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct bin_size_overflow : public size_overflow {
|
||||
bin_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
bin_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct ext_size_overflow : public size_overflow {
|
||||
ext_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
ext_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
struct depth_size_overflow : public size_overflow {
|
||||
depth_size_overflow(const std::string& msg)
|
||||
:size_overflow(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
depth_size_overflow(const char* msg)
|
||||
:size_overflow(msg) {}
|
||||
#endif
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_V1_UNPACK_EXCEPTION_HPP
|
||||
@@ -0,0 +1,243 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
|
||||
#define MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
|
||||
|
||||
#include "msgpack/unpack_decl.hpp"
|
||||
#include "msgpack/unpack_exception.hpp"
|
||||
#include "msgpack/v2/null_visitor.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v2) {
|
||||
/// @endcond
|
||||
|
||||
namespace detail {
|
||||
|
||||
class create_object_visitor : public msgpack::v2::null_visitor {
|
||||
public:
|
||||
create_object_visitor(unpack_reference_func f, void* user_data, unpack_limit const& limit)
|
||||
:m_func(f), m_user_data(user_data), m_limit(limit) {
|
||||
m_stack.reserve(MSGPACK_EMBED_STACK_SIZE);
|
||||
m_stack.push_back(&m_obj);
|
||||
}
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
create_object_visitor(create_object_visitor&& other)
|
||||
:m_func(other.m_func),
|
||||
m_user_data(other.m_user_data),
|
||||
m_limit(std::move(other.m_limit)),
|
||||
m_stack(std::move(other.m_stack)),
|
||||
m_zone(other.m_zone),
|
||||
m_referenced(other.m_referenced) {
|
||||
other.m_zone = MSGPACK_NULLPTR;
|
||||
m_stack[0] = &m_obj;
|
||||
}
|
||||
create_object_visitor& operator=(create_object_visitor&& other) {
|
||||
this->~create_object_visitor();
|
||||
new (this) create_object_visitor(std::move(other));
|
||||
return *this;
|
||||
}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
void init() {
|
||||
m_stack.resize(1);
|
||||
m_obj = msgpack::object();
|
||||
m_stack[0] = &m_obj;
|
||||
}
|
||||
msgpack::object const& data() const
|
||||
{
|
||||
return m_obj;
|
||||
}
|
||||
msgpack::zone const& zone() const { return *m_zone; }
|
||||
msgpack::zone& zone() { return *m_zone; }
|
||||
void set_zone(msgpack::zone& zone) { m_zone = &zone; }
|
||||
bool referenced() const { return m_referenced; }
|
||||
void set_referenced(bool referenced) { m_referenced = referenced; }
|
||||
// visit functions
|
||||
bool visit_nil() {
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::NIL;
|
||||
return true;
|
||||
}
|
||||
bool visit_boolean(bool v) {
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::BOOLEAN;
|
||||
obj->via.boolean = v;
|
||||
return true;
|
||||
}
|
||||
bool visit_positive_integer(uint64_t v) {
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::POSITIVE_INTEGER;
|
||||
obj->via.u64 = v;
|
||||
return true;
|
||||
}
|
||||
bool visit_negative_integer(int64_t v) {
|
||||
msgpack::object* obj = m_stack.back();
|
||||
if(v >= 0) {
|
||||
obj->type = msgpack::type::POSITIVE_INTEGER;
|
||||
obj->via.u64 = v;
|
||||
}
|
||||
else {
|
||||
obj->type = msgpack::type::NEGATIVE_INTEGER;
|
||||
obj->via.i64 = v;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
bool visit_float(double v) {
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::FLOAT;
|
||||
obj->via.f64 = v;
|
||||
return true;
|
||||
}
|
||||
bool visit_str(const char* v, uint32_t size) {
|
||||
if (size > m_limit.str()) throw msgpack::str_size_overflow("str size overflow");
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::STR;
|
||||
if (m_func && m_func(obj->type, size, m_user_data)) {
|
||||
obj->via.str.ptr = v;
|
||||
set_referenced(true);
|
||||
}
|
||||
else {
|
||||
char* tmp = static_cast<char*>(zone().allocate_align(size));
|
||||
std::memcpy(tmp, v, size);
|
||||
obj->via.str.ptr = tmp;
|
||||
}
|
||||
obj->via.str.size = size;
|
||||
return true;
|
||||
}
|
||||
bool visit_bin(const char* v, uint32_t size) {
|
||||
if (size > m_limit.bin()) throw msgpack::bin_size_overflow("bin size overflow");
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::BIN;
|
||||
if (m_func && m_func(obj->type, size, m_user_data)) {
|
||||
obj->via.bin.ptr = v;
|
||||
set_referenced(true);
|
||||
}
|
||||
else {
|
||||
char* tmp = static_cast<char*>(zone().allocate_align(size));
|
||||
std::memcpy(tmp, v, size);
|
||||
obj->via.bin.ptr = tmp;
|
||||
}
|
||||
obj->via.bin.size = size;
|
||||
return true;
|
||||
}
|
||||
bool visit_ext(const char* v, uint32_t size) {
|
||||
if (size > m_limit.ext()) throw msgpack::ext_size_overflow("ext size overflow");
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::EXT;
|
||||
if (m_func && m_func(obj->type, size, m_user_data)) {
|
||||
obj->via.ext.ptr = v;
|
||||
set_referenced(true);
|
||||
}
|
||||
else {
|
||||
char* tmp = static_cast<char*>(zone().allocate_align(size));
|
||||
std::memcpy(tmp, v, size);
|
||||
obj->via.ext.ptr = tmp;
|
||||
}
|
||||
obj->via.ext.size = static_cast<uint32_t>(size - 1);
|
||||
return true;
|
||||
}
|
||||
bool start_array(uint32_t num_elements) {
|
||||
if (num_elements > m_limit.array()) throw msgpack::array_size_overflow("array size overflow");
|
||||
if (m_stack.size() > m_limit.depth()) throw msgpack::depth_size_overflow("depth size overflow");
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::ARRAY;
|
||||
obj->via.array.size = num_elements;
|
||||
if (num_elements == 0) {
|
||||
obj->via.array.ptr = MSGPACK_NULLPTR;
|
||||
}
|
||||
else {
|
||||
size_t size = num_elements*sizeof(msgpack::object);
|
||||
if (size / sizeof(msgpack::object) != num_elements) {
|
||||
throw msgpack::array_size_overflow("array size overflow");
|
||||
}
|
||||
obj->via.array.ptr =
|
||||
static_cast<msgpack::object*>(m_zone->allocate_align(size));
|
||||
}
|
||||
m_stack.push_back(obj->via.array.ptr);
|
||||
return true;
|
||||
}
|
||||
bool start_array_item() {
|
||||
return true;
|
||||
}
|
||||
bool end_array_item() {
|
||||
++m_stack.back();
|
||||
return true;
|
||||
}
|
||||
bool end_array() {
|
||||
m_stack.pop_back();
|
||||
return true;
|
||||
}
|
||||
bool start_map(uint32_t num_kv_pairs) {
|
||||
if (num_kv_pairs > m_limit.map()) throw msgpack::map_size_overflow("map size overflow");
|
||||
if (m_stack.size() > m_limit.depth()) throw msgpack::depth_size_overflow("depth size overflow");
|
||||
msgpack::object* obj = m_stack.back();
|
||||
obj->type = msgpack::type::MAP;
|
||||
obj->via.map.size = num_kv_pairs;
|
||||
if (num_kv_pairs == 0) {
|
||||
obj->via.map.ptr = MSGPACK_NULLPTR;
|
||||
}
|
||||
else {
|
||||
size_t size = num_kv_pairs*sizeof(msgpack::object_kv);
|
||||
if (size / sizeof(msgpack::object_kv) != num_kv_pairs) {
|
||||
throw msgpack::map_size_overflow("map size overflow");
|
||||
}
|
||||
obj->via.map.ptr =
|
||||
static_cast<msgpack::object_kv*>(m_zone->allocate_align(size));
|
||||
}
|
||||
m_stack.push_back(reinterpret_cast<msgpack::object*>(obj->via.map.ptr));
|
||||
return true;
|
||||
}
|
||||
bool start_map_key() {
|
||||
return true;
|
||||
}
|
||||
bool end_map_key() {
|
||||
++m_stack.back();
|
||||
return true;
|
||||
}
|
||||
bool start_map_value() {
|
||||
return true;
|
||||
}
|
||||
bool end_map_value() {
|
||||
++m_stack.back();
|
||||
return true;
|
||||
}
|
||||
bool end_map() {
|
||||
m_stack.pop_back();
|
||||
return true;
|
||||
}
|
||||
void parse_error(size_t /*parsed_offset*/, size_t /*error_offset*/) {
|
||||
throw msgpack::parse_error("parse error");
|
||||
}
|
||||
void insufficient_bytes(size_t /*parsed_offset*/, size_t /*error_offset*/) {
|
||||
throw msgpack::insufficient_bytes("insufficient bytes");
|
||||
}
|
||||
private:
|
||||
public:
|
||||
unpack_reference_func m_func;
|
||||
void* m_user_data;
|
||||
unpack_limit m_limit;
|
||||
msgpack::object m_obj;
|
||||
std::vector<msgpack::object*> m_stack;
|
||||
msgpack::zone* m_zone;
|
||||
bool m_referenced;
|
||||
};
|
||||
|
||||
} // detail
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v2)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V2_CREATE_OBJECT_VISITOR_HPP
|
||||
@@ -0,0 +1,94 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_V2_NULL_VISITOR_HPP
|
||||
#define MSGPACK_V2_NULL_VISITOR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v2) {
|
||||
/// @endcond
|
||||
|
||||
struct null_visitor {
|
||||
bool visit_nil() {
|
||||
return true;
|
||||
}
|
||||
bool visit_boolean(bool /*v*/) {
|
||||
return true;
|
||||
}
|
||||
bool visit_positive_integer(uint64_t /*v*/) {
|
||||
return true;
|
||||
}
|
||||
bool visit_negative_integer(int64_t /*v*/) {
|
||||
return true;
|
||||
}
|
||||
bool visit_float(double /*v*/) {
|
||||
return true;
|
||||
}
|
||||
bool visit_str(const char* /*v*/, uint32_t /*size*/) {
|
||||
return true;
|
||||
}
|
||||
bool visit_bin(const char* /*v*/, uint32_t /*size*/) {
|
||||
return true;
|
||||
}
|
||||
bool visit_ext(const char* /*v*/, uint32_t /*size*/) {
|
||||
return true;
|
||||
}
|
||||
bool start_array(uint32_t /*num_elements*/) {
|
||||
return true;
|
||||
}
|
||||
bool start_array_item() {
|
||||
return true;
|
||||
}
|
||||
bool end_array_item() {
|
||||
return true;
|
||||
}
|
||||
bool end_array() {
|
||||
return true;
|
||||
}
|
||||
bool start_map(uint32_t /*num_kv_pairs*/) {
|
||||
return true;
|
||||
}
|
||||
bool start_map_key() {
|
||||
return true;
|
||||
}
|
||||
bool end_map_key() {
|
||||
return true;
|
||||
}
|
||||
bool start_map_value() {
|
||||
return true;
|
||||
}
|
||||
bool end_map_value() {
|
||||
return true;
|
||||
}
|
||||
bool end_map() {
|
||||
return true;
|
||||
}
|
||||
void parse_error(size_t /*parsed_offset*/, size_t /*error_offset*/) {
|
||||
}
|
||||
void insufficient_bytes(size_t /*parsed_offset*/, size_t /*error_offset*/) {
|
||||
}
|
||||
bool referenced() const {
|
||||
return false;
|
||||
}
|
||||
void set_referenced(bool /*referenced*/) {
|
||||
}
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v2)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V2_NULL_VISITOR_HPP
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,37 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2008-2016 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_V2_PARSE_RETURN_HPP
|
||||
#define MSGPACK_V2_PARSE_RETURN_HPP
|
||||
|
||||
#include "msgpack/v1/parse_return.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v2) {
|
||||
/// @endcond
|
||||
|
||||
|
||||
// for internal use
|
||||
typedef enum {
|
||||
PARSE_SUCCESS = v1::PARSE_SUCCESS,
|
||||
PARSE_EXTRA_BYTES = v1::PARSE_EXTRA_BYTES,
|
||||
PARSE_CONTINUE = v1::PARSE_CONTINUE,
|
||||
PARSE_PARSE_ERROR = v1::PARSE_PARSE_ERROR,
|
||||
PARSE_STOP_VISITOR = -2
|
||||
} parse_return;
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v2)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V2_PARSE_RETURN_HPP
|
||||
+14
-1303
File diff suppressed because it is too large
Load Diff
@@ -87,14 +87,6 @@ class unpacker;
|
||||
template <typename unpack_visitor, typename referenced_buffer_hook>
|
||||
class basic_unpacker;
|
||||
|
||||
typedef enum unpack_return {
|
||||
UNPACK_SUCCESS = v1::UNPACK_SUCCESS,
|
||||
UNPACK_EXTRA_BYTES = v1::UNPACK_EXTRA_BYTES,
|
||||
UNPACK_CONTINUE = v1::UNPACK_CONTINUE,
|
||||
UNPACK_PARSE_ERROR = v1::UNPACK_PARSE_ERROR,
|
||||
UNPACK_STOP_VISITOR = -2
|
||||
} unpack_return;
|
||||
|
||||
/// Unpack msgpack::object from a buffer.
|
||||
/**
|
||||
* @param data The pointer to the buffer.
|
||||
@@ -327,14 +319,14 @@ bool parse(const char* data, size_t len, Visitor& v);
|
||||
|
||||
namespace detail {
|
||||
|
||||
unpack_return
|
||||
parse_return
|
||||
unpack_imp(const char* data, std::size_t len, std::size_t& off,
|
||||
msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
|
||||
unpack_reference_func f, void* user_data,
|
||||
unpack_limit const& limit);
|
||||
|
||||
template <typename UnpackVisitor>
|
||||
unpack_return
|
||||
parse_return
|
||||
parse_imp(const char* data, size_t len, size_t& off, UnpackVisitor& v);
|
||||
|
||||
} // detail
|
||||
|
||||
@@ -0,0 +1,874 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_V2_X3_PARSE_HPP
|
||||
#define MSGPACK_V2_X3_PARSE_HPP
|
||||
|
||||
#if defined(MSGPACK_USE_X3_PARSE)
|
||||
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#if BOOST_VERSION >= 106100
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wunused-parameter"
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#include <boost/config/warning_disable.hpp>
|
||||
#include <boost/spirit/home/x3.hpp>
|
||||
#include <boost/spirit/home/x3/binary.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v2) {
|
||||
/// @endcond
|
||||
|
||||
namespace detail {
|
||||
|
||||
namespace x3 = boost::spirit::x3;
|
||||
|
||||
using x3::byte_;
|
||||
|
||||
// byte range utility
|
||||
const auto byte_range = [](const std::uint8_t from, const std::uint8_t to) {
|
||||
const auto check = [from, to](auto& ctx)
|
||||
{
|
||||
const std::uint8_t value = x3::_attr(ctx);
|
||||
x3::_val(ctx) = value;
|
||||
x3::_pass(ctx) = from <= value && value <= to;
|
||||
};
|
||||
return x3::byte_ [check];
|
||||
};
|
||||
|
||||
// MessagePack rule
|
||||
const auto mp_positive_fixint = byte_range(0x00, 0x7f);
|
||||
const auto mp_fixmap = byte_range(0x80, 0x8f);
|
||||
const auto mp_fixarray = byte_range(0x90, 0x9f);
|
||||
const auto mp_fixstr = byte_range(0xa0, 0xbf);
|
||||
const auto mp_nil = x3::byte_(0xc0);
|
||||
const auto mp_false = x3::byte_(0xc2);
|
||||
const auto mp_true = x3::byte_(0xc3);
|
||||
const auto mp_bin8 = x3::byte_(0xc4);
|
||||
const auto mp_bin16 = x3::byte_(0xc5);
|
||||
const auto mp_bin32 = x3::byte_(0xc6);
|
||||
const auto mp_ext8 = x3::byte_(0xc7);
|
||||
const auto mp_ext16 = x3::byte_(0xc8);
|
||||
const auto mp_ext32 = x3::byte_(0xc9);
|
||||
const auto mp_float32 = x3::byte_(0xca);
|
||||
const auto mp_float64 = x3::byte_(0xcb);
|
||||
const auto mp_uint8 = x3::byte_(0xcc);
|
||||
const auto mp_uint16 = x3::byte_(0xcd);
|
||||
const auto mp_uint32 = x3::byte_(0xce);
|
||||
const auto mp_uint64 = x3::byte_(0xcf);
|
||||
const auto mp_int8 = x3::byte_(0xd0);
|
||||
const auto mp_int16 = x3::byte_(0xd1);
|
||||
const auto mp_int32 = x3::byte_(0xd2);
|
||||
const auto mp_int64 = x3::byte_(0xd3);
|
||||
const auto mp_fixext1 = x3::byte_(0xd4);
|
||||
const auto mp_fixext2 = x3::byte_(0xd5);
|
||||
const auto mp_fixext4 = x3::byte_(0xd6);
|
||||
const auto mp_fixext8 = x3::byte_(0xd7);
|
||||
const auto mp_fixext16 = x3::byte_(0xd8);
|
||||
const auto mp_str8 = x3::byte_(0xd9);
|
||||
const auto mp_str16 = x3::byte_(0xda);
|
||||
const auto mp_str32 = x3::byte_(0xdb);
|
||||
const auto mp_array16 = x3::byte_(0xdc);
|
||||
const auto mp_array32 = x3::byte_(0xdd);
|
||||
const auto mp_map16 = x3::byte_(0xde);
|
||||
const auto mp_map32 = x3::byte_(0xdf);
|
||||
const auto mp_negative_fixint = byte_range(0xe0, 0xff);
|
||||
|
||||
const auto mp_d_uint8 = x3::byte_;
|
||||
const auto mp_d_uint16 = x3::big_word;
|
||||
const auto mp_d_uint32 = x3::big_dword;
|
||||
const auto mp_d_uint64 = x3::big_qword;
|
||||
|
||||
const auto mp_d_int8 = x3::byte_;
|
||||
const auto mp_d_int16 = x3::big_word;
|
||||
const auto mp_d_int32 = x3::big_dword;
|
||||
const auto mp_d_int64 = x3::big_qword;
|
||||
|
||||
x3::rule<class mp_object> const mp_object("mp_object");
|
||||
x3::rule<class array_items> const array_item("array_item");
|
||||
x3::rule<class map_items> const map_item("map_item");
|
||||
x3::rule<class kv> const kv("kv");
|
||||
|
||||
struct tag_app_specific {};
|
||||
struct index_size {
|
||||
enum struct type_t {
|
||||
array,
|
||||
map,
|
||||
other
|
||||
};
|
||||
index_size(std::size_t size, type_t type = type_t::other):size(size), type(type) {}
|
||||
std::size_t index = 0;
|
||||
std::size_t size;
|
||||
type_t type;
|
||||
};
|
||||
|
||||
template <typename Visitor>
|
||||
struct app_specific {
|
||||
template <typename Vis>
|
||||
app_specific(Vis&& vis):vis(vis) {}
|
||||
std::vector<index_size> index_sizes;
|
||||
Visitor vis;
|
||||
};
|
||||
|
||||
template <typename Visitor>
|
||||
app_specific<Visitor> make_app_specific(Visitor&& vis) {
|
||||
return app_specific<Visitor>(std::forward<Visitor>(vis));
|
||||
}
|
||||
|
||||
const auto more = [](auto &ctx) {
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
_pass(ctx) = app_specific.index_sizes.back().index++ < app_specific.index_sizes.back().size;
|
||||
};
|
||||
|
||||
const auto done = [](auto &ctx) {
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
if (app_specific.index_sizes.back().index == app_specific.index_sizes.back().size + 1) {
|
||||
_pass(ctx) = true;
|
||||
switch (app_specific.index_sizes.back().type) {
|
||||
case index_size::type_t::array:
|
||||
app_specific.vis.end_array();
|
||||
break;
|
||||
case index_size::type_t::map:
|
||||
app_specific.vis.end_map();
|
||||
break;
|
||||
case index_size::type_t::other:
|
||||
break;
|
||||
}
|
||||
app_specific.index_sizes.pop_back();
|
||||
}
|
||||
else {
|
||||
_pass(ctx) = false;
|
||||
}
|
||||
};
|
||||
|
||||
const auto mp_object_def =
|
||||
// -----------------------------------------------
|
||||
mp_nil [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_nil();
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_true [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_boolean(true);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_false [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_boolean(false);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_positive_fixint [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_positive_integer(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_negative_fixint [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::int8_t val = _attr(ctx);
|
||||
app_specific.vis.visit_negative_integer(val);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_uint8 >> mp_d_uint8 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_negative_integer(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_uint16 >> mp_d_uint16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_positive_integer(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_uint32 >> mp_d_uint32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_positive_integer(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_uint64 >> mp_d_uint64 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.visit_positive_integer(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_int8 >> mp_d_int8 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::int8_t val = _attr(ctx);
|
||||
app_specific.vis.visit_negative_integer(val);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_int16 >> mp_d_int16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::int16_t val = _attr(ctx);
|
||||
app_specific.vis.visit_negative_integer(val);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_int32 >> mp_d_int32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::int32_t val = _attr(ctx);
|
||||
app_specific.vis.visit_negative_integer(val);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_int64 >> mp_d_int64 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::int64_t val = _attr(ctx);
|
||||
app_specific.vis.visit_negative_integer(val);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_float32 >> mp_d_uint32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
union { uint32_t i; float f; } mem;
|
||||
mem.i = _attr(ctx);
|
||||
app_specific.vis.visit_float(mem.f);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_float64 >> mp_d_uint64 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
union { uint64_t i; double f; } mem;
|
||||
mem.i = _attr(ctx);
|
||||
#if defined(TARGET_OS_IPHONE)
|
||||
// ok
|
||||
#elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
||||
// https://github.com/msgpack/msgpack-perl/pull/1
|
||||
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
||||
#endif
|
||||
app_specific.vis.visit_float(mem.f);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixstr [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::size_t size = _attr(ctx) & 0b00011111;
|
||||
app_specific.index_sizes.emplace_back(size);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& str = _attr(ctx);
|
||||
std::size_t size = std::distance(str.begin(), str.end());
|
||||
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_str8 >> mp_d_uint8 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& str = _attr(ctx);
|
||||
std::size_t size = std::distance(str.begin(), str.end());
|
||||
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_str16 >> mp_d_uint16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& str = _attr(ctx);
|
||||
std::size_t size = std::distance(str.begin(), str.end());
|
||||
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_str32 >> mp_d_uint32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& str = _attr(ctx);
|
||||
std::size_t size = std::distance(str.begin(), str.end());
|
||||
app_specific.vis.visit_str(size ? &str.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_bin8 >> mp_d_uint8 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& bin = _attr(ctx);
|
||||
std::size_t size = std::distance(bin.begin(), bin.end());
|
||||
app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_bin16 >> mp_d_uint16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& bin = _attr(ctx);
|
||||
std::size_t size = std::distance(bin.begin(), bin.end());
|
||||
app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_bin32 >> mp_d_uint32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx));
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& bin = _attr(ctx);
|
||||
std::size_t size = std::distance(bin.begin(), bin.end());
|
||||
app_specific.vis.visit_bin(size ? &bin.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixarray [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::size_t size = _attr(ctx) & 0b00001111;
|
||||
app_specific.index_sizes.emplace_back(size, index_size::type_t::array);
|
||||
app_specific.vis.start_array(size);
|
||||
}
|
||||
)
|
||||
]
|
||||
>> *(x3::eps [more] >> array_item)
|
||||
>> x3::eps [done]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_array16 >> mp_d_uint16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::size_t size = _attr(ctx);
|
||||
app_specific.index_sizes.emplace_back(size, index_size::type_t::array);
|
||||
app_specific.vis.start_array(size);
|
||||
}
|
||||
)
|
||||
]
|
||||
>> *(x3::eps [more] >> array_item)
|
||||
>> x3::eps [done]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_array32 >> mp_d_uint32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::size_t size = _attr(ctx);
|
||||
app_specific.index_sizes.emplace_back(size, index_size::type_t::array);
|
||||
app_specific.vis.start_array(size);
|
||||
}
|
||||
)
|
||||
]
|
||||
>> *(x3::eps [more] >> array_item)
|
||||
>> x3::eps [done]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixmap [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::size_t size = _attr(ctx) & 0b00001111;
|
||||
app_specific.index_sizes.emplace_back(size, index_size::type_t::map);
|
||||
app_specific.vis.start_map(size);
|
||||
}
|
||||
)
|
||||
]
|
||||
>> *(x3::eps [more] >> map_item)
|
||||
>> x3::eps [done]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_map16 >> mp_d_uint16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::size_t size = _attr(ctx);
|
||||
app_specific.index_sizes.emplace_back(size, index_size::type_t::map);
|
||||
app_specific.vis.start_map(size);
|
||||
}
|
||||
)
|
||||
]
|
||||
>> *(x3::eps [more] >> map_item)
|
||||
>> x3::eps [done]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_map32 >> mp_d_uint32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
std::size_t size = _attr(ctx);
|
||||
app_specific.index_sizes.emplace_back(size, index_size::type_t::map);
|
||||
app_specific.vis.start_map(size);
|
||||
}
|
||||
)
|
||||
]
|
||||
>> *(x3::eps [more] >> map_item)
|
||||
>> x3::eps [done]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixext1 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(1+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixext2 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(2+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixext4 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(4+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixext8 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(8+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_fixext16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(16+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_ext8 >> mp_d_uint8 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx)+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_ext16 >> mp_d_uint16 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx)+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
]
|
||||
|
|
||||
// -----------------------------------------------
|
||||
mp_ext32 >> mp_d_uint32 [
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.index_sizes.emplace_back(_attr(ctx)+1);
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::raw [
|
||||
*(x3::eps [more] >> x3::char_)
|
||||
>> x3::eps [done]
|
||||
][
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
auto const& ext = _attr(ctx);
|
||||
std::size_t size = std::distance(ext.begin(), ext.end());
|
||||
app_specific.vis.visit_ext(size ? &ext.front() : nullptr, size);
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
const auto array_item_def =
|
||||
x3::eps[
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.start_array_item();
|
||||
_pass(ctx) = true;
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
mp_object
|
||||
>>
|
||||
x3::eps[
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.end_array_item();
|
||||
_pass(ctx) = true;
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
const auto map_item_def = kv;
|
||||
const auto kv_def =
|
||||
x3::eps[
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.start_map_key();
|
||||
_pass(ctx) = true;
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
mp_object
|
||||
>>
|
||||
x3::eps[
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.end_map_key();
|
||||
_pass(ctx) = true;
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
x3::eps[
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.start_map_value();
|
||||
_pass(ctx) = true;
|
||||
}
|
||||
)
|
||||
]
|
||||
>>
|
||||
mp_object
|
||||
>>
|
||||
x3::eps[
|
||||
(
|
||||
[](auto& ctx){
|
||||
auto& app_specific = x3::get<tag_app_specific>(ctx).get();
|
||||
app_specific.vis.end_map_value();
|
||||
_pass(ctx) = true;
|
||||
}
|
||||
)
|
||||
];
|
||||
|
||||
BOOST_SPIRIT_DEFINE(
|
||||
mp_object, array_item, map_item, kv
|
||||
);
|
||||
|
||||
const auto rule = mp_object;
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename Iterator, typename Visitor>
|
||||
inline bool parse(Iterator&& begin, Iterator&& end, Visitor&& vis) {
|
||||
auto data = detail::make_app_specific(std::forward<Visitor>(vis));
|
||||
return detail::x3::parse(
|
||||
std::forward<Iterator>(begin),
|
||||
std::forward<Iterator>(end),
|
||||
detail::x3::with<detail::tag_app_specific>(std::ref(data))[detail::rule]
|
||||
);
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v2)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#else // BOOST_VERSION >= 106100
|
||||
|
||||
#error Boost 1.61.0 or later is required to use x3 parse
|
||||
|
||||
#endif // BOOST_VERSION >= 106100
|
||||
|
||||
#endif // defined(MSGPACK_USE_X3_PARSE)
|
||||
|
||||
#endif // MSGPACK_V2_X3_PARSE_HPP
|
||||
@@ -0,0 +1,119 @@
|
||||
//
|
||||
// MessagePack for C++ deserializing routine
|
||||
//
|
||||
// Copyright (C) 2017 KONDO Takatoshi
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
#ifndef MSGPACK_V2_X3_UNPACK_HPP
|
||||
#define MSGPACK_V2_X3_UNPACK_HPP
|
||||
|
||||
#if defined(MSGPACK_USE_X3_PARSE)
|
||||
|
||||
#include <boost/version.hpp>
|
||||
|
||||
#if BOOST_VERSION >= 106100
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/v2/create_object_visitor.hpp"
|
||||
#include "msgpack/v2/x3_parse.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v2) {
|
||||
/// @endcond
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <typename Iterator>
|
||||
inline void
|
||||
unpack_imp(Iterator&& begin, Iterator&& end,
|
||||
msgpack::zone& result_zone, msgpack::object& result, bool& referenced,
|
||||
unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR,
|
||||
unpack_limit const& limit = unpack_limit())
|
||||
{
|
||||
create_object_visitor v(f, user_data, limit);
|
||||
v.set_zone(result_zone);
|
||||
referenced = false;
|
||||
v.set_referenced(referenced);
|
||||
if (!parse(std::forward<Iterator>(begin), std::forward<Iterator>(end), v)) {
|
||||
throw msgpack::parse_error("parse error");
|
||||
}
|
||||
referenced = v.referenced();
|
||||
result = v.data();
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
|
||||
template <typename Iterator>
|
||||
inline msgpack::object_handle unpack(
|
||||
Iterator&& begin, Iterator&& end,
|
||||
bool& referenced,
|
||||
unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR,
|
||||
unpack_limit const& limit = unpack_limit())
|
||||
{
|
||||
msgpack::object obj;
|
||||
msgpack::unique_ptr<msgpack::zone> z(new msgpack::zone);
|
||||
referenced = false;
|
||||
detail::unpack_imp(
|
||||
std::forward<Iterator>(begin), std::forward<Iterator>(end), *z, obj, referenced, f, user_data, limit);
|
||||
return msgpack::object_handle(obj, msgpack::move(z));
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
inline msgpack::object_handle unpack(
|
||||
Iterator&& begin, Iterator&& end,
|
||||
unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR,
|
||||
unpack_limit const& limit = unpack_limit())
|
||||
{
|
||||
bool referenced;
|
||||
return unpack(std::forward<Iterator>(begin), std::forward<Iterator>(end), referenced, f, user_data, limit);
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
inline msgpack::object unpack(
|
||||
msgpack::zone& z,
|
||||
Iterator&& begin, Iterator&& end,
|
||||
bool& referenced,
|
||||
unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR,
|
||||
unpack_limit const& limit = unpack_limit())
|
||||
{
|
||||
msgpack::object obj;
|
||||
referenced = false;
|
||||
detail::unpack_imp(
|
||||
std::forward<Iterator>(begin), std::forward<Iterator>(end), z, obj, referenced, f, user_data, limit);
|
||||
return obj;
|
||||
}
|
||||
|
||||
template <typename Iterator>
|
||||
inline msgpack::object unpack(
|
||||
msgpack::zone& z,
|
||||
Iterator&& begin, Iterator&& end,
|
||||
unpack_reference_func f = MSGPACK_NULLPTR, void* user_data = MSGPACK_NULLPTR,
|
||||
unpack_limit const& limit = unpack_limit())
|
||||
{
|
||||
bool referenced;
|
||||
return unpack(
|
||||
z, std::forward<Iterator>(begin), std::forward<Iterator>(end), referenced, f, user_data, limit);
|
||||
}
|
||||
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v2)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#else // BOOST_VERSION >= 106100
|
||||
|
||||
#error Boost 1.61.0 or later is required to use x3 parse
|
||||
|
||||
#endif // BOOST_VERSION >= 106100
|
||||
|
||||
#endif // defined(MSGPACK_USE_X3_PARSE)
|
||||
|
||||
#endif // MSGPACK_V2_X3_UNPACK_HPP
|
||||
@@ -48,6 +48,12 @@ IF (MSGPACK_BOOST)
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_USE_X3_PARSE)
|
||||
LIST (APPEND check_PROGRAMS
|
||||
msgpack_x3_parse.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_CXX11)
|
||||
LIST (APPEND check_PROGRAMS
|
||||
iterator_cpp11.cpp
|
||||
|
||||
@@ -0,0 +1,829 @@
|
||||
#include "msgpack.hpp"
|
||||
|
||||
#include <sstream>
|
||||
#include <limits>
|
||||
|
||||
#if defined(MSGPACK_USE_X3_PARSE)
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
const double kEPS = 1e-10;
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, nil_t)
|
||||
{
|
||||
msgpack::type::nil_t v;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_TRUE(oh.get().is_nil());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bool_false)
|
||||
{
|
||||
bool v = false;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<bool>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bool_true)
|
||||
{
|
||||
bool v = true;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<bool>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, positive_fixint_1)
|
||||
{
|
||||
uint8_t v = 0;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, positive_fixint_2)
|
||||
{
|
||||
uint8_t v = 127;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, negative_fixint_1)
|
||||
{
|
||||
int8_t v = -1;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, negative_fixint_2)
|
||||
{
|
||||
int8_t v = -32;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint8_1)
|
||||
{
|
||||
uint8_t v = 128U;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint8_2)
|
||||
{
|
||||
uint8_t v = 0xffU;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint16_1)
|
||||
{
|
||||
uint16_t v = 0x100U;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint16_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint16_2)
|
||||
{
|
||||
uint16_t v = 0xffffU;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint16_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint32_1)
|
||||
{
|
||||
uint32_t v = 0x10000UL;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint32_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint32_2)
|
||||
{
|
||||
uint32_t v = 0xffffffffUL;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint32_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint64_1)
|
||||
{
|
||||
uint64_t v = 0x100000000ULL;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint64_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, uint64_2)
|
||||
{
|
||||
uint64_t v = 0xffffffffffffffffULL;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<uint64_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int8_1)
|
||||
{
|
||||
int8_t v = 0b11011111;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int8_2)
|
||||
{
|
||||
int8_t v = 0b10000000;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int8_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int16_1)
|
||||
{
|
||||
int16_t v = 0xff00;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int16_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int16_2)
|
||||
{
|
||||
int16_t v = 0x8000;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int16_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int32_1)
|
||||
{
|
||||
int32_t v = 0xff000000L;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int32_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int32_2)
|
||||
{
|
||||
int32_t v = 0x80000000L;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int32_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int64_1)
|
||||
{
|
||||
int64_t v = 0xff00000000000000LL;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int64_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, int64_2)
|
||||
{
|
||||
int64_t v = 0x8000000000000000LL;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<int64_t>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, array_1)
|
||||
{
|
||||
std::vector<int> v;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<int> >());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, array_2)
|
||||
{
|
||||
std::vector<int> v;
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i != 0xffU; ++i) v.push_back(i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<int> >());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, array_3)
|
||||
{
|
||||
std::vector<int> v;
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i != 0xffU+1U; ++i) v.push_back(i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<int> >());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, array_4)
|
||||
{
|
||||
std::vector<int> v;
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i != 0xffffU; ++i) v.push_back(i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<int> >());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, array_5)
|
||||
{
|
||||
std::vector<uint32_t> v;
|
||||
std::stringstream ss;
|
||||
for (uint32_t i = 0; i != 0xffffU+1U; ++i) v.push_back(i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<uint32_t> >());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, map_1)
|
||||
{
|
||||
std::map<int, int> v;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, (oh.get().as<std::map<int, int> >()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, map_2)
|
||||
{
|
||||
std::map<int, int> v;
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i != 0xffU; ++i) v.emplace(i, i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, (oh.get().as<std::map<int, int> >()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, map_3)
|
||||
{
|
||||
std::map<int, int> v;
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i != 0xffU+1U; ++i) v.emplace(i, i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, (oh.get().as<std::map<int, int> >()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, map_4)
|
||||
{
|
||||
std::map<int, int> v;
|
||||
std::stringstream ss;
|
||||
for (int i = 0; i != 0xffffU; ++i) v.emplace(i, i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, (oh.get().as<std::map<int, int> >()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, map_5)
|
||||
{
|
||||
std::map<uint32_t, uint32_t> v;
|
||||
std::stringstream ss;
|
||||
for (uint32_t i = 0; i != 0xffffU+1U; ++i) v.emplace(i, i);
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, (oh.get().as<std::map<uint32_t, uint32_t> >()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, float_1)
|
||||
{
|
||||
std::vector<float> v;
|
||||
v.push_back(0.0);
|
||||
v.push_back(-0.0);
|
||||
v.push_back(1.0);
|
||||
v.push_back(-1.0);
|
||||
v.push_back(numeric_limits<float>::min());
|
||||
v.push_back(numeric_limits<float>::max());
|
||||
v.push_back(nanf("tag"));
|
||||
if (numeric_limits<float>::has_infinity) {
|
||||
v.push_back(numeric_limits<float>::infinity());
|
||||
v.push_back(-numeric_limits<float>::infinity());
|
||||
}
|
||||
if (numeric_limits<float>::has_quiet_NaN) {
|
||||
v.push_back(numeric_limits<float>::quiet_NaN());
|
||||
}
|
||||
if (numeric_limits<float>::has_signaling_NaN) {
|
||||
v.push_back(numeric_limits<float>::signaling_NaN());
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < v.size() ; i++) {
|
||||
std::stringstream ss;
|
||||
float val1 = v[i];
|
||||
msgpack::pack(ss, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
float val2 = oh.get().as<float>();
|
||||
|
||||
if (std::isnan(val1))
|
||||
EXPECT_TRUE(std::isnan(val2));
|
||||
else if (std::isinf(val1))
|
||||
EXPECT_TRUE(std::isinf(val2));
|
||||
else
|
||||
EXPECT_TRUE(fabs(val2 - val1) <= kEPS);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, double_1)
|
||||
{
|
||||
std::vector<double> v;
|
||||
v.push_back(0.0);
|
||||
v.push_back(-0.0);
|
||||
v.push_back(1.0);
|
||||
v.push_back(-1.0);
|
||||
v.push_back(numeric_limits<double>::min());
|
||||
v.push_back(numeric_limits<double>::max());
|
||||
v.push_back(nanf("tag"));
|
||||
if (numeric_limits<double>::has_infinity) {
|
||||
v.push_back(numeric_limits<double>::infinity());
|
||||
v.push_back(-numeric_limits<double>::infinity());
|
||||
}
|
||||
if (numeric_limits<double>::has_quiet_NaN) {
|
||||
v.push_back(numeric_limits<double>::quiet_NaN());
|
||||
}
|
||||
if (numeric_limits<double>::has_signaling_NaN) {
|
||||
v.push_back(numeric_limits<double>::signaling_NaN());
|
||||
}
|
||||
|
||||
for (unsigned int i = 0; i < v.size() ; i++) {
|
||||
std::stringstream ss;
|
||||
double val1 = v[i];
|
||||
msgpack::pack(ss, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
double val2 = oh.get().as<double>();
|
||||
|
||||
if (std::isnan(val1))
|
||||
EXPECT_TRUE(std::isnan(val2));
|
||||
else if (std::isinf(val1))
|
||||
EXPECT_TRUE(std::isinf(val2));
|
||||
else
|
||||
EXPECT_TRUE(fabs(val2 - val1) <= kEPS);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, string_1)
|
||||
{
|
||||
std::string v;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, string_2)
|
||||
{
|
||||
std::string v;
|
||||
|
||||
for (uint64_t i = 0; i != 0x1fU; ++i) v.push_back('0'+(i%10));
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, string_3)
|
||||
{
|
||||
std::string v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffU; ++i) v.push_back('0'+(i%10));
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, string_4)
|
||||
{
|
||||
std::string v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffU+1U; ++i) v.push_back('0'+(i%10));
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, string_5)
|
||||
{
|
||||
std::string v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffffU; ++i) v.push_back('0'+(i%10));
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, string_6)
|
||||
{
|
||||
std::string v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffffUL + 1UL; ++i) v.push_back('0'+(i%10));
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bin_1)
|
||||
{
|
||||
std::vector<char> v;
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<char>>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bin_2)
|
||||
{
|
||||
std::vector<char> v;
|
||||
|
||||
for (uint64_t i = 0; i != 0x1fU; ++i) v.push_back(i%0xff);
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<char>>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bin_3)
|
||||
{
|
||||
std::vector<char> v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffU; ++i) v.push_back(i%0xff);
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<char>>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bin_4)
|
||||
{
|
||||
std::vector<char> v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffU+1U; ++i) v.push_back(i%0xff);
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<char>>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bin_5)
|
||||
{
|
||||
std::vector<char> v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffffU; ++i) v.push_back(i%0xff);
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<char>>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, bin_6)
|
||||
{
|
||||
std::vector<char> v;
|
||||
|
||||
for (uint64_t i = 0; i != 0xffffUL + 1UL; ++i) v.push_back(i%0xff);
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
auto oh = msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, oh.get().as<std::vector<char>>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, fixext1)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char const buf [] = { 2 };
|
||||
|
||||
packer.pack_ext(sizeof(buf), 1);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(1ul, oh.get().via.ext.size);
|
||||
EXPECT_EQ(1, oh.get().via.ext.type());
|
||||
EXPECT_EQ(2, oh.get().via.ext.data()[0]);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, fixext2)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char const buf [] = { 2, 3 };
|
||||
|
||||
packer.pack_ext(sizeof(buf), 0);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(2ul, oh.get().via.ext.size);
|
||||
EXPECT_EQ(0, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, fixext4)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char const buf [] = { 2, 3, 4, 5 };
|
||||
|
||||
packer.pack_ext(sizeof(buf), 1);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(4ul, oh.get().via.ext.size);
|
||||
EXPECT_EQ(1, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, fixext8)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char const buf [] = { 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
|
||||
packer.pack_ext(sizeof(buf), 1);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(8ul, oh.get().via.ext.size);
|
||||
EXPECT_EQ(1, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, fixext16)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char const buf [] = { 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17 };
|
||||
|
||||
packer.pack_ext(sizeof(buf), 1);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(16ul, oh.get().via.ext.size);
|
||||
EXPECT_EQ(1, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, ext_0)
|
||||
{
|
||||
std::size_t const size = 0;
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
|
||||
packer.pack_ext(size, 77);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(size, oh.get().via.ext.size);
|
||||
EXPECT_EQ(77, oh.get().via.ext.type());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, ext_255)
|
||||
{
|
||||
std::size_t const size = 255;
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char buf[size];
|
||||
for (std::size_t i = 0; i != size; ++i) buf[i] = static_cast<char>(i);
|
||||
packer.pack_ext(sizeof(buf), 77);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(size, oh.get().via.ext.size);
|
||||
EXPECT_EQ(77, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, ext_256)
|
||||
{
|
||||
std::size_t const size = 256;
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char buf[size];
|
||||
for (std::size_t i = 0; i != size; ++i) buf[i] = static_cast<char>(i);
|
||||
packer.pack_ext(sizeof(buf), 77);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(size, oh.get().via.ext.size);
|
||||
EXPECT_EQ(77, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, ext_65535)
|
||||
{
|
||||
std::size_t const size = 65535;
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char buf[size];
|
||||
for (std::size_t i = 0; i != size; ++i) buf[i] = static_cast<char>(i);
|
||||
packer.pack_ext(sizeof(buf), 77);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(size, oh.get().via.ext.size);
|
||||
EXPECT_EQ(77, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, ext_65536)
|
||||
{
|
||||
std::size_t const size = 65536;
|
||||
std::stringstream ss;
|
||||
msgpack::packer<std::stringstream> packer(ss);
|
||||
char buf[size];
|
||||
for (std::size_t i = 0; i != size; ++i) buf[i] = static_cast<char>(i);
|
||||
packer.pack_ext(sizeof(buf), 77);
|
||||
packer.pack_ext_body(buf, sizeof(buf));
|
||||
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(size, oh.get().via.ext.size);
|
||||
EXPECT_EQ(77, oh.get().via.ext.type());
|
||||
EXPECT_TRUE(
|
||||
std::equal(buf, buf + sizeof(buf), oh.get().via.ext.data()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, unpack_referenced_1)
|
||||
{
|
||||
std::string v = "ABC";
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
bool r;
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(ss.str().begin(), ss.str().end(), r);
|
||||
EXPECT_FALSE(r);
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, unpack_referenced_2)
|
||||
{
|
||||
std::string v = "ABC";
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
// copy is required because ss.str() returns temporary object.
|
||||
std::string str = ss.str();
|
||||
bool r;
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(
|
||||
str.begin(),
|
||||
str.end(),
|
||||
r,
|
||||
[](msgpack::type::object_type, std::size_t, void*) {
|
||||
return true;
|
||||
}
|
||||
);
|
||||
EXPECT_TRUE(r);
|
||||
EXPECT_EQ(v, oh.get().as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, unpack_zone_1)
|
||||
{
|
||||
std::string v = "ABC";
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
msgpack::zone z;
|
||||
msgpack::object obj =
|
||||
msgpack::unpack(z, ss.str().begin(), ss.str().end());
|
||||
EXPECT_EQ(v, obj.as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, unpack_zone_2)
|
||||
{
|
||||
std::string v = "ABC";
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
msgpack::zone z;
|
||||
bool r;
|
||||
msgpack::object obj =
|
||||
msgpack::unpack(z, ss.str().begin(), ss.str().end(), r);
|
||||
EXPECT_EQ(v, obj.as<std::string>());
|
||||
|
||||
EXPECT_FALSE(r);
|
||||
EXPECT_EQ(v, obj.as<std::string>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_X3_PARSE, unpack_zone_3)
|
||||
{
|
||||
std::string v = "ABC";
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
|
||||
// copy is required because ss.str() returns temporary object.
|
||||
std::string str = ss.str();
|
||||
msgpack::zone z;
|
||||
bool r;
|
||||
msgpack::object obj =
|
||||
msgpack::unpack(
|
||||
z,
|
||||
str.begin(),
|
||||
str.end(),
|
||||
r,
|
||||
[](msgpack::type::object_type, std::size_t, void*) {
|
||||
return true;
|
||||
}
|
||||
);
|
||||
EXPECT_TRUE(r);
|
||||
EXPECT_EQ(v, obj.as<std::string>());
|
||||
}
|
||||
|
||||
#endif // defined(MSGPACK_USE_X3_PARSE)
|
||||
Reference in New Issue
Block a user