mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-21 23:56:55 +02:00
Compare commits
84 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
44c0f705c9 | ||
![]() |
ddb884e9cd | ||
![]() |
c593c32b87 | ||
![]() |
d812fa5edc | ||
![]() |
e9e06a546c | ||
![]() |
1021aeea6f | ||
![]() |
2c0040cef6 | ||
![]() |
f33c7dfdbe | ||
![]() |
d372a71786 | ||
![]() |
2987022c10 | ||
![]() |
34f531e26e | ||
![]() |
91006555f1 | ||
![]() |
cd7c5bcfec | ||
![]() |
add68ff9e6 | ||
![]() |
ede530de0a | ||
![]() |
62de80fa72 | ||
![]() |
f2b3f52d44 | ||
![]() |
035bfeb39e | ||
![]() |
04292fe63d | ||
![]() |
573ebca3d2 | ||
![]() |
37fcaa1264 | ||
![]() |
a55c73d90e | ||
![]() |
b2f056c8b6 | ||
![]() |
e7f7b51005 | ||
![]() |
8c602e8579 | ||
![]() |
0cc87c0a15 | ||
![]() |
9d4ff7fe10 | ||
![]() |
2486aad254 | ||
![]() |
1fb1dad6bc | ||
![]() |
2d65f66b0e | ||
![]() |
4bc88d7f6f | ||
![]() |
35638ead37 | ||
![]() |
f09713e838 | ||
![]() |
6507243913 | ||
![]() |
f2ffcf0b08 | ||
![]() |
df1d126f61 | ||
![]() |
211c50c755 | ||
![]() |
8bd1b7877c | ||
![]() |
d6b2de9243 | ||
![]() |
818d87c9cb | ||
![]() |
327f3d1ad0 | ||
![]() |
ac062e28cb | ||
![]() |
34f8fd65bb | ||
![]() |
706fde4d56 | ||
![]() |
2dd3dbc85f | ||
![]() |
1edfba0cd2 | ||
![]() |
bc2c446e97 | ||
![]() |
ec8895155c | ||
![]() |
8824c626b4 | ||
![]() |
960656648b | ||
![]() |
dcabd641b5 | ||
![]() |
cfb543401a | ||
![]() |
db4fcf9109 | ||
![]() |
0726c3d930 | ||
![]() |
6c78b521b4 | ||
![]() |
f6d4704605 | ||
![]() |
7c3ef8e7c5 | ||
![]() |
8fac2a5ca9 | ||
![]() |
7e56a08074 | ||
![]() |
d679ba57a0 | ||
![]() |
2603c2a591 | ||
![]() |
535bf33681 | ||
![]() |
b051192ed6 | ||
![]() |
fb64ea0b68 | ||
![]() |
0b9a597360 | ||
![]() |
d5cef62cb9 | ||
![]() |
0b2c6d9d1a | ||
![]() |
cef8a6fdfa | ||
![]() |
cd5ba5057e | ||
![]() |
5eabf7189a | ||
![]() |
12be5d06e3 | ||
![]() |
25c3947a91 | ||
![]() |
d13d933eea | ||
![]() |
33ff3a45b8 | ||
![]() |
05de839b44 | ||
![]() |
d59e1d7716 | ||
![]() |
d5c837b612 | ||
![]() |
3b405fcab3 | ||
![]() |
68acf21a8e | ||
![]() |
05f654fd64 | ||
![]() |
07c5b00c4a | ||
![]() |
7bcb6aad05 | ||
![]() |
6f0683bb46 | ||
![]() |
8b87e62835 |
6
.github/depends/zlib.sh
vendored
6
.github/depends/zlib.sh
vendored
@@ -27,9 +27,9 @@ while getopts "b:t:p:" c; do
|
||||
done
|
||||
|
||||
mkdir $prefix || exit 1
|
||||
wget https://zlib.net/zlib-1.2.11.tar.gz || exit 1
|
||||
tar -xf zlib-1.2.11.tar.gz || exit 1
|
||||
cd zlib-1.2.11
|
||||
wget https://zlib.net/zlib-1.3.1.tar.gz || exit 1
|
||||
tar -xf zlib-1.3.1.tar.gz || exit 1
|
||||
cd zlib-1.3.1
|
||||
|
||||
build()
|
||||
{
|
||||
|
1
.github/workflows/coverage.yml
vendored
1
.github/workflows/coverage.yml
vendored
@@ -56,6 +56,7 @@ jobs:
|
||||
-D MSGPACK_BUILD_TESTS=ON \
|
||||
-D CMAKE_BUILD_TYPE=Debug \
|
||||
-D MSGPACK_GEN_COVERAGE=ON \
|
||||
-D MSGPACK_USE_STD_VARIANT_ADAPTOR=ON \
|
||||
-D CMAKE_PREFIX_PATH="$HOME/zlib-prefix/64;$HOME/boost-prefix/64" \
|
||||
-B build \
|
||||
-S . || exit 1
|
||||
|
10
.github/workflows/gha.yml
vendored
10
.github/workflows/gha.yml
vendored
@@ -25,7 +25,7 @@ jobs:
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/boost-prefix/
|
||||
key: ${{ runner.os }}-boost-1-76-0-2021-08-09
|
||||
key: ${{ runner.os }}-boost-1-76-0-2022-08-09
|
||||
|
||||
- name: Build boost
|
||||
if: steps.cache-boost.outputs.cache-hit != 'true'
|
||||
@@ -36,7 +36,7 @@ jobs:
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/zlib-prefix/
|
||||
key: ${{ runner.os }}-zlib-1-2-11-2021-08-09
|
||||
key: ${{ runner.os }}-zlib-1-2-13-2022-11-02
|
||||
|
||||
- name: Build zlib
|
||||
if: steps.cache-zlib.outputs.cache-hit != 'true'
|
||||
@@ -111,7 +111,7 @@ jobs:
|
||||
uses: actions/cache@v2
|
||||
with:
|
||||
path: ~/zlib-prefix/
|
||||
key: ${{ runner.os }}-zlib-1-2-11-2021-08-09
|
||||
key: ${{ runner.os }}-zlib-1-2-13-2022-11-02
|
||||
|
||||
- name: Build zlib
|
||||
if: steps.cache-zlib.outputs.cache-hit != 'true'
|
||||
@@ -145,6 +145,7 @@ jobs:
|
||||
3)
|
||||
export CXX="g++-10"
|
||||
export MSGPACK_CXX_VERSION="MSGPACK_CXX17=ON"
|
||||
export MSGPACK_USE_STD_VARIANT_ADAPTOR="MSGPACK_USE_STD_VARIANT_ADAPTOR=ON"
|
||||
;;
|
||||
4)
|
||||
export CXX="clang++-10"
|
||||
@@ -195,6 +196,7 @@ jobs:
|
||||
matrix:
|
||||
# MSVC2019 only supports /std:c++14, /std:c++17 and /std:c++latest
|
||||
cxx: [14, 17, 20]
|
||||
pp_flag: ["/Zc:preprocessor-", "/Zc:preprocessor"]
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
|
||||
@@ -225,7 +227,7 @@ jobs:
|
||||
-D CMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" `
|
||||
-D MSGPACK_BUILD_TESTS=ON `
|
||||
-D $CPPVER `
|
||||
-D CMAKE_CXX_FLAGS="/D_VARIADIC_MAX=10 /EHsc /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING /D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING /D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING /W3 /WX" `
|
||||
-D CMAKE_CXX_FLAGS="${{ matrix.pp_flag }} /D_VARIADIC_MAX=10 /EHsc /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING /D_SILENCE_CXX17_ALLOCATOR_VOID_DEPRECATION_WARNING /D_SILENCE_CXX17_OLD_ALLOCATOR_MEMBERS_DEPRECATION_WARNING /W3 /WX" `
|
||||
-B build `
|
||||
-S .
|
||||
if ($LastExitCode -ne 0) { exit $LastExitCode }
|
||||
|
5
.gitignore
vendored
5
.gitignore
vendored
@@ -49,3 +49,8 @@ Makefile
|
||||
/test/streaming_c
|
||||
/test/version
|
||||
/test/zone
|
||||
|
||||
build
|
||||
*-build
|
||||
.cache
|
||||
compile_commands.json
|
||||
|
32
CHANGELOG.md
32
CHANGELOG.md
@@ -1,3 +1,35 @@
|
||||
# 2024-04-02 version 6.1.1
|
||||
* Fix compilation error when std::variant has the same types (#1112)
|
||||
* Improve CI (#1090, #1110)
|
||||
* Fix to avoid common function name's (has_as::check) ambiguity/conflict with other libraries' macros (#1085)
|
||||
|
||||
# 2023-07-08 version 6.1.0
|
||||
* Remove dependency on boost in chrono.hpp (#1076)
|
||||
* Add support for std::variant behavior (#1075)
|
||||
* Fix msgpack::type::variant behavior to respect MessagePack format (#1071)
|
||||
* Add rebind allocators (#1065)
|
||||
|
||||
# 2023-03-02 version 6.0.0
|
||||
## << breaking changes >>
|
||||
* Change CMake package name of C++ library to msgpack-cxx (#1054)
|
||||
Unified all C++ package, library, cmake, tarball name become msgpack-cxx.
|
||||
|
||||
# 2023-01-10 version 5.0.0 for C++
|
||||
* Fix config for new MSVC preprocessor (#1040)
|
||||
## << breaking changes >>
|
||||
* Change CMake package name of C++ library to msgpackc-cxx (#1045, #1048)
|
||||
|
||||
# 2022-11-02 version 4.1.3 for C++
|
||||
* Fix compile error that direct inclusion of chrono with `MSGPACK_NO_BOOST` (#1038))
|
||||
|
||||
# 2022-09-07 version 4.1.2 for C++
|
||||
* Fix noexcept on zone (#1030)
|
||||
* Improve cmake support (#1028, #1032)
|
||||
* Improve CI (#1023)
|
||||
* Improve supporting platform (#1021)
|
||||
* Refine double/float packing (#1018)
|
||||
* Refine include files dependency (#1011)
|
||||
|
||||
# 2022-03-09 version 4.1.1 for C++
|
||||
* Remove chrono support on `MSGPACK_NO_BOOST` to fix compile error.
|
||||
* Improve build system (#1003)
|
||||
|
@@ -2,7 +2,9 @@ CMAKE_MINIMUM_REQUIRED (VERSION 3.1 FATAL_ERROR)
|
||||
|
||||
CMAKE_POLICY (SET CMP0054 NEW)
|
||||
|
||||
PROJECT (msgpack LANGUAGES CXX)
|
||||
PROJECT (msgpack-cxx LANGUAGES CXX)
|
||||
|
||||
ADD_LIBRARY (msgpack-cxx INTERFACE)
|
||||
|
||||
FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/version_master.hpp contents)
|
||||
STRING (REGEX MATCH "#define MSGPACK_VERSION_MAJOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents})
|
||||
@@ -21,16 +23,17 @@ OPTION (MSGPACK_CXX14 "Using c++14 compiler" OFF)
|
||||
OPTION (MSGPACK_CXX17 "Using c++17 compiler" OFF)
|
||||
OPTION (MSGPACK_CXX20 "Using c++20 compiler" OFF)
|
||||
|
||||
OPTION (MSGPACK_32BIT "32bit compile" OFF)
|
||||
OPTION (MSGPACK_USE_BOOST "Use Boost libraried" ON)
|
||||
OPTION (MSGPACK_USE_X3_PARSE "Use Boost X3 parse" OFF)
|
||||
OPTION (MSGPACK_BUILD_TESTS "Build tests" OFF)
|
||||
OPTION (MSGPACK_BUILD_DOCS "Build Doxygen documentation" ON)
|
||||
OPTION (MSGPACK_FUZZ_REGRESSION "Enable regression testing" OFF)
|
||||
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples" OFF)
|
||||
OPTION (MSGPACK_GEN_COVERAGE "Generate coverage report" OFF)
|
||||
OPTION (MSGPACK_USE_STATIC_BOOST "Statically link with boost libraries" OFF)
|
||||
OPTION (MSGPACK_CHAR_SIGN "Char sign to use (signed or unsigned)")
|
||||
OPTION (MSGPACK_32BIT "32bit compile" OFF)
|
||||
OPTION (MSGPACK_USE_BOOST "Use Boost libraried" ON)
|
||||
OPTION (MSGPACK_USE_X3_PARSE "Use Boost X3 parse" OFF)
|
||||
OPTION (MSGPACK_BUILD_TESTS "Build tests" OFF)
|
||||
OPTION (MSGPACK_BUILD_DOCS "Build Doxygen documentation" ON)
|
||||
OPTION (MSGPACK_FUZZ_REGRESSION "Enable regression testing" OFF)
|
||||
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples" OFF)
|
||||
OPTION (MSGPACK_GEN_COVERAGE "Generate coverage report" OFF)
|
||||
OPTION (MSGPACK_USE_STATIC_BOOST "Statically link with boost libraries" OFF)
|
||||
OPTION (MSGPACK_CHAR_SIGN "Char sign to use (signed or unsigned)")
|
||||
OPTION (MSGPACK_USE_STD_VARIANT_ADAPTOR "Enable the adaptor for std::variant" OFF)
|
||||
|
||||
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
@@ -55,11 +58,11 @@ ENDIF ()
|
||||
|
||||
IF (MSGPACK_32BIT)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET (CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
|
||||
SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}")
|
||||
TARGET_COMPILE_OPTIONS(msgpack-cxx INTERFACE -m32)
|
||||
TARGET_LINK_OPTIONS(msgpack-cxx INTERFACE -m32)
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
|
||||
SET (CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
|
||||
SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}")
|
||||
TARGET_COMPILE_OPTIONS(msgpack-cxx INTERFACE -m32)
|
||||
TARGET_LINK_OPTIONS(msgpack-cxx INTERFACE -m32)
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
@@ -76,18 +79,22 @@ IF (MSGPACK_USE_BOOST)
|
||||
|
||||
FIND_PACKAGE (Boost REQUIRED)
|
||||
ELSE ()
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_NO_BOOST ${CMAKE_CXX_FLAGS}")
|
||||
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_NO_BOOST)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_CHAR_SIGN)
|
||||
SET (CMAKE_CXX_FLAGS "-f${MSGPACK_CHAR_SIGN}-char ${CMAKE_CXX_FLAGS}")
|
||||
TARGET_COMPILE_OPTIONS(msgpack-cxx INTERFACE -f${MSGPACK_CHAR_SIGN}-char)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_DEFAULT_API_VERSION)
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DEFAULT_API_VERSION=${MSGPACK_DEFAULT_API_VERSION} ${CMAKE_CXX_FLAGS}")
|
||||
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_DEFAULT_API_VERSION=${MSGPACK_DEFAULT_API_VERSION})
|
||||
ELSE ()
|
||||
SET (MSGPACK_DEFAULT_API_VERSION 3)
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_DEFAULT_API_VERSION=3 ${CMAKE_CXX_FLAGS}")
|
||||
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_DEFAULT_API_VERSION=3)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_USE_STD_VARIANT_ADAPTOR)
|
||||
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_USE_STD_VARIANT_ADAPTOR)
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
@@ -110,9 +117,7 @@ ENDIF ()
|
||||
|
||||
INCLUDE (Files.cmake)
|
||||
|
||||
ADD_LIBRARY (msgpackc-cxx INTERFACE)
|
||||
|
||||
TARGET_INCLUDE_DIRECTORIES (msgpackc-cxx
|
||||
TARGET_INCLUDE_DIRECTORIES (msgpack-cxx
|
||||
INTERFACE
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
|
||||
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
|
||||
@@ -120,7 +125,7 @@ TARGET_INCLUDE_DIRECTORIES (msgpackc-cxx
|
||||
)
|
||||
|
||||
IF (MSGPACK_USE_BOOST)
|
||||
TARGET_LINK_LIBRARIES (msgpackc-cxx INTERFACE Boost::boost)
|
||||
TARGET_LINK_LIBRARIES (msgpack-cxx INTERFACE Boost::boost)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_GEN_COVERAGE)
|
||||
@@ -134,7 +139,6 @@ IF (MSGPACK_GEN_COVERAGE)
|
||||
|
||||
INCLUDE (CodeCoverage)
|
||||
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}")
|
||||
|
||||
SETUP_TARGET_FOR_COVERAGE(coverage make coverage test)
|
||||
ENDIF ()
|
||||
|
||||
@@ -157,7 +161,7 @@ IF (MSGPACK_FUZZ_REGRESSION)
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "sparc")
|
||||
SET (CMAKE_CXX_FLAGS "-DMSGPACK_ZONE_ALIGN=8 ${CMAKE_CXX_FLAGS}")
|
||||
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_ZONE_ALIGN=8)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_BUILD_EXAMPLES)
|
||||
@@ -194,9 +198,9 @@ ENDIF ()
|
||||
include (GNUInstallDirs)
|
||||
|
||||
# Install library.
|
||||
INSTALL (TARGETS msgpackc-cxx
|
||||
EXPORT msgpackc-cxx-targets
|
||||
COMPONENT msgpackc-cxx
|
||||
INSTALL (TARGETS msgpack-cxx
|
||||
EXPORT msgpack-cxx-targets
|
||||
COMPONENT msgpack-cxx
|
||||
# This provides include directory in exported target
|
||||
# relative to prefix in single directory we've put everything in.
|
||||
INCLUDES DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
|
||||
@@ -205,7 +209,7 @@ INSTALL (TARGETS msgpackc-cxx
|
||||
# Install headers from source tree.
|
||||
INSTALL (DIRECTORY include/
|
||||
DESTINATION include
|
||||
COMPONENT msgpackc-cxx
|
||||
COMPONENT msgpack-cxx
|
||||
)
|
||||
|
||||
INCLUDE (CMakePackageConfigHelpers)
|
||||
@@ -213,18 +217,18 @@ INCLUDE (CMakePackageConfigHelpers)
|
||||
IF (NOT (CMAKE_VERSION VERSION_LESS 3.14))
|
||||
SET (extra_version_file_args ARCH_INDEPENDENT)
|
||||
ENDIF ()
|
||||
SET (cmake_config_path "${CMAKE_INSTALL_LIBDIR}/cmake/msgpackc-cxx")
|
||||
SET (cmake_config_path "${CMAKE_INSTALL_LIBDIR}/cmake/msgpack-cxx")
|
||||
|
||||
# Configure the main package file from source tree.
|
||||
CONFIGURE_PACKAGE_CONFIG_FILE (
|
||||
msgpack-config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-config.cmake"
|
||||
msgpack-cxx-config.cmake.in
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-cxx-config.cmake"
|
||||
INSTALL_DESTINATION "${cmake_config_path}"
|
||||
)
|
||||
|
||||
# Write package version file.
|
||||
WRITE_BASIC_PACKAGE_VERSION_FILE (
|
||||
msgpack-config-version.cmake
|
||||
msgpack-cxx-config-version.cmake
|
||||
VERSION ${VERSION}
|
||||
COMPATIBILITY SameMajorVersion
|
||||
${extra_version_file_args}
|
||||
@@ -232,16 +236,16 @@ WRITE_BASIC_PACKAGE_VERSION_FILE (
|
||||
|
||||
# Install the generated package version file and the main package file.
|
||||
INSTALL (FILES
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-config-version.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-cxx-config.cmake"
|
||||
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-cxx-config-version.cmake"
|
||||
DESTINATION "${cmake_config_path}"
|
||||
COMPONENT msgpackc-cxx
|
||||
COMPONENT msgpack-cxx
|
||||
)
|
||||
|
||||
# This installs package in install tree for using installed targets.
|
||||
INSTALL (
|
||||
EXPORT msgpackc-cxx-targets
|
||||
FILE msgpackc-cxx-targets.cmake
|
||||
EXPORT msgpack-cxx-targets
|
||||
FILE msgpack-cxx-targets.cmake
|
||||
DESTINATION "${cmake_config_path}"
|
||||
COMPONENT msgpackc-cxx
|
||||
COMPONENT msgpack-cxx
|
||||
)
|
||||
|
@@ -1,4 +1,4 @@
|
||||
SET (msgpackc_HEADERS
|
||||
SET (msgpack-cxx_HEADERS
|
||||
include/msgpack.hpp
|
||||
include/msgpack/adaptor/adaptor_base.hpp
|
||||
include/msgpack/adaptor/adaptor_base_decl.hpp
|
||||
@@ -33,6 +33,7 @@ SET (msgpackc_HEADERS
|
||||
include/msgpack/adaptor/cpp17/carray_byte.hpp
|
||||
include/msgpack/adaptor/cpp17/optional.hpp
|
||||
include/msgpack/adaptor/cpp17/string_view.hpp
|
||||
include/msgpack/adaptor/cpp17/variant.hpp
|
||||
include/msgpack/adaptor/cpp17/vector_byte.hpp
|
||||
include/msgpack/adaptor/cpp20/span.hpp
|
||||
include/msgpack/adaptor/define.hpp
|
||||
@@ -542,6 +543,7 @@ SET (msgpackc_HEADERS
|
||||
include/msgpack/v1/adaptor/cpp17/carray_byte.hpp
|
||||
include/msgpack/v1/adaptor/cpp17/optional.hpp
|
||||
include/msgpack/v1/adaptor/cpp17/string_view.hpp
|
||||
include/msgpack/v1/adaptor/cpp17/variant.hpp
|
||||
include/msgpack/v1/adaptor/cpp17/vector_byte.hpp
|
||||
include/msgpack/v1/adaptor/cpp20/span.hpp
|
||||
include/msgpack/v1/adaptor/define.hpp
|
||||
|
@@ -1,7 +1,7 @@
|
||||
`msgpack` for C++
|
||||
===================
|
||||
|
||||
Version 4.1.1 [](https://github.com/msgpack/msgpack-c/actions) [](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/cpp_master)
|
||||
Version 6.1.1 [](https://github.com/msgpack/msgpack-c/actions) [](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/cpp_master)
|
||||
[](https://codecov.io/gh/msgpack/msgpack-c/branch/cpp_master)
|
||||
|
||||
It's like JSON but smaller and faster.
|
||||
@@ -98,7 +98,7 @@ Usage
|
||||
# ...
|
||||
find_package(msgpack REQUIRED)
|
||||
# ...
|
||||
target_link_libraries(your_target_name <PRIVATE/PUBLIC/INTERFACE> msgpackc-cxx)
|
||||
target_link_libraries(your_target_name <PRIVATE/PUBLIC/INTERFACE> msgpack-cxx)
|
||||
# ...
|
||||
```
|
||||
|
||||
|
16
appveyor.yml
16
appveyor.yml
@@ -1,4 +1,4 @@
|
||||
version: 4.1.1.{build}
|
||||
version: 6.1.1.{build}
|
||||
|
||||
branches:
|
||||
only:
|
||||
@@ -23,10 +23,10 @@ environment:
|
||||
boost_subdir: lib32-msvc-14.0
|
||||
build_script:
|
||||
- ps: |
|
||||
appveyor DownloadFile http://zlib.net/zlib-1.2.11.tar.gz -FileName zlib-1.2.11.tar.gz
|
||||
7z x zlib-1.2.11.tar.gz 2> $null
|
||||
7z x zlib-1.2.11.tar 2> $null
|
||||
cd zlib-1.2.11
|
||||
appveyor DownloadFile http://zlib.net/zlib-1.3.1.tar.gz -FileName zlib-1.3.1.tar.gz
|
||||
7z x zlib-1.3.1.tar.gz 2> $null
|
||||
7z x zlib-1.3.1.tar 2> $null
|
||||
cd zlib-1.3.1
|
||||
|
||||
md build
|
||||
md prefix
|
||||
@@ -34,7 +34,7 @@ build_script:
|
||||
|
||||
cmake `
|
||||
-G $env:msvc `
|
||||
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\zlib-1.2.11\prefix" `
|
||||
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\zlib-1.3.1\prefix" `
|
||||
..
|
||||
if ($LastExitCode -ne 0) { exit $LastExitCode }
|
||||
|
||||
@@ -52,7 +52,7 @@ build_script:
|
||||
-D MSGPACK_BUILD_EXAMPLES=ON `
|
||||
-D MSGPACK_BUILD_TESTS=ON `
|
||||
-D CMAKE_EXE_LINKER_FLAGS=/LIBPATH:"$env:boost_prefix\$env:boost_subdir" `
|
||||
-D CMAKE_PREFIX_PATH="$env:boost_prefix;$env:APPVEYOR_BUILD_FOLDER\zlib-1.2.11\prefix" `
|
||||
-D CMAKE_PREFIX_PATH="$env:boost_prefix;$env:APPVEYOR_BUILD_FOLDER\zlib-1.3.1\prefix" `
|
||||
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\prefix" `
|
||||
-D CMAKE_CXX_FLAGS="/D_VARIADIC_MAX=10 /EHsc /DBOOST_ALL_DYN_LINK" `
|
||||
..
|
||||
@@ -62,5 +62,5 @@ build_script:
|
||||
if ($LastExitCode -ne 0) { exit $LastExitCode }
|
||||
|
||||
test_script:
|
||||
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.11\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release;%boost_prefix%\%boost_subdir%
|
||||
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\zlib-1.3.1\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release;%boost_prefix%\%boost_subdir%
|
||||
- ctest -VV -C Release
|
||||
|
@@ -21,6 +21,7 @@ cmake \
|
||||
-D MSGPACK_CHAR_SIGN=${CHAR_SIGN} \
|
||||
-D MSGPACK_DEFAULT_API_VERSION=${API_VERSION} \
|
||||
-D MSGPACK_USE_X3_PARSE=${X3_PARSE} \
|
||||
-D MSGPACK_USE_STD_VARIANT_ADAPTOR=${STD_VARIANT_ADAPTOR} \
|
||||
-D CMAKE_CXX_FLAGS="${CXXFLAGS} ${ARCH_FLAG}" \
|
||||
-D CMAKE_INSTALL_PREFIX=$prefix_dir \
|
||||
-B $build_dir \
|
||||
|
@@ -138,7 +138,7 @@ class zone {
|
||||
finalizer_array m_finalizer_array;
|
||||
|
||||
public:
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE);
|
||||
|
||||
public:
|
||||
void* allocate_align(size_t size, size_t align = MSGPACK_ZONE_ALIGN);
|
||||
@@ -194,7 +194,7 @@ private:
|
||||
zone& operator=(const zone&);
|
||||
};
|
||||
|
||||
inline zone::zone(size_t chunk_size) /* throw() */ :m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
|
||||
inline zone::zone(size_t chunk_size):m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -1,4 +1,4 @@
|
||||
FIND_PACKAGE (Boost REQUIRED COMPONENTS system)
|
||||
FIND_PACKAGE (Boost REQUIRED)
|
||||
FIND_PACKAGE (Threads REQUIRED)
|
||||
FIND_PACKAGE (ZLIB REQUIRED)
|
||||
|
||||
@@ -21,8 +21,7 @@ FOREACH (source_file ${exec_PROGRAMS})
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
|
||||
msgpackc-cxx
|
||||
Boost::system
|
||||
msgpack-cxx
|
||||
Threads::Threads
|
||||
)
|
||||
IF (ZLIB_FOUND)
|
||||
|
@@ -43,7 +43,7 @@ FOREACH (source_file ${exec_PROGRAMS})
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
|
||||
msgpackc-cxx
|
||||
msgpack-cxx
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra")
|
||||
@@ -64,7 +64,7 @@ FOREACH (source_file ${with_pthread_PROGRAMS})
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
|
||||
msgpackc-cxx
|
||||
msgpack-cxx
|
||||
Threads::Threads
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
@@ -86,7 +86,7 @@ FOREACH (source_file ${with_boost_lib_PROGRAMS})
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
|
||||
msgpackc-cxx
|
||||
msgpack-cxx
|
||||
Boost::timer
|
||||
)
|
||||
IF (NOT MSVC AND NOT APPLE)
|
||||
|
@@ -17,7 +17,7 @@ IF (MSGPACK_CXX11 OR MSGPACK_CXX14 OR MSGPACK_CXX17)
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
|
||||
msgpackc-cxx
|
||||
msgpack-cxx
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra")
|
||||
|
@@ -1,5 +1,5 @@
|
||||
IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
|
||||
FIND_PACKAGE (Boost REQUIRED COMPONENTS context system)
|
||||
FIND_PACKAGE (Boost REQUIRED COMPONENTS context)
|
||||
FIND_PACKAGE (Threads REQUIRED)
|
||||
|
||||
LIST (APPEND exec_PROGRAMS
|
||||
@@ -15,7 +15,7 @@ IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
|
||||
${source_file_we}
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE msgpackc-cxx)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE msgpack-cxx)
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra")
|
||||
@@ -40,9 +40,8 @@ IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
|
||||
${source_file}
|
||||
)
|
||||
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
|
||||
msgpackc-cxx
|
||||
msgpack-cxx
|
||||
Boost::context
|
||||
Boost::system
|
||||
Threads::Threads
|
||||
)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
|
@@ -1,5 +1,5 @@
|
||||
FIND_PACKAGE (Threads REQUIRED)
|
||||
FIND_PACKAGE (Boost REQUIRED COMPONENTS system filesystem unit_test_framework)
|
||||
FIND_PACKAGE (Boost REQUIRED COMPONENTS filesystem unit_test_framework)
|
||||
|
||||
LIST (APPEND check_PROGRAMS
|
||||
regression_runner.cpp
|
||||
@@ -16,10 +16,9 @@ FOREACH (source_file ${check_PROGRAMS})
|
||||
$<IF:$<BOOL:${MSGPACK_USE_STATIC_BOOST}>,,BOOST_TEST_DYN_LINK>)
|
||||
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
msgpackc-cxx
|
||||
msgpack-cxx
|
||||
Threads::Threads
|
||||
Boost::filesystem
|
||||
Boost::system
|
||||
Boost::unit_test_framework
|
||||
)
|
||||
|
||||
|
16
include/msgpack/adaptor/cpp17/variant.hpp
Normal file
16
include/msgpack/adaptor/cpp17/variant.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2023 Uy Ha
|
||||
//
|
||||
// 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_TYPE_CPP17_VARIANT_HPP
|
||||
#define MSGPACK_TYPE_CPP17_VARIANT_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/cpp17/variant.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_CPP17_VARIANT_HPP
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
@@ -27,7 +27,7 @@ http://www.boost.org/LICENSE_1_0.txt)
|
||||
#define MSGPACK_OS_LINUX MSGPACK_VERSION_NUMBER_NOT_AVAILABLE
|
||||
|
||||
#if !defined(MSGPACK_PREDEF_DETAIL_OS_DETECTED) && ( \
|
||||
defined(linux) || defined(__linux) \
|
||||
defined(linux) || defined(__linux) || defined(__linux__) \
|
||||
)
|
||||
# undef MSGPACK_OS_LINUX
|
||||
# define MSGPACK_OS_LINUX MSGPACK_VERSION_NUMBER_AVAILABLE
|
||||
|
@@ -24,16 +24,22 @@
|
||||
# define MSGPACK_PP_CONFIG_EDG() 0x0020
|
||||
# define MSGPACK_PP_CONFIG_DMC() 0x0040
|
||||
#
|
||||
# if !defined(__clang__) && (!defined(_MSVC_TRADITIONAL) || _MSVC_TRADITIONAL)
|
||||
# define MSGPACK_TRADITIONAL_MSVC 1
|
||||
# else
|
||||
# define MSGPACK_TRADITIONAL_MSVC 0
|
||||
# endif
|
||||
#
|
||||
# ifndef MSGPACK_PP_CONFIG_FLAGS
|
||||
# if defined(__GCCXML__) || defined(__WAVE__) || defined(__MWERKS__) && __MWERKS__ >= 0x3200
|
||||
# define MSGPACK_PP_CONFIG_FLAGS() (MSGPACK_PP_CONFIG_STRICT())
|
||||
# elif defined(__EDG__) || defined(__EDG_VERSION__)
|
||||
# if defined(_MSC_VER) && !defined(__clang__) && (defined(__INTELLISENSE__) || __EDG_VERSION__ >= 308)
|
||||
# if defined(_MSC_VER) && MSGPACK_TRADITIONAL_MSVC && (defined(__INTELLISENSE__) || __EDG_VERSION__ >= 308)
|
||||
# define MSGPACK_PP_CONFIG_FLAGS() (MSGPACK_PP_CONFIG_MSVC())
|
||||
# else
|
||||
# define MSGPACK_PP_CONFIG_FLAGS() (MSGPACK_PP_CONFIG_EDG() | MSGPACK_PP_CONFIG_STRICT())
|
||||
# endif
|
||||
# elif defined(_MSC_VER) && defined(__clang__)
|
||||
# elif defined(_MSC_VER) && !MSGPACK_TRADITIONAL_MSVC
|
||||
# define MSGPACK_PP_CONFIG_FLAGS() (MSGPACK_PP_CONFIG_STRICT())
|
||||
# elif defined(__MWERKS__)
|
||||
# define MSGPACK_PP_CONFIG_FLAGS() (MSGPACK_PP_CONFIG_MWCC())
|
||||
@@ -75,7 +81,7 @@
|
||||
# define MSGPACK_PP_VARIADICS 0
|
||||
# elif defined(__CUDACC__)
|
||||
# define MSGPACK_PP_VARIADICS 1
|
||||
# elif defined(_MSC_VER) && defined(__clang__)
|
||||
# elif defined(_MSC_VER) && !MSGPACK_TRADITIONAL_MSVC
|
||||
# define MSGPACK_PP_VARIADICS 1
|
||||
# /* VC++ (C/C++) and Intel C++ Compiler >= 17.0 with MSVC */
|
||||
# elif defined _MSC_VER && _MSC_VER >= 1400 && (!defined __EDG__ || defined(__INTELLISENSE__) || defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700)
|
||||
@@ -94,7 +100,7 @@
|
||||
# elif !MSGPACK_PP_VARIADICS + 1 < 2
|
||||
# undef MSGPACK_PP_VARIADICS
|
||||
# define MSGPACK_PP_VARIADICS 1
|
||||
# if defined _MSC_VER && _MSC_VER >= 1400 && !defined(__clang__) && (defined(__INTELLISENSE__) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI))
|
||||
# if defined _MSC_VER && _MSC_VER >= 1400 && MSGPACK_TRADITIONAL_MSVC && (defined(__INTELLISENSE__) || (defined(__INTEL_COMPILER) && __INTEL_COMPILER >= 1700) || !(defined __EDG__ || defined __GCCXML__ || defined __CUDACC__ || defined __PATHSCALE__ || defined __DMC__ || defined __CODEGEARC__ || defined __BORLANDC__ || defined __MWERKS__ || defined __SUNPRO_CC || defined __HP_aCC || defined __MRC__ || defined __SC__ || defined __IBMCPP__ || defined __PGI))
|
||||
# undef MSGPACK_PP_VARIADICS_MSVC
|
||||
# define MSGPACK_PP_VARIADICS_MSVC 1
|
||||
# endif
|
||||
|
@@ -88,7 +88,7 @@
|
||||
#elif defined(unix) || defined(__unix) || defined(__APPLE__) || defined(__OpenBSD__)
|
||||
|
||||
#include <arpa/inet.h> /* __BYTE_ORDER */
|
||||
# if defined(linux)
|
||||
# if defined(linux) || defined(__linux__)
|
||||
# include <byteswap.h>
|
||||
# endif
|
||||
|
||||
|
@@ -37,9 +37,7 @@
|
||||
#include "adaptor/cpp11/array_char.hpp"
|
||||
#include "adaptor/cpp11/array_unsigned_char.hpp"
|
||||
|
||||
#if !defined(MSGPACK_NO_BOOST)
|
||||
#include "adaptor/cpp11/chrono.hpp"
|
||||
#endif // !defined(MSGPACK_NO_BOOST)
|
||||
|
||||
#include "adaptor/cpp11/forward_list.hpp"
|
||||
#include "adaptor/cpp11/reference_wrapper.hpp"
|
||||
@@ -63,6 +61,10 @@
|
||||
#include "adaptor/cpp17/carray_byte.hpp"
|
||||
#include "adaptor/cpp17/vector_byte.hpp"
|
||||
|
||||
#if MSGPACK_HAS_INCLUDE(<variant>)
|
||||
#include "adaptor/cpp17/variant.hpp"
|
||||
#endif // MSGPACK_HAS_INCLUDE(<variant>)
|
||||
|
||||
#if MSGPACK_HAS_INCLUDE(<span>)
|
||||
#include "adaptor/cpp20/span.hpp"
|
||||
#endif // MSGPACK_HAS_INCLUDE(<span>)
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
|
@@ -122,6 +122,12 @@ struct basic_variant :
|
||||
int_init(v);
|
||||
}
|
||||
basic_variant(unsigned long long v):base(uint64_t(v)) {}
|
||||
basic_variant(float v) {
|
||||
double_init(v);
|
||||
}
|
||||
basic_variant(double v) {
|
||||
double_init(v);
|
||||
}
|
||||
|
||||
bool is_nil() const {
|
||||
return boost::get<msgpack::type::nil_t>(this) != MSGPACK_NULLPTR;
|
||||
@@ -177,71 +183,50 @@ struct basic_variant :
|
||||
int64_t as_int64_t() const {
|
||||
return boost::get<int64_t>(*this);
|
||||
}
|
||||
int64_t& as_int64_t() {
|
||||
return boost::get<int64_t>(*this);
|
||||
}
|
||||
uint64_t as_uint64_t() const {
|
||||
return boost::get<uint64_t>(*this);
|
||||
}
|
||||
uint64_t& as_uint64_t() {
|
||||
return boost::get<uint64_t>(*this);
|
||||
}
|
||||
double as_double() const {
|
||||
return boost::get<double>(*this);
|
||||
}
|
||||
double& as_double() {
|
||||
return boost::get<double>(*this);
|
||||
if (is_double()) {
|
||||
return boost::get<double>(*this);
|
||||
}
|
||||
if (is_int64_t()) {
|
||||
return static_cast<double>(boost::get<int64_t>(*this));
|
||||
}
|
||||
if (is_uint64_t()) {
|
||||
return static_cast<double>(boost::get<uint64_t>(*this));
|
||||
}
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
std::string const& as_string() const {
|
||||
return boost::get<std::string>(*this);
|
||||
}
|
||||
std::string& as_string() {
|
||||
return boost::get<std::string>(*this);
|
||||
}
|
||||
#if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
boost::string_ref const& as_boost_string_ref() const {
|
||||
return boost::get<boost::string_ref>(*this);
|
||||
}
|
||||
boost::string_ref& as_boost_string_ref() {
|
||||
return boost::get<boost::string_ref>(*this);
|
||||
}
|
||||
#endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53
|
||||
std::vector<char> const& as_vector_char() const {
|
||||
return boost::get<std::vector<char> >(*this);
|
||||
}
|
||||
std::vector<char>& as_vector_char() {
|
||||
return boost::get<std::vector<char> >(*this);
|
||||
}
|
||||
raw_ref const& as_raw_ref() const {
|
||||
return boost::get<raw_ref>(*this);
|
||||
}
|
||||
ext const& as_ext() const {
|
||||
return boost::get<ext>(*this);
|
||||
}
|
||||
ext& as_ext() {
|
||||
return boost::get<ext>(*this);
|
||||
}
|
||||
ext_ref const& as_ext_ref() const {
|
||||
return boost::get<ext_ref>(*this);
|
||||
}
|
||||
std::vector<basic_variant<STR, BIN, EXT> > const& as_vector() const {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::vector<basic_variant<STR, BIN, EXT> >& as_vector() {
|
||||
return boost::get<std::vector<basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > const& as_map() const {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_map() {
|
||||
return boost::get<std::map<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > const& as_multimap() const {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> >& as_multimap() {
|
||||
return boost::get<std::multimap<basic_variant<STR, BIN, EXT>, basic_variant<STR, BIN, EXT> > >(*this);
|
||||
}
|
||||
private:
|
||||
template <typename T>
|
||||
void int_init(T v) {
|
||||
@@ -252,6 +237,19 @@ private:
|
||||
static_cast<base&>(*this) = uint64_t(v);
|
||||
}
|
||||
}
|
||||
void double_init(double v) {
|
||||
if (v == v) { // check for nan
|
||||
if (v >= 0 && v <= double(std::numeric_limits<uint64_t>::max()) && v == double(uint64_t(v))) {
|
||||
static_cast<base&>(*this) = uint64_t(v);
|
||||
return;
|
||||
}
|
||||
else if (v < 0 && v >= double(std::numeric_limits<int64_t>::min()) && v == double(int64_t(v))) {
|
||||
static_cast<base&>(*this) = int64_t(v);
|
||||
return;
|
||||
}
|
||||
}
|
||||
static_cast<base&>(*this) = v;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename STR, typename BIN, typename EXT>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/adaptor/boost/string_ref.hpp"
|
||||
#include "msgpack/adaptor/ext.hpp"
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(__GNUC__)
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <boost/utility/string_ref.hpp>
|
||||
|
@@ -15,6 +15,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <boost/utility/string_view.hpp>
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
|
@@ -13,12 +13,12 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <limits>
|
||||
#include <chrono>
|
||||
|
||||
#include <boost/numeric/conversion/cast.hpp>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
@@ -27,6 +27,113 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
namespace detail {
|
||||
template <
|
||||
typename Target,
|
||||
typename Source,
|
||||
bool target_is_signed = std::is_signed<Target>::value,
|
||||
bool source_is_signed = std::is_signed<Source>::value,
|
||||
typename = typename std::enable_if<
|
||||
std::is_integral<Target>::value &&
|
||||
std::is_integral<Source>::value
|
||||
>::type
|
||||
>
|
||||
struct would_underflow {
|
||||
// The default case includes the cases that Source being unsigned, and since Source
|
||||
// is unsigned, no underflow can happen
|
||||
would_underflow(Source) : value{false} {}
|
||||
bool value;
|
||||
};
|
||||
|
||||
template <typename Target, typename Source>
|
||||
struct would_underflow<Target, Source, false, true> {
|
||||
// When Source is signed and Target is unsigned, we only need to compare with 0 to
|
||||
// detect underflow, this works correctly and also avoids warnings from the compiler
|
||||
would_underflow(Source source) : value{source < 0} {}
|
||||
bool value;
|
||||
};
|
||||
template <typename Target, typename Source>
|
||||
struct would_underflow<Target, Source, true, true> {
|
||||
// When Source and Target are signed, the promotion rules apply sensibly so we do
|
||||
// not need to do anything
|
||||
would_underflow(Source source)
|
||||
: value{source < std::numeric_limits<Target>::min()} {}
|
||||
bool value;
|
||||
};
|
||||
|
||||
template <
|
||||
typename Target,
|
||||
typename Source,
|
||||
bool target_is_signed = std::is_signed<Target>::value,
|
||||
bool source_is_signed = std::is_signed<Source>::value,
|
||||
typename = typename std::enable_if<
|
||||
std::is_integral<Target>::value &&
|
||||
std::is_integral<Source>::value
|
||||
>::type
|
||||
>
|
||||
struct would_overflow {
|
||||
// The default case is Source and Target having the same signedness, the promotion
|
||||
// rule also apply sensibly here so nothing special needs to be done
|
||||
would_overflow(Source source)
|
||||
: value{source > std::numeric_limits<Target>::max()} {}
|
||||
bool value;
|
||||
};
|
||||
template <typename Target, typename Source>
|
||||
struct would_overflow <Target, Source, false, true> {
|
||||
// When Target is unsigned and Source is signed, we cannot rely on the promotion
|
||||
// rule.
|
||||
would_overflow(Source source)
|
||||
: value{
|
||||
sizeof(Target) >= sizeof(Source)
|
||||
// Given Source is signed, Target being unsigned and having at least the
|
||||
// same size makes impossible to overflow
|
||||
? false
|
||||
// Source being larger than Target makes it safe to cast the maximum value
|
||||
// of Target to Source
|
||||
: source > static_cast<Source>(std::numeric_limits<Target>::max())
|
||||
} {}
|
||||
bool value;
|
||||
};
|
||||
template <typename Target, typename Source>
|
||||
struct would_overflow <Target, Source, true, false> {
|
||||
// When Target is signed and Source is unsigned, we cannot rely on the promotion
|
||||
// rule.
|
||||
would_overflow(Source source)
|
||||
: value{
|
||||
sizeof(Target) > sizeof(Source)
|
||||
// Target being larger than Source makes it impossible to overflow
|
||||
? false
|
||||
// Source being unsigned and having at least the size of Target makes it
|
||||
// safe to cast the maximum value of Target to Source
|
||||
: source > static_cast<Source>(std::numeric_limits<Target>::max())
|
||||
} {}
|
||||
bool value;
|
||||
};
|
||||
|
||||
template <
|
||||
typename Target,
|
||||
typename Source,
|
||||
typename = typename std::enable_if<
|
||||
std::is_integral<Target>::value &&
|
||||
std::is_integral<Source>::value
|
||||
>::type
|
||||
>
|
||||
Target integral_cast(Source source) {
|
||||
if (would_underflow<Target, Source>(source).value) {
|
||||
throw std::underflow_error{
|
||||
"casting from Source to Target causes an underflow error"
|
||||
};
|
||||
}
|
||||
if(would_overflow<Target, Source>(source).value) {
|
||||
throw std::overflow_error{
|
||||
"casting from Source to Target causes an overflow error"
|
||||
};
|
||||
}
|
||||
|
||||
return static_cast<Target>(source);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
template <typename Clock, typename Duration>
|
||||
struct as<std::chrono::time_point<Clock, Duration>> {
|
||||
typename std::chrono::time_point<Clock, Duration> operator()(msgpack::object const& o) const {
|
||||
@@ -42,7 +149,7 @@ struct as<std::chrono::time_point<Clock, Duration>> {
|
||||
case 8: {
|
||||
uint64_t value;
|
||||
_msgpack_load64(uint64_t, o.via.ext.data(), &value);
|
||||
uint32_t nanosec = boost::numeric_cast<uint32_t>(value >> 34);
|
||||
uint32_t nanosec = detail::integral_cast<uint32_t>(value >> 34);
|
||||
uint64_t sec = value & 0x00000003ffffffffLL;
|
||||
tp += std::chrono::duration_cast<Duration>(
|
||||
std::chrono::nanoseconds(nanosec));
|
||||
@@ -66,7 +173,7 @@ struct as<std::chrono::time_point<Clock, Duration>> {
|
||||
else {
|
||||
++sec;
|
||||
tp += std::chrono::seconds(sec);
|
||||
int64_t ns = boost::numeric_cast<int64_t>(nanosec) - 1000000000L;
|
||||
int64_t ns = detail::integral_cast<int64_t>(nanosec) - 1000000000L;
|
||||
tp += std::chrono::duration_cast<Duration>(
|
||||
std::chrono::nanoseconds(ns));
|
||||
}
|
||||
@@ -95,7 +202,7 @@ struct convert<std::chrono::time_point<Clock, Duration>> {
|
||||
case 8: {
|
||||
uint64_t value;
|
||||
_msgpack_load64(uint64_t, o.via.ext.data(), &value);
|
||||
uint32_t nanosec = boost::numeric_cast<uint32_t>(value >> 34);
|
||||
uint32_t nanosec = detail::integral_cast<uint32_t>(value >> 34);
|
||||
uint64_t sec = value & 0x00000003ffffffffLL;
|
||||
tp += std::chrono::duration_cast<Duration>(
|
||||
std::chrono::nanoseconds(nanosec));
|
||||
@@ -120,7 +227,7 @@ struct convert<std::chrono::time_point<Clock, Duration>> {
|
||||
else {
|
||||
++sec;
|
||||
tp += std::chrono::seconds(sec);
|
||||
int64_t ns = boost::numeric_cast<int64_t>(nanosec) - 1000000000L;
|
||||
int64_t ns = detail::integral_cast<int64_t>(nanosec) - 1000000000L;
|
||||
tp += std::chrono::duration_cast<Duration>(
|
||||
std::chrono::nanoseconds(ns));
|
||||
}
|
||||
@@ -139,7 +246,7 @@ template <typename Clock, typename Duration>
|
||||
struct pack<std::chrono::time_point<Clock, Duration>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, std::chrono::time_point<Clock, Duration> const& v) const {
|
||||
int64_t count = boost::numeric_cast<int64_t>(v.time_since_epoch().count());
|
||||
int64_t count = detail::integral_cast<int64_t>(v.time_since_epoch().count());
|
||||
int64_t nano_num =
|
||||
Duration::period::ratio::num *
|
||||
(1000000000L / Duration::period::ratio::den);
|
||||
@@ -155,11 +262,11 @@ struct pack<std::chrono::time_point<Clock, Duration>> {
|
||||
/ Duration::period::ratio::den;
|
||||
|
||||
if ((sec >> 34) == 0) {
|
||||
uint64_t data64 = (boost::numeric_cast<uint64_t>(nanosec) << 34) | boost::numeric_cast<uint64_t>(sec);
|
||||
uint64_t data64 = (detail::integral_cast<uint64_t>(nanosec) << 34) | detail::integral_cast<uint64_t>(sec);
|
||||
if ((data64 & 0xffffffff00000000L) == 0) {
|
||||
// timestamp 32
|
||||
o.pack_ext(4, -1);
|
||||
uint32_t data32 = boost::numeric_cast<uint32_t>(data64);
|
||||
uint32_t data32 = detail::integral_cast<uint32_t>(data64);
|
||||
char buf[4];
|
||||
_msgpack_store32(buf, data32);
|
||||
o.pack_ext_body(buf, 4);
|
||||
@@ -178,7 +285,7 @@ struct pack<std::chrono::time_point<Clock, Duration>> {
|
||||
char buf[12];
|
||||
|
||||
|
||||
_msgpack_store32(&buf[0], boost::numeric_cast<uint32_t>(nanosec));
|
||||
_msgpack_store32(&buf[0], detail::integral_cast<uint32_t>(nanosec));
|
||||
_msgpack_store64(&buf[4], sec);
|
||||
o.pack_ext_body(buf, 12);
|
||||
}
|
||||
@@ -189,7 +296,7 @@ struct pack<std::chrono::time_point<Clock, Duration>> {
|
||||
template <typename Clock, typename Duration>
|
||||
struct object_with_zone<std::chrono::time_point<Clock, Duration>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::chrono::time_point<Clock, Duration>& v) const {
|
||||
int64_t count = boost::numeric_cast<int64_t>(v.time_since_epoch().count());
|
||||
int64_t count = detail::integral_cast<int64_t>(v.time_since_epoch().count());
|
||||
|
||||
int64_t nano_num =
|
||||
Duration::period::ratio::num *
|
||||
@@ -205,14 +312,14 @@ struct object_with_zone<std::chrono::time_point<Clock, Duration>> {
|
||||
* Duration::period::ratio::num
|
||||
/ Duration::period::ratio::den;
|
||||
if ((sec >> 34) == 0) {
|
||||
uint64_t data64 = (boost::numeric_cast<uint64_t>(nanosec) << 34) | boost::numeric_cast<uint64_t>(sec);
|
||||
uint64_t data64 = (detail::integral_cast<uint64_t>(nanosec) << 34) | detail::integral_cast<uint64_t>(sec);
|
||||
if ((data64 & 0xffffffff00000000L) == 0) {
|
||||
// timestamp 32
|
||||
o.type = msgpack::type::EXT;
|
||||
o.via.ext.size = 4;
|
||||
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
|
||||
p[0] = static_cast<char>(-1);
|
||||
uint32_t data32 = boost::numeric_cast<uint32_t>(data64);
|
||||
uint32_t data32 = detail::integral_cast<uint32_t>(data64);
|
||||
_msgpack_store32(&p[1], data32);
|
||||
o.via.ext.ptr = p;
|
||||
}
|
||||
@@ -232,7 +339,7 @@ struct object_with_zone<std::chrono::time_point<Clock, Duration>> {
|
||||
o.via.ext.size = 12;
|
||||
char* p = static_cast<char*>(o.zone.allocate_no_align(o.via.ext.size + 1));
|
||||
p[0] = static_cast<char>(-1);
|
||||
_msgpack_store32(&p[1], boost::numeric_cast<uint32_t>(nanosec));
|
||||
_msgpack_store32(&p[1], detail::integral_cast<uint32_t>(nanosec));
|
||||
_msgpack_store64(&p[1 + 4], sec);
|
||||
o.via.ext.ptr = p;
|
||||
}
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <forward_list>
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
@@ -13,6 +13,7 @@
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
#include <ctime>
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
|
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <memory>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <unordered_set>
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/int_decl.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <optional>
|
||||
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <string_view>
|
||||
|
151
include/msgpack/v1/adaptor/cpp17/variant.hpp
Normal file
151
include/msgpack/v1/adaptor/cpp17/variant.hpp
Normal file
@@ -0,0 +1,151 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2023 Uy Ha
|
||||
//
|
||||
// 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_TYPE_VARIANT_HPP
|
||||
#define MSGPACK_V1_TYPE_VARIANT_HPP
|
||||
|
||||
#if defined(MSGPACK_USE_STD_VARIANT_ADAPTOR)
|
||||
|
||||
#include "msgpack/cpp_version.hpp"
|
||||
|
||||
#if MSGPACK_CPP_VERSION >= 201703
|
||||
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
#include <variant>
|
||||
|
||||
namespace msgpack {
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
namespace adaptor {
|
||||
namespace detail {
|
||||
template <
|
||||
typename Variant,
|
||||
typename T,
|
||||
typename... Ts,
|
||||
std::size_t current_index,
|
||||
std::size_t... indices
|
||||
>
|
||||
Variant construct_variant(
|
||||
std::size_t index,
|
||||
msgpack::object& object,
|
||||
std::index_sequence<current_index, indices...>
|
||||
) {
|
||||
if constexpr(sizeof...(Ts) == 0) {
|
||||
return Variant{std::in_place_index<current_index>, object.as<T>()};
|
||||
}
|
||||
else {
|
||||
if (index == current_index) {
|
||||
return Variant{std::in_place_index<current_index>, object.as<T>()};
|
||||
}
|
||||
return construct_variant<Variant, Ts...>(
|
||||
index,
|
||||
object,
|
||||
std::index_sequence<indices...>()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
struct object_variant_overload {
|
||||
object_variant_overload(msgpack::object& obj, msgpack::zone& zone)
|
||||
: obj{obj}
|
||||
, zone{zone} {}
|
||||
|
||||
template<typename T>
|
||||
void operator()(T const& value) {
|
||||
obj = msgpack::object(value, zone);
|
||||
}
|
||||
|
||||
msgpack::object& obj;
|
||||
msgpack::zone& zone;
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
template <typename... Ts>
|
||||
struct as<std::variant<Ts...>, typename std::enable_if<(msgpack::has_as<Ts>::value && ...)>::type> {
|
||||
std::variant<Ts...> operator()(msgpack::object const& o) const {
|
||||
if ( o.type != msgpack::type::ARRAY
|
||||
|| o.via.array.size != 2
|
||||
|| o.via.array.ptr[0].type != msgpack::type::POSITIVE_INTEGER
|
||||
|| o.via.array.ptr[0].via.u64 >= sizeof...(Ts)) {
|
||||
throw msgpack::type_error{};
|
||||
}
|
||||
|
||||
return detail::construct_variant<std::variant<Ts...>, Ts...>(
|
||||
o.via.array.ptr[0].as<std::size_t>(),
|
||||
o.via.array.ptr[1],
|
||||
std::make_index_sequence<sizeof...(Ts)>()
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
template<typename... Ts>
|
||||
struct convert<std::variant<Ts...>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::variant<Ts...>& v) const {
|
||||
if ( o.type != msgpack::type::ARRAY
|
||||
|| o.via.array.size != 2
|
||||
|| o.via.array.ptr[0].type != msgpack::type::POSITIVE_INTEGER
|
||||
|| o.via.array.ptr[0].via.u64 >= sizeof...(Ts)) {
|
||||
throw msgpack::type_error{};
|
||||
}
|
||||
|
||||
v = detail::construct_variant<std::variant<Ts...>, Ts...>(
|
||||
o.via.array.ptr[0].as<std::size_t>(),
|
||||
o.via.array.ptr[1],
|
||||
std::make_index_sequence<sizeof...(Ts)>()
|
||||
);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Ts>
|
||||
struct pack<std::variant<Ts...>>{
|
||||
template<typename Stream>
|
||||
msgpack::packer<Stream>& operator()(
|
||||
msgpack::packer<Stream>& o,
|
||||
std::variant<Ts...> const& v
|
||||
) const {
|
||||
o.pack_array(2);
|
||||
o.pack_uint64(v.index());
|
||||
std::visit([&o](auto const& value){o.pack(value);}, v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template<typename... Ts>
|
||||
struct object_with_zone<std::variant<Ts...>> {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
std::variant<Ts...> const& v
|
||||
) const {
|
||||
msgpack::object *p =
|
||||
static_cast<msgpack::object *>(
|
||||
o.zone.allocate_align(
|
||||
sizeof(msgpack::object) * 2,
|
||||
MSGPACK_ZONE_ALIGNOF(msgpack::object)
|
||||
)
|
||||
);
|
||||
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.size = 2;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.ptr[0]= msgpack::object(v.index(), o.zone);
|
||||
std::visit(detail::object_variant_overload(o.via.array.ptr[1], o.zone), v);
|
||||
}
|
||||
};
|
||||
} // namespace adaptor
|
||||
}
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP_VERSION >= 201703
|
||||
#endif // defined(MSGPACK_USE_STD_VARIANT_ADAPTOR)
|
||||
#endif // MSGPACK_V1_TYPE_VARIANT_HPP
|
@@ -16,6 +16,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
@@ -18,6 +18,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace msgpack {
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <list>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/meta.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <string>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
@@ -138,7 +138,7 @@ class zone {
|
||||
finalizer_array m_finalizer_array;
|
||||
|
||||
public:
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE);
|
||||
|
||||
public:
|
||||
void* allocate_align(size_t size, size_t align = MSGPACK_ZONE_ALIGN);
|
||||
@@ -239,7 +239,7 @@ private:
|
||||
zone& operator=(const zone&);
|
||||
};
|
||||
|
||||
inline zone::zone(size_t chunk_size) /* throw() */ :m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
|
||||
inline zone::zone(size_t chunk_size):m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -171,7 +171,7 @@ private:
|
||||
finalizer_array m_finalizer_array;
|
||||
|
||||
public:
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) noexcept;
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE);
|
||||
|
||||
public:
|
||||
void* allocate_align(size_t size, size_t align = MSGPACK_ZONE_ALIGN);
|
||||
@@ -226,7 +226,7 @@ private:
|
||||
char* allocate_expand(size_t size);
|
||||
};
|
||||
|
||||
inline zone::zone(size_t chunk_size) noexcept:m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
|
||||
inline zone::zone(size_t chunk_size):m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
|
||||
{
|
||||
}
|
||||
|
||||
|
@@ -53,16 +53,16 @@ template <typename T>
|
||||
struct has_as {
|
||||
private:
|
||||
template <typename U>
|
||||
static auto check(U*) ->
|
||||
static auto check_(U*) ->
|
||||
// Check v1 specialization
|
||||
typename std::is_same<
|
||||
decltype(adaptor::as<U>()(std::declval<msgpack::object>())),
|
||||
T
|
||||
>::type;
|
||||
template <typename...>
|
||||
static std::false_type check(...);
|
||||
static std::false_type check_(...);
|
||||
public:
|
||||
using type = decltype(check<T>(MSGPACK_NULLPTR));
|
||||
using type = decltype(check_<T>(MSGPACK_NULLPTR));
|
||||
static constexpr bool value = type::value;
|
||||
};
|
||||
|
||||
|
@@ -1138,6 +1138,17 @@ inline packer<Stream>& packer<Stream>::pack_unsigned_long_long(unsigned long lon
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_float(float d)
|
||||
{
|
||||
if(d == d) { // check for nan
|
||||
// compare d to limits to avoid undefined behaviour
|
||||
if(d >= 0 && d <= float(std::numeric_limits<uint64_t>::max()) && d == float(uint64_t(d))) {
|
||||
pack_imp_uint64(uint64_t(d));
|
||||
return *this;
|
||||
} else if(d < 0 && d >= float(std::numeric_limits<int64_t>::min()) && d == float(int64_t(d))) {
|
||||
pack_imp_int64(int64_t(d));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
union { float f; uint32_t i; } mem;
|
||||
mem.f = d;
|
||||
char buf[5];
|
||||
@@ -1149,6 +1160,17 @@ inline packer<Stream>& packer<Stream>::pack_float(float d)
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_double(double d)
|
||||
{
|
||||
if(d == d) { // check for nan
|
||||
// compare d to limits to avoid undefined behaviour
|
||||
if(d >= 0 && d <= double(std::numeric_limits<uint64_t>::max()) && d == double(uint64_t(d))) {
|
||||
pack_imp_uint64(uint64_t(d));
|
||||
return *this;
|
||||
} else if(d < 0 && d >= double(std::numeric_limits<int64_t>::min()) && d == double(int64_t(d))) {
|
||||
pack_imp_int64(int64_t(d));
|
||||
return *this;
|
||||
}
|
||||
}
|
||||
|
||||
union { double f; uint64_t i; } mem;
|
||||
mem.f = d;
|
||||
char buf[9];
|
||||
|
@@ -10,6 +10,7 @@
|
||||
#ifndef MSGPACK_V1_SBUFFER_HPP
|
||||
#define MSGPACK_V1_SBUFFER_HPP
|
||||
|
||||
#include "msgpack/v1/cpp_config_decl.hpp"
|
||||
#include "msgpack/v1/sbuffer_decl.hpp"
|
||||
#include "msgpack/assert.hpp"
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
@@ -79,7 +79,7 @@ template <typename T>
|
||||
struct has_as {
|
||||
private:
|
||||
template <typename U>
|
||||
static auto check(U*) ->
|
||||
static auto check_(U*) ->
|
||||
typename std::enable_if<
|
||||
// check v2 specialization
|
||||
std::is_same<
|
||||
@@ -92,9 +92,9 @@ private:
|
||||
std::true_type
|
||||
>::type;
|
||||
template <typename...>
|
||||
static std::false_type check(...);
|
||||
static std::false_type check_(...);
|
||||
public:
|
||||
using type = decltype(check<T>(MSGPACK_NULLPTR));
|
||||
using type = decltype(check_<T>(MSGPACK_NULLPTR));
|
||||
static constexpr bool value = type::value;
|
||||
};
|
||||
|
||||
|
@@ -12,6 +12,7 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
|
@@ -36,7 +36,7 @@ template <typename T>
|
||||
struct has_as {
|
||||
private:
|
||||
template <typename U>
|
||||
static auto check(U*) ->
|
||||
static auto check_(U*) ->
|
||||
typename std::enable_if<
|
||||
// check v3 specialization
|
||||
std::is_same<
|
||||
@@ -52,9 +52,9 @@ private:
|
||||
std::true_type
|
||||
>::type;
|
||||
template <typename...>
|
||||
static std::false_type check(...);
|
||||
static std::false_type check_(...);
|
||||
public:
|
||||
using type = decltype(check<T>(MSGPACK_NULLPTR));
|
||||
using type = decltype(check_<T>(MSGPACK_NULLPTR));
|
||||
static constexpr bool value = type::value;
|
||||
};
|
||||
|
||||
|
@@ -1,3 +1,3 @@
|
||||
#define MSGPACK_VERSION_MAJOR 4
|
||||
#define MSGPACK_VERSION_MAJOR 6
|
||||
#define MSGPACK_VERSION_MINOR 1
|
||||
#define MSGPACK_VERSION_REVISION 1
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
find include -name "*.hpp" -or -name "*.h" | sed -e 's/\s\+/\n/g' | LC_ALL=C sort > cpp_headers.tmp
|
||||
|
||||
echo 'SET (msgpackc_HEADERS' > Files.cmake
|
||||
echo 'SET (msgpack-cxx_HEADERS' > Files.cmake
|
||||
cat cpp_headers.tmp | sed -e 's/^/ /g' >> Files.cmake
|
||||
echo ')' >> Files.cmake
|
||||
|
||||
|
@@ -32,7 +32,7 @@ tar --append --file=$filename $prefix/ChangeLog
|
||||
tar --append --file=$filename $prefix/NEWS
|
||||
tar --append --file=$filename $prefix/COPYING
|
||||
tar --append --file=$filename $prefix/README
|
||||
tar --append --file=$filename $prefix/msgpack-config.cmake.in
|
||||
tar --append --file=$filename $prefix/msgpack-cxx-config.cmake.in
|
||||
rm -f $prefix
|
||||
|
||||
gzip -f $filename
|
||||
|
@@ -1,9 +0,0 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
find_dependency(Boost REQUIRED)
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/msgpackc-cxx-targets.cmake")
|
||||
|
||||
check_required_components(msgpackc-cxx)
|
11
msgpack-cxx-config.cmake.in
Normal file
11
msgpack-cxx-config.cmake.in
Normal file
@@ -0,0 +1,11 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
include(CMakeFindDependencyMacro)
|
||||
|
||||
IF (@MSGPACK_USE_BOOST@)
|
||||
find_dependency(Boost REQUIRED)
|
||||
ENDIF ()
|
||||
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/msgpack-cxx-targets.cmake")
|
||||
|
||||
check_required_components(msgpack-cxx)
|
@@ -4,7 +4,7 @@ project(test-install LANGUAGES CXX)
|
||||
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
find_package(msgpack REQUIRED)
|
||||
find_package(msgpack-cxx REQUIRED)
|
||||
|
||||
add_executable(test-install simple.cpp)
|
||||
target_link_libraries(test-install PRIVATE msgpackc-cxx)
|
||||
target_link_libraries(test-install PRIVATE msgpack-cxx)
|
||||
|
@@ -1,6 +1,6 @@
|
||||
FIND_PACKAGE (Threads REQUIRED)
|
||||
FIND_PACKAGE (ZLIB)
|
||||
FIND_PACKAGE (Boost REQUIRED COMPONENTS unit_test_framework system)
|
||||
FIND_PACKAGE (Boost REQUIRED COMPONENTS unit_test_framework)
|
||||
|
||||
LIST (APPEND check_PROGRAMS
|
||||
array_ref.cpp
|
||||
@@ -78,8 +78,7 @@ FOREACH (source_file ${check_PROGRAMS})
|
||||
$<IF:$<BOOL:${MSGPACK_USE_STATIC_BOOST}>,,BOOST_TEST_DYN_LINK>)
|
||||
|
||||
TARGET_LINK_LIBRARIES (${source_file_we}
|
||||
msgpackc-cxx
|
||||
Boost::system
|
||||
msgpack-cxx
|
||||
Boost::unit_test_framework
|
||||
Threads::Threads
|
||||
ZLIB::ZLIB
|
||||
@@ -109,7 +108,7 @@ ADD_EXECUTABLE (
|
||||
)
|
||||
|
||||
TARGET_LINK_LIBRARIES (multi_file
|
||||
msgpackc-cxx
|
||||
msgpack-cxx
|
||||
)
|
||||
|
||||
ADD_TEST (multi_file multi_file)
|
||||
|
@@ -264,7 +264,7 @@ BOOST_AUTO_TEST_CASE(pack_convert_variant_float)
|
||||
BOOST_CHECK(val2.is_double());
|
||||
BOOST_CHECK(fabs(12.34 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_NO_THROW(boost::get<double>(val2));
|
||||
BOOST_CHECK(fabs(val2.as_double() - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK(fabs(val1.as_double() - val2.as_double()) <= kEPS);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(object_variant_float)
|
||||
@@ -277,7 +277,8 @@ BOOST_AUTO_TEST_CASE(object_variant_float)
|
||||
BOOST_CHECK(val2.is_double());
|
||||
BOOST_CHECK(fabs(12.34 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_NO_THROW(boost::get<double>(val2));
|
||||
BOOST_CHECK(fabs(val2.as_double() - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK(fabs(val1.as_double() - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK(val1 == val2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(object_with_zone_variant_float)
|
||||
@@ -291,7 +292,116 @@ BOOST_AUTO_TEST_CASE(object_with_zone_variant_float)
|
||||
BOOST_CHECK(val2.is_double());
|
||||
BOOST_CHECK(fabs(12.34 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_NO_THROW(boost::get<double>(val2));
|
||||
BOOST_CHECK(fabs(val2.as_double() - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK(fabs(val1.as_double() - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK(val1 == val2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(pack_convert_variant_float_zero_atdp_positive)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::type::variant val1 = 12.0;
|
||||
BOOST_CHECK(val1.is_uint64_t());
|
||||
BOOST_CHECK_EQUAL(val1.as_uint64_t(), 12);
|
||||
BOOST_CHECK(fabs(12.0 - val1.as_double()) <= kEPS);
|
||||
|
||||
msgpack::pack(ss, val1);
|
||||
|
||||
std::string const& str = ss.str();
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(str.data(), str.size());
|
||||
msgpack::type::variant val2 = oh.get().as<msgpack::type::variant>();
|
||||
BOOST_CHECK(val2.is_uint64_t());
|
||||
BOOST_CHECK_EQUAL(val2.as_uint64_t(), 12);
|
||||
BOOST_CHECK_NO_THROW(boost::get<uint64_t>(val2));
|
||||
BOOST_CHECK(fabs(12.0 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_EQUAL(val1.as_uint64_t(), val2.as_uint64_t());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(object_variant_float_zero_atdp_positive)
|
||||
{
|
||||
msgpack::type::variant val1 = 12.0;
|
||||
BOOST_CHECK(val1.is_uint64_t());
|
||||
BOOST_CHECK_EQUAL(val1.as_uint64_t(), 12);
|
||||
BOOST_CHECK(fabs(12.0 - val1.as_double()) <= kEPS);
|
||||
msgpack::object obj(val1);
|
||||
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
|
||||
BOOST_CHECK(val2.is_uint64_t());
|
||||
BOOST_CHECK_EQUAL(val2.as_uint64_t(), 12);
|
||||
BOOST_CHECK_NO_THROW(boost::get<uint64_t>(val2));
|
||||
BOOST_CHECK(fabs(12.0 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_EQUAL(val1.as_uint64_t(), val2.as_uint64_t());
|
||||
BOOST_CHECK(val1 == val2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(object_with_zone_variant_float_zero_atdp_positive)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::type::variant val1 = 12.0;
|
||||
BOOST_CHECK(val1.is_uint64_t());
|
||||
BOOST_CHECK_EQUAL(val1.as_uint64_t(), 12);
|
||||
BOOST_CHECK(fabs(12.0 - val1.as_double()) <= kEPS);
|
||||
msgpack::object obj(val1, z);
|
||||
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
|
||||
BOOST_CHECK(val2.is_uint64_t());
|
||||
BOOST_CHECK_EQUAL(val2.as_uint64_t(), 12);
|
||||
BOOST_CHECK_NO_THROW(boost::get<uint64_t>(val2));
|
||||
BOOST_CHECK_EQUAL(val1.as_uint64_t(), val2.as_uint64_t());
|
||||
BOOST_CHECK(fabs(12.0 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK(val1 == val2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(pack_convert_variant_float_zero_atdp_negative)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::type::variant val1 = -12.0;
|
||||
BOOST_CHECK(val1.is_int64_t());
|
||||
BOOST_CHECK_EQUAL(val1.as_int64_t(), -12);
|
||||
BOOST_CHECK(fabs(-12.0 - val1.as_double()) <= kEPS);
|
||||
|
||||
msgpack::pack(ss, val1);
|
||||
|
||||
std::string const& str = ss.str();
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(str.data(), str.size());
|
||||
msgpack::type::variant val2 = oh.get().as<msgpack::type::variant>();
|
||||
BOOST_CHECK(val2.is_int64_t());
|
||||
BOOST_CHECK_EQUAL(val2.as_int64_t(), -12);
|
||||
BOOST_CHECK_NO_THROW(boost::get<int64_t>(val2));
|
||||
BOOST_CHECK(fabs(-12.0 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_EQUAL(val1.as_int64_t(), val2.as_int64_t());
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(object_variant_float_zero_atdp_negative)
|
||||
{
|
||||
msgpack::type::variant val1 = -12.0;
|
||||
BOOST_CHECK(val1.is_int64_t());
|
||||
BOOST_CHECK_EQUAL(val1.as_int64_t(), -12);
|
||||
BOOST_CHECK(fabs(-12.0 - val1.as_double()) <= kEPS);
|
||||
msgpack::object obj(val1);
|
||||
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
|
||||
BOOST_CHECK(val2.is_int64_t());
|
||||
BOOST_CHECK_EQUAL(val2.as_int64_t(), -12);
|
||||
BOOST_CHECK_NO_THROW(boost::get<int64_t>(val2));
|
||||
BOOST_CHECK(fabs(-12.0 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_EQUAL(val1.as_int64_t(), val2.as_int64_t());
|
||||
BOOST_CHECK(val1 == val2);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(object_with_zone_variant_float_zero_atdp_negative)
|
||||
{
|
||||
msgpack::zone z;
|
||||
msgpack::type::variant val1 = -12.0;
|
||||
BOOST_CHECK(val1.is_int64_t());
|
||||
BOOST_CHECK_EQUAL(val1.as_int64_t(), -12);
|
||||
BOOST_CHECK(fabs(-12.0 - val1.as_double()) <= kEPS);
|
||||
msgpack::object obj(val1, z);
|
||||
msgpack::type::variant val2 = obj.as<msgpack::type::variant>();
|
||||
BOOST_CHECK(val2.is_int64_t());
|
||||
BOOST_CHECK_EQUAL(val2.as_int64_t(), -12);
|
||||
BOOST_CHECK_NO_THROW(boost::get<int64_t>(val2));
|
||||
BOOST_CHECK(fabs(-12.0 - val2.as_double()) <= kEPS);
|
||||
BOOST_CHECK_EQUAL(val1.as_int64_t(), val2.as_int64_t());
|
||||
BOOST_CHECK(val1 == val2);
|
||||
}
|
||||
|
||||
// str
|
||||
|
@@ -154,6 +154,8 @@ BOOST_AUTO_TEST_CASE(simple_buffer_float)
|
||||
v.push_back(-0.0);
|
||||
v.push_back(1.0);
|
||||
v.push_back(-1.0);
|
||||
v.push_back(1.1f);
|
||||
v.push_back(-1.1f);
|
||||
v.push_back(numeric_limits<float>::min());
|
||||
v.push_back(numeric_limits<float>::max());
|
||||
v.push_back(nanf("tag"));
|
||||
@@ -186,6 +188,12 @@ BOOST_AUTO_TEST_CASE(simple_buffer_float)
|
||||
BOOST_CHECK(std::isinf(val2));
|
||||
else
|
||||
BOOST_CHECK(fabs(val2 - val1) <= kEPS);
|
||||
|
||||
// check for compact storing of float
|
||||
if (val1 == val1 && val1 >= float(std::numeric_limits<int64_t>::min()) && val1 <= float(std::numeric_limits<int64_t>::max()) && val1 == float(int64_t(val1)))
|
||||
BOOST_REQUIRE_EQUAL(sbuf.size(),1);
|
||||
else
|
||||
BOOST_REQUIRE_EQUAL(sbuf.data()[0],char(0xca));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -236,6 +244,8 @@ BOOST_AUTO_TEST_CASE(simple_buffer_double)
|
||||
v.push_back(-0.0);
|
||||
v.push_back(1.0);
|
||||
v.push_back(-1.0);
|
||||
v.push_back(1.1);
|
||||
v.push_back(-1.1);
|
||||
v.push_back(numeric_limits<double>::min());
|
||||
v.push_back(numeric_limits<double>::max());
|
||||
v.push_back(nanf("tag"));
|
||||
@@ -272,6 +282,12 @@ BOOST_AUTO_TEST_CASE(simple_buffer_double)
|
||||
BOOST_CHECK(std::isinf(val2));
|
||||
else
|
||||
BOOST_CHECK(fabs(val2 - val1) <= kEPS);
|
||||
|
||||
// check for compact storing of double
|
||||
if (val1 == val1 && val1 >= double(std::numeric_limits<int64_t>::min()) && val1 <= double(std::numeric_limits<int64_t>::max()) && val1 == double(int64_t(val1)))
|
||||
BOOST_REQUIRE_EQUAL(sbuf.size(),1);
|
||||
else
|
||||
BOOST_REQUIRE_EQUAL(uint8_t(sbuf.data()[0]),uint8_t(0xcb));
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -252,6 +252,9 @@ struct equal_to : std::equal_to<Key> {
|
||||
template <class Key>
|
||||
struct set_allocator : std::allocator<Key> {
|
||||
using std::allocator<Key>::allocator;
|
||||
|
||||
template<class U>
|
||||
struct rebind { using other = set_allocator<U>; };
|
||||
};
|
||||
|
||||
// C++ named requirement Allocator implies that the first template type
|
||||
@@ -262,6 +265,9 @@ struct set_allocator : std::allocator<Key> {
|
||||
template <typename KeyValuePair>
|
||||
struct map_allocator_impl : std::allocator<KeyValuePair> {
|
||||
using std::allocator<KeyValuePair>::allocator;
|
||||
|
||||
template<class U>
|
||||
struct rebind { using other = map_allocator_impl<U>; };
|
||||
};
|
||||
|
||||
template <class Key, class T>
|
||||
@@ -270,6 +276,9 @@ using map_allocator = map_allocator_impl<std::pair<const Key, T>>;
|
||||
template <class T>
|
||||
struct allocator : std::allocator<T> {
|
||||
using std::allocator<T>::allocator;
|
||||
|
||||
template<class U>
|
||||
struct rebind { using other = allocator<U>; };
|
||||
};
|
||||
|
||||
} // namespace test
|
||||
@@ -861,8 +870,6 @@ BOOST_AUTO_TEST_CASE(no_def_con_array_simple_buffer)
|
||||
BOOST_CHECK(val1 == val2);
|
||||
}
|
||||
|
||||
#if !defined(MSGPACK_NO_BOOST)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(system_clock)
|
||||
{
|
||||
std::chrono::system_clock::time_point val1;
|
||||
@@ -1428,8 +1435,6 @@ BOOST_AUTO_TEST_CASE(high_resolution_clock_impl_now)
|
||||
BOOST_CHECK(val1 == val3);
|
||||
}
|
||||
|
||||
#endif // !defined(MSGPACK_NO_BOOST)
|
||||
|
||||
|
||||
BOOST_AUTO_TEST_CASE(timespec_pack_convert_zero)
|
||||
{
|
||||
|
@@ -461,4 +461,52 @@ BOOST_AUTO_TEST_CASE(carray_byte_object_with_zone)
|
||||
}
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_USE_STD_VARIANT_ADAPTOR)
|
||||
|
||||
BOOST_AUTO_TEST_CASE(variant_pack_unpack_as) {
|
||||
std::stringstream ss;
|
||||
std::variant<bool, int, float, double> val1{1.0};
|
||||
msgpack::pack(ss, val1);
|
||||
std::string const& str = ss.str();
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(str.data(), str.size());
|
||||
std::variant<bool, int, float, double> val2 =
|
||||
oh.get().as<std::variant<bool, int, float, double> >();
|
||||
BOOST_CHECK(val1 == val2);
|
||||
BOOST_CHECK_THROW((oh.get().as<std::variant<bool>>()), msgpack::type_error);
|
||||
|
||||
{
|
||||
std::stringstream same_ss;
|
||||
std::variant<int, float, int> same_expected{std::in_place_index<2>, 2};
|
||||
msgpack::pack(same_ss, same_expected);
|
||||
std::string const& same_str = same_ss.str();
|
||||
msgpack::object_handle same_oh =
|
||||
msgpack::unpack(same_str.data(), same_str.size());
|
||||
std::variant<int, float, int> same_actual = same_oh->as<std::variant<int, float, int>>();
|
||||
BOOST_CHECK(same_expected == same_actual);
|
||||
}
|
||||
|
||||
{
|
||||
std::stringstream same_ss;
|
||||
std::variant<int, int> same_expected{std::in_place_index<1>, 2};
|
||||
msgpack::pack(same_ss, same_expected);
|
||||
std::string const& same_str = same_ss.str();
|
||||
msgpack::object_handle same_oh =
|
||||
msgpack::unpack(same_str.data(), same_str.size());
|
||||
std::variant<int, int> same_actual = same_oh->as<std::variant<int, int>>();
|
||||
BOOST_CHECK(same_expected == same_actual);
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(variant_with_zone) {
|
||||
msgpack::zone z;
|
||||
std::variant<bool, int, float, double> val1{1.0};
|
||||
msgpack::object obj(val1, z);
|
||||
std::variant<bool, int, float, double> val2 = obj.as<std::variant<bool, int, float, double>>();
|
||||
BOOST_CHECK(val1 == val2);
|
||||
BOOST_CHECK_THROW((obj.as<std::variant<bool>>()), msgpack::type_error);
|
||||
}
|
||||
|
||||
#endif // defined(MSGPACK_USE_STD_VARIANT_ADAPTOR)
|
||||
|
||||
#endif // MSGPACK_CPP_VERSION >= 201703
|
||||
|
Reference in New Issue
Block a user