Compare commits

...

86 Commits

Author SHA1 Message Date
Takatoshi Kondo
a0b2ec09da Merge pull request #1165 from MusicScience37/fix-error-for-empty-data-in-fbuffer
Fixed processing of empty data in fbuffer class.
2025-07-21 23:16:51 +09:00
Kenta Kabashima
6bd9a571f2 Fixed processing of empty data in fbuffer class. 2025-07-21 22:48:28 +09:00
Takatoshi Kondo
9b801f087a Merge pull request #1162 from jwbee/patch-1
Include type_traits before use of std:: members
2025-07-04 12:07:45 +09:00
Takatoshi Kondo
6d478cff4d Merge pull request #1163 from redboltz/update_windows_image_2022
Updated CI windows image to 2022
2025-07-04 12:06:36 +09:00
Takatoshi Kondo
3b0fc097f0 Updated CI windows image to 2022 2025-07-04 11:43:41 +09:00
Takatoshi Kondo
39aec8fe75 Merge pull request #1159 from redboltz/update_cmake_minimum_35
Updated cmake minimum required to 3.5-4.0
2025-07-04 11:19:32 +09:00
jwbee
cbeb5805cc Include type_traits before use of std:: members
msgpack-cpp relies on its users to include, directly or indirectly, the <type_traits> header before including msgpack headers. If they don't, it can't compile, because std::remove_volatile will not be declared. This fixes the issue by including it from msgpack, which should be fine now that msgpack-cpp requires C++11.
2025-07-03 11:26:35 -07:00
Takatoshi Kondo
2644706289 Updated cmake minimum required to 3.5-4.0 2025-05-18 21:09:47 +09:00
Takatoshi Kondo
1cde61e205 Merge pull request #1157 from redboltz/miyanyan-timespec
Miyanyan timespec
2025-05-17 11:08:02 +09:00
Takatoshi Kondo
8023a857e1 Updated CI ubuntu version. 2025-05-17 10:42:04 +09:00
miyanyan
0225acf247 timespec.hpp: remove duplicated include 2025-05-16 21:48:31 +08:00
Takatoshi Kondo
1876badbae Merge pull request #1154 from scrossuk/cpp_master
Work around MSVC C++20 modules error for nested msgpack::object::with_zone
2025-04-13 17:13:59 +09:00
Stephen Cross
712ec2e383 Work around MSVC C++20 modules error for nested msgpack::object::with_zone
When packaging msgpack into a C++20 module (by #include of msgpack in the
global module fragment and then `export using ...;` for relevant names),
MSVC (VS 17.13.5) reports the following:

```
error C2504: 'msgpack::v2::object': base class undefined
```

This is apparently due to with_zone being a nested type of msgpack::object;
in order to work around this problem, with_zone is replaced with an alias
to a struct defined outside of msgpack::object.
2025-04-10 12:56:17 +01:00
Takatoshi Kondo
800c483b99 Merge pull request #1151 from redboltz/fix_codecov_ignore_dir
Fixed codecov ignore directory typo.
2025-02-21 21:55:57 +09:00
Takatoshi Kondo
e18398a119 Fixed codecov ignore directory typo. 2025-02-21 21:29:43 +09:00
Takatoshi Kondo
f45dce33c2 Merge pull request #1150 from redboltz/update_codecov_action
Updated codecov-action to v5.
2025-02-21 21:27:38 +09:00
Takatoshi Kondo
3ccc51f44a Updated codecov badge link. 2025-02-21 20:55:42 +09:00
Takatoshi Kondo
86ce9185e2 Updated codecov-action to v5. 2025-02-21 20:36:42 +09:00
Takatoshi Kondo
aa719e81ea Merge pull request #1149 from redboltz/fix_ci2
Fixed boost download URL.
2025-02-21 19:28:33 +09:00
Takatoshi Kondo
765de1fd6d Fixed coverage upload. 2025-02-21 19:06:05 +09:00
Takatoshi Kondo
876a09b8ce Added ignore mismatch. 2025-02-21 18:25:55 +09:00
Takatoshi Kondo
1e294d7a12 Fixed boost download URL. 2025-02-21 17:58:30 +09:00
Takatoshi Kondo
766c8127df Merge pull request #1142 from uyha/cpp_master
Fixed `find_package` command in README
2025-02-21 17:04:36 +09:00
Takatoshi Kondo
f9f2917cc0 Merge pull request #1146 from redboltz/fix_brace
Fixed brace
2024-11-02 11:42:20 +09:00
Takatoshi Kondo
919908742b Fixed brace 2024-11-02 11:41:41 +09:00
Takatoshi Kondo
3c8ca3b29b Merge pull request #1145 from redboltz/update_to_700
Updated the version to 7.0.0.
2024-11-02 11:31:49 +09:00
Takatoshi Kondo
b41688c588 Updated the version to 7.0.0. 2024-11-02 11:10:53 +09:00
Takatoshi Kondo
405977dfa6 Merge pull request #1144 from stephanlachnit/p-cpp-revert-broken-float
Revert "Merge pull request #1018 from GeorgFritze/cpp_master"
2024-10-31 21:18:23 +09:00
Stephan Lachnit
3788b5ba63 Revert "Merge pull request #1018 from GeorgFritze/cpp_master"
This reverts commit d13d933eea, reversing
changes made to 05f654fd64.
2024-10-24 16:35:11 +02:00
Uy Ha
f2be864e04 Fixed find_package command in README 2024-10-08 15:11:59 +00:00
Takatoshi Kondo
5c606bd638 Merge pull request #1133 from redboltz/fix_1132
Fixed cmake warnings.
2024-08-06 12:44:10 +09:00
Takatoshi Kondo
0605190fd3 Removed C++03 builds from appveyor. 2024-08-06 12:22:17 +09:00
Takatoshi Kondo
28cfb1ff81 Boost.Test has dropped C++03 support.
msgpack-c adjusted it.
2024-08-06 11:38:49 +09:00
Takatoshi Kondo
636a0130ba Conditional include msgpack::variant.
It uses boost::variant. boost::variant requires boost::tyoe_index.
boost::type index has dropped C++03 support.
2024-08-06 11:21:55 +09:00
Takatoshi Kondo
22f6fa1cd2 Fixed brew update on CI. 2024-08-06 10:50:12 +09:00
Takatoshi Kondo
232fff18d4 Fixed cmake warnings. 2024-08-06 10:26:03 +09:00
Takatoshi Kondo
820ccf1f1d Merge pull request #1122 from redboltz/fix_ci
Updated the boost version to 1.85.0
2024-05-28 07:22:01 +09:00
Takatoshi Kondo
a687df0e22 Update osx enviconment. 2024-05-27 23:58:29 +09:00
Takatoshi Kondo
8d57954246 Updated the boost version to 1.85.0 2024-05-27 23:36:29 +09:00
Takatoshi Kondo
5c521bc346 Merge pull request #1117 from redboltz/fix_1116
Fixed invalid documentation.
2024-04-17 20:47:25 +09:00
Takatoshi Kondo
7bb73f3b98 Fixed invalid documentation. 2024-04-17 20:19:00 +09:00
Takatoshi Kondo
44c0f705c9 Merge pull request #1113 from redboltz/update_to_611
Update the version to 6.1.1.
2024-04-02 12:13:33 +09:00
Takatoshi Kondo
ddb884e9cd Update the version to 6.1.1. 2024-04-02 11:14:58 +09:00
Takatoshi Kondo
c593c32b87 Merge pull request #1112 from uyha/same-type-variant
Fix compilation error when `std::variant` has the same types
2024-04-02 11:07:50 +09:00
Uy Ha
d812fa5edc Fix compilation error when std::variant has the same types 2024-04-02 01:23:25 +00:00
Takatoshi Kondo
e9e06a546c Merge pull request #1110 from Zopolis4/appveyedcpp
Fix appveyor for cpp_master
2024-03-07 15:54:10 +09:00
Zopolis4
1021aeea6f Update zlib to 1.3.1 in appveyor.yml and .github/depends/zlib.sh 2024-03-07 16:58:37 +11:00
Takatoshi Kondo
2c0040cef6 Merge pull request #1101 from msgpack/revert-1096-Arenoros-zone/optimization_size/delayed_malloc
Revert "Arenoros zone/optimization size/delayed malloc"
2023-11-23 19:22:14 +09:00
Takatoshi Kondo
f33c7dfdbe Removd boost system. 2023-11-23 18:38:43 +09:00
Takatoshi Kondo
d372a71786 Revert "Arenoros zone/optimization size/delayed malloc" 2023-11-23 18:24:47 +09:00
Takatoshi Kondo
2987022c10 Merge pull request #1096 from redboltz/Arenoros-zone/optimization_size/delayed_malloc
Arenoros zone/optimization size/delayed malloc
2023-10-03 12:47:02 +09:00
Takatoshi Kondo
34f531e26e Rename ruby file. 2023-10-03 10:51:29 +09:00
Takatoshi Kondo
91006555f1 Remove boost system requirement. 2023-10-03 10:51:29 +09:00
Takatoshi Kondo
cd7c5bcfec Remove Boost::system. 2023-10-03 10:51:29 +09:00
Arenoros
add68ff9e6 replace nullptr -> MSGPACK_NULLPTR 2023-10-02 19:52:40 +03:00
Arenoros
ede530de0a fix build 2023-10-02 19:52:40 +03:00
Arenoros
62de80fa72 port optimizations for cpp03 2023-10-02 19:52:40 +03:00
Arenoros
f2b3f52d44 Correction of comments 2023-10-02 19:52:40 +03:00
Arenoros
035bfeb39e fix zone::chunk_list::clear 2023-10-02 19:52:40 +03:00
Arenoros
04292fe63d fix failed test 2023-10-02 19:52:40 +03:00
Arenoros
573ebca3d2 Optimization of msgpack::zone size on the stack and deferred memory allocation 2023-10-02 19:52:40 +03:00
Takatoshi Kondo
37fcaa1264 Merge pull request #1090 from redboltz/update_zlib_for_ci
Updated zlib for CI.
2023-08-30 00:00:16 +09:00
Takatoshi Kondo
a55c73d90e Updated zlib for CI. 2023-08-29 23:28:21 +09:00
Takatoshi Kondo
b2f056c8b6 Merge pull request #1085 from hiradyazdan/cpp_master
Fix to avoid common function name's (`has_as::check`) ambiguity/conflict with other libraries' macros
2023-08-14 09:26:04 +09:00
hiradyazdan
e7f7b51005 modified function name 'has_as::check' to avoid ambiguity/conflicts with other libraries/engines's macro definitions (e.g. UE) 2023-08-13 18:32:33 +01:00
Takatoshi Kondo
8c602e8579 Merge pull request #1083 from redboltz/update_610
Updated the version to 6.1.0.
2023-07-08 13:58:07 +09:00
Takatoshi Kondo
0cc87c0a15 Updated the version to 6.1.0. 2023-07-08 13:16:38 +09:00
Takatoshi Kondo
9d4ff7fe10 Merge pull request #1082 from redboltz/release_600
Updated changelog.
2023-07-08 13:07:06 +09:00
Takatoshi Kondo
2486aad254 Updated changelog. 2023-07-08 12:29:03 +09:00
Takatoshi Kondo
1fb1dad6bc Merge pull request #1076 from uyha/chrono-no-boost
remove dependency on boost in chrono.hpp
2023-07-06 09:11:42 +09:00
Takatoshi Kondo
2d65f66b0e Merge pull request #1075 from uyha/variant
feat: add support for `std::variant`
2023-07-06 09:09:57 +09:00
Uy Ha
4bc88d7f6f fix indent 2023-07-04 06:56:39 +00:00
Uy Ha
35638ead37 fix style 2023-07-04 06:06:43 +00:00
Uy Ha
f09713e838 fix style 2023-07-04 06:00:22 +00:00
Uy Ha
6507243913 fix style 2023-07-04 05:30:35 +00:00
Uy Ha
f2ffcf0b08 remove dependency on boost in chrono.hpp 2023-07-03 20:05:06 +00:00
Uy Ha
df1d126f61 update CI 2023-07-03 16:30:45 +00:00
Uy Ha
211c50c755 enhance error handling, implement object_with_zone, and add more tests 2023-07-03 16:17:12 +00:00
Uy Ha
8bd1b7877c add headers to Files.cmake 2023-07-03 14:49:43 +00:00
Uy Ha
d6b2de9243 fix MSVC build 2023-07-03 14:01:56 +00:00
Uy Ha
818d87c9cb add option in CMake 2023-07-03 13:50:37 +00:00
Uy Ha
327f3d1ad0 implement as and pack for std::variant 2023-07-03 13:37:37 +00:00
Takatoshi Kondo
ac062e28cb Merge pull request #1071 from redboltz/fix_1070
Fixed #1070.
2023-05-15 09:24:13 +09:00
Takatoshi Kondo
34f8fd65bb Fixed #1070.
- msgpack::type::variant behaves as MessagePack format.
  e.g.)
  12.34  => double
  12.0   => uint64_t
  -12.34 => double
  -12.0  => int64_t
- msgpack::type::variant::as_double() can be used even if interval type is
  int64_t and/or uint64_t.
- msgpack::type::variant::as_*() don't return non const reference
  internal value.
- fix coding style
2023-05-14 10:12:21 +09:00
Takatoshi Kondo
706fde4d56 Merge pull request #1065 from ArsenArsen/cpp_gcc13
test: Add missing rebind to allocators
2023-04-21 10:02:59 +09:00
Arsen Arsenović
2dd3dbc85f test: Add missing rebind to allocators
See https://gcc.gnu.org/gcc-13/porting_to.html
2023-04-18 15:50:52 +02:00
37 changed files with 637 additions and 196 deletions

View File

@@ -49,9 +49,9 @@ while getopts "b:t:p:" c; do
done
mkdir $prefix || exit 1
wget https://boostorg.jfrog.io/artifactory/main/release/1.76.0/source/boost_1_76_0.tar.bz2 || exit 1
tar xf boost_1_76_0.tar.bz2 || exit 1
cd boost_1_76_0
wget https://archives.boost.io/release/1.85.0/source/boost_1_85_0.tar.bz2 || exit 1
tar xf boost_1_85_0.tar.bz2 || exit 1
cd boost_1_85_0
./bootstrap.sh || exit 1
build()

View File

@@ -27,9 +27,9 @@ while getopts "b:t:p:" c; do
done
mkdir $prefix || exit 1
wget https://zlib.net/zlib-1.2.13.tar.gz || exit 1
tar -xf zlib-1.2.13.tar.gz || exit 1
cd zlib-1.2.13
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()
{

View File

@@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3
- name: Install build dependencies
run: |
sudo apt-get update
@@ -24,10 +24,10 @@ jobs:
- name: Cache boost
id: cache-boost
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/boost-prefix/
key: ${{ runner.os }}-boost-64-1-76-0-2021-08-09
key: ${{ runner.os }}-boost-1-85-0-2024-05-27
- name: Build boost
if: steps.cache-boost.outputs.cache-hit != 'true'
@@ -35,7 +35,7 @@ jobs:
- name: Cache zlib
id: cache-zlib
uses: actions/cache@v1
uses: actions/cache@v3
with:
path: ~/zlib-prefix/
key: ${{ runner.os }}-zlib-64-1-2-11-2021-08-09
@@ -56,18 +56,22 @@ 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
cmake --build build --target all || exit 1
ctest --test-dir build || exit 1
- name: Upload coverage to Codecov
- name: Generate coverage
working-directory: build
run: |
# Create lcov report
lcov --capture --directory . --output-file coverage.info
lcov --capture --directory . --output-file coverage.info --ignore-errors mismatch
lcov --remove coverage.info '/usr/*' --output-file coverage.info # filter system-files
lcov --list coverage.info # debug info
# Uploading report to CodeCov
bash <(curl -s https://codecov.io/bash) -f coverage.info || echo "Codecov did not collect coverage reports"
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v5
with:
files: build/coverage.info
token: ${{ secrets.CODECOV_TOKEN }}

View File

@@ -18,14 +18,19 @@ jobs:
matrix:
pattern: [0, 1, 2, 3, 4]
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v3
- name: Install Dependencies
run: |
brew update
brew install --force llvm
- name: Cache boost
id: cache-boost
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/boost-prefix/
key: ${{ runner.os }}-boost-1-76-0-2022-08-09
key: ${{ runner.os }}-boost-1-85-0-2024-05-27
- name: Build boost
if: steps.cache-boost.outputs.cache-hit != 'true'
@@ -33,7 +38,7 @@ jobs:
- name: Cache zlib
id: cache-zlib
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/zlib-prefix/
key: ${{ runner.os }}-zlib-1-2-13-2022-11-02
@@ -55,7 +60,7 @@ jobs:
case ${{ matrix.pattern }} in
0)
export MSGPACK_CXX_VERSION="MSGPACK_CXX11=OFF"
export MSGPACK_CXX_VERSION="MSGPACK_CXX11=ON"
;;
1)
export API_VERSION=1
@@ -79,13 +84,13 @@ jobs:
linux:
name: ${{ format('Linux (pattern {0})', matrix.pattern) }}
runs-on: ubuntu-20.04
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
- name: Install build dependencies
shell: bash
@@ -97,10 +102,10 @@ jobs:
- name: Cache boost
id: cache-boost
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/boost-prefix/
key: ${{ runner.os }}-boost-1-76-0-2021-08-09
key: ${{ runner.os }}-boost-1-85-0-2024-05-27
- name: Build boost
if: steps.cache-boost.outputs.cache-hit != 'true'
@@ -108,7 +113,7 @@ jobs:
- name: Cache zlib
id: cache-zlib
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: ~/zlib-prefix/
key: ${{ runner.os }}-zlib-1-2-13-2022-11-02
@@ -131,23 +136,24 @@ jobs:
case ${{ matrix.pattern }} in
0)
export CXX="clang++-10"
export MSGPACK_CXX_VERSION="MSGPACK_CXX11=OFF"
export CXX="clang++"
export MSGPACK_CXX_VERSION="MSGPACK_CXX11=ON"
;;
1)
export CXX="g++-10"
export MSGPACK_CXX_VERSION="MSGPACK_CXX11=ON"
;;
2)
export CXX="clang++-10"
export CXX="clang++"
export MSGPACK_CXX_VERSION="MSGPACK_CXX14=ON"
;;
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"
export CXX="clang++"
export MSGPACK_CXX_VERSION="MSGPACK_CXX20=ON"
export NO_BOOST="-DMSGPACK_NO_BOOST"
;;
@@ -156,7 +162,7 @@ jobs:
export ARCH=32
;;
6)
export CXX="clang++-10"
export CXX="clang++"
export API_VERSION=2
;;
7)
@@ -164,7 +170,7 @@ jobs:
export API_VERSION=1
;;
8)
export CXX="clang++-10"
export CXX="clang++"
export CHAR_SIGN="unsigned"
;;
9)
@@ -172,7 +178,7 @@ jobs:
export X3_PARSE="ON"
;;
10)
export CXX="clang++-10"
export CXX="clang++"
export ACTION="ci/build_regression.sh"
;;
11)
@@ -189,19 +195,19 @@ jobs:
windows:
name: ${{ format('Windows cxx{0}', matrix.cxx) }}
runs-on: windows-2019
runs-on: windows-2022
strategy:
fail-fast: false
matrix:
# MSVC2019 only supports /std:c++14, /std:c++17 and /std:c++latest
# MSVC2022 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
- uses: actions/checkout@v3
- name: Cache vcpkg dependencies
id: cache-vcpkg
uses: actions/cache@v2
uses: actions/cache@v3
with:
path: C:/vcpkg/installed/x64-windows
key: ${{ runner.os }}-vcpkg-2021-08-09
@@ -222,7 +228,7 @@ jobs:
md build
cmake `
-A x64 `
-G "Visual Studio 16 2019" `
-G "Visual Studio 17 2022" `
-D CMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" `
-D MSGPACK_BUILD_TESTS=ON `
-D $CPPVER `

5
.gitignore vendored
View File

@@ -49,3 +49,8 @@ Makefile
/test/streaming_c
/test/version
/test/zone
build
*-build
.cache
compile_commands.json

View File

@@ -1,3 +1,24 @@
# 2024-11-02 version 7.0.0
* Refine build system (#1133)
* Refine CI (#1122)
* Refine documents (#1117)
## << breaking changes >>
* Revert double and fload packing behavior (#1144)
* If below decimal point is zero (e.g. 2.00),
* Before: pack as int format family `0x02`
* After : pack as float format family `0xcb 0x40 0x00 0x00 0x00 0x00 0x00 0x00 0x00`
# 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)

View File

@@ -1,6 +1,4 @@
CMAKE_MINIMUM_REQUIRED (VERSION 3.1 FATAL_ERROR)
CMAKE_POLICY (SET CMP0054 NEW)
CMAKE_MINIMUM_REQUIRED (VERSION 3.5...4.0)
PROJECT (msgpack-cxx LANGUAGES CXX)
@@ -18,21 +16,22 @@ SET (VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
LIST (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
SET (GNUCXX_STD_SUPPORT_VERSION "4.3")
OPTION (MSGPACK_CXX11 "Using c++11 compiler" OFF)
OPTION (MSGPACK_CXX11 "Using c++11 compiler" ON)
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)
@@ -66,6 +65,10 @@ IF (MSGPACK_32BIT)
ENDIF ()
IF (MSGPACK_USE_BOOST)
IF ((CMAKE_VERSION VERSION_GREATER 3.30) OR
(CMAKE_VERSION VERSION_EQUAL 3.30))
CMAKE_POLICY(SET CMP0167 NEW)
ENDIF ()
SET (Boost_USE_MULTITHREADED ON)
IF (MSGPACK_USE_STATIC_BOOST)
@@ -92,6 +95,10 @@ ELSE ()
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")
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.1)
INCLUDE (CheckCXXSourceCompiles)
@@ -138,14 +145,21 @@ IF (MSGPACK_GEN_COVERAGE)
ENDIF ()
IF (MSGPACK_BUILD_TESTS)
IF (${CMAKE_CXX_STANDARD} EQUAL 98)
MESSAGE (FATAL_ERROR "Tests requires C++11 or newer")
ENDIF ()
IF ((CMAKE_VERSION VERSION_GREATER 3.27) OR
(CMAKE_VERSION VERSION_EQUAL 3.27))
CMAKE_POLICY(SET CMP0145 OLD)
ENDIF ()
IF (NOT MSGPACK_USE_BOOST)
MESSAGE(FATAL_ERROR "Test requires -DMSGPACK_USE_BOOST=ON")
ENDIF ()
ENABLE_TESTING ()
INCLUDE (CTest)
# MEMORYCHECK_COMMAND_OPTIONS needs to place prior to CTEST_MEMORYCHECK_COMMAND
SET (MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --show-leak-kinds=definite,possible --error-exitcode=1")
FIND_PROGRAM (CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
INCLUDE (Dart)
ADD_SUBDIRECTORY (test)
ENDIF ()

View File

@@ -33,6 +33,7 @@ SET (msgpack-cxx_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 (msgpack-cxx_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

View File

@@ -12,7 +12,7 @@ Same as QuickStart for C Language.
## First program
Include `msgpack.hpp` header and link `msgpack` library to use MessagePack on your program.
Include `msgpack.hpp` header to use MessagePack on your program.
```cpp
#include <msgpack.hpp>

View File

@@ -1,8 +1,8 @@
`msgpack` for C++
===================
Version 6.0.0 [![Build Status](https://github.com/msgpack/msgpack-c/workflows/CI/badge.svg?branch=cpp_master)](https://github.com/msgpack/msgpack-c/actions) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/cpp_master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/cpp_master)
[![codecov](https://codecov.io/gh/msgpack/msgpack-c/branch/cpp_master/graph/badge.svg)](https://codecov.io/gh/msgpack/msgpack-c/branch/cpp_master)
Version 7.0.0 [![Build Status](https://github.com/msgpack/msgpack-c/workflows/CI/badge.svg?branch=cpp_master)](https://github.com/msgpack/msgpack-c/actions) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/cpp_master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/cpp_master)
[![codecov](https://codecov.io/gh/msgpack/msgpack-c/branch/cpp_master/graph/badge.svg)](https://app.codecov.io/gh/msgpack/msgpack-c/tree/cpp_master)
It's like JSON but smaller and faster.
@@ -87,7 +87,6 @@ For C++ compiler
clang++ -DMSGPACK_NO_BOOST your_code.cpp
```
Usage
-----
@@ -96,7 +95,7 @@ Usage
```cmake
# ...
find_package(msgpack REQUIRED)
find_package(msgpack-cxx REQUIRED)
# ...
target_link_libraries(your_target_name <PRIVATE/PUBLIC/INTERFACE> msgpack-cxx)
# ...

View File

@@ -1,4 +1,4 @@
version: 6.0.0.{build}
version: 7.0.0.{build}
branches:
only:
@@ -6,16 +6,6 @@ branches:
environment:
matrix:
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
cpp11: -DMSGPACK_CXX11=OFF
msvc: '"Visual Studio 12 2013"'
boost_prefix: C:\Libraries\boost_1_58_0
boost_subdir: lib32-msvc-12.0
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
cpp11: -DMSGPACK_CXX11=OFF
msvc: '"Visual Studio 14 2015"'
boost_prefix: C:\Libraries\boost_1_69_0
boost_subdir: lib32-msvc-14.0
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
cpp11: -DMSGPACK_CXX11=ON
msvc: '"Visual Studio 14 2015"'
@@ -23,10 +13,10 @@ environment:
boost_subdir: lib32-msvc-14.0
build_script:
- ps: |
appveyor DownloadFile http://zlib.net/zlib-1.2.13.tar.gz -FileName zlib-1.2.13.tar.gz
7z x zlib-1.2.13.tar.gz 2> $null
7z x zlib-1.2.13.tar 2> $null
cd zlib-1.2.13
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 +24,7 @@ build_script:
cmake `
-G $env:msvc `
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\zlib-1.2.13\prefix" `
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\zlib-1.3.1\prefix" `
..
if ($LastExitCode -ne 0) { exit $LastExitCode }
@@ -52,7 +42,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.13\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 +52,5 @@ build_script:
if ($LastExitCode -ne 0) { exit $LastExitCode }
test_script:
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.13\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

View File

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

View File

@@ -48,7 +48,7 @@ FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMAND ${CMAKE_COMMAND} -E echo ""
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)

View File

@@ -31,6 +31,6 @@ ignore:
- "erb"
- "ci"
- "cmake"
- "examle"
- "example"
- "external"
- "usr"

View File

@@ -1,4 +1,4 @@
FIND_PACKAGE (Boost REQUIRED COMPONENTS system)
FIND_PACKAGE (Boost REQUIRED)
FIND_PACKAGE (Threads REQUIRED)
FIND_PACKAGE (ZLIB REQUIRED)
@@ -22,7 +22,6 @@ FOREACH (source_file ${exec_PROGRAMS})
)
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
Boost::system
Threads::Threads
)
IF (ZLIB_FOUND)

View File

@@ -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
@@ -42,7 +42,6 @@ IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
Boost::context
Boost::system
Threads::Threads
)
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")

View File

@@ -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
@@ -19,7 +19,6 @@ FOREACH (source_file ${check_PROGRAMS})
msgpack-cxx
Threads::Threads
Boost::filesystem
Boost::system
Boost::unit_test_framework
)

View 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

View File

@@ -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>)
@@ -71,7 +73,11 @@
#if !defined(MSGPACK_NO_BOOST)
#include "adaptor/boost/fusion.hpp"
#if !defined(MSGPACK_USE_CPP03)
#include "adaptor/boost/msgpack_variant.hpp"
#endif // !defined(MSGPACK_USE_CPP03)
#include "adaptor/boost/optional.hpp"
#include "adaptor/boost/string_ref.hpp"
#include "adaptor/boost/string_view.hpp"

View File

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

View File

@@ -11,17 +11,14 @@
#ifndef MSGPACK_V1_TYPE_CPP11_CHRONO_HPP
#define MSGPACK_V1_TYPE_CPP11_CHRONO_HPP
#if !defined(MSGPACK_NO_BOOST)
#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
@@ -30,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 {
@@ -45,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));
@@ -69,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));
}
@@ -98,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));
@@ -123,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));
}
@@ -142,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);
@@ -158,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);
@@ -181,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);
}
@@ -192,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 *
@@ -208,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;
}
@@ -235,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;
}
@@ -250,6 +354,4 @@ struct object_with_zone<std::chrono::time_point<Clock, Duration>> {
} // namespace msgpack
#endif // !defined(MSGPACK_NO_BOOST)
#endif // MSGPACK_V1_TYPE_CPP11_CHRONO_HPP

View File

@@ -13,7 +13,6 @@
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
#include "msgpack/object.hpp"
#include <ctime>

View 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

View File

@@ -87,6 +87,7 @@ struct is_pointer;
#include <memory>
#include <tuple>
#include <type_traits>
namespace msgpack {
/// @cond

View File

@@ -31,6 +31,7 @@ public:
{
MSGPACK_ASSERT(buf || len == 0);
if (!buf) return;
if (len == 0) return;
if (1 != fwrite(buf, len, 1, m_file)) {
throw std::runtime_error("fwrite() failed");
}

View File

@@ -32,11 +32,11 @@ struct object_kv {
msgpack::object val;
};
struct object::with_zone : msgpack::object {
with_zone(msgpack::zone& z) : zone(z) { }
struct object_with_zone_type : msgpack::object {
object_with_zone_type(msgpack::zone& z) : zone(z) { }
msgpack::zone& zone;
private:
with_zone();
object_with_zone_type();
};

View File

@@ -53,21 +53,23 @@ 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;
};
#endif // !defined(MSGPACK_USE_CPP03)
struct object_with_zone_type;
/// Object class that corresponding to MessagePack format object
/**
* See https://github.com/msgpack/msgpack-c/wiki/v1_1_cpp_object
@@ -219,7 +221,8 @@ struct object {
template <typename T>
object& operator=(const T& v);
struct with_zone;
// Not a nested struct (i.e. 'struct with_zone;') to work around MSVC C++20 modules error C2504
typedef object_with_zone_type with_zone;
protected:
struct implicit_type;

View File

@@ -1138,17 +1138,6 @@ 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];
@@ -1160,17 +1149,6 @@ 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];

View File

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

View File

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

View File

@@ -1,3 +1,3 @@
#define MSGPACK_VERSION_MAJOR 6
#define MSGPACK_VERSION_MAJOR 7
#define MSGPACK_VERSION_MINOR 0
#define MSGPACK_VERSION_REVISION 0

View File

@@ -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
@@ -8,7 +8,6 @@ LIST (APPEND check_PROGRAMS
boost_optional.cpp
boost_string_ref.cpp
boost_string_view.cpp
boost_variant.cpp
buffer.cpp
carray.cpp
cases.cpp
@@ -43,6 +42,7 @@ ENDIF ()
IF (MSGPACK_CXX11 OR MSGPACK_CXX14 OR MSGPACK_CXX17 OR MSGPACK_CXX20)
LIST (APPEND check_PROGRAMS
boost_variant.cpp
iterator_cpp11.cpp
msgpack_cpp11.cpp
reference_cpp11.cpp
@@ -79,7 +79,6 @@ FOREACH (source_file ${check_PROGRAMS})
TARGET_LINK_LIBRARIES (${source_file_we}
msgpack-cxx
Boost::system
Boost::unit_test_framework
Threads::Threads
ZLIB::ZLIB

View 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

View File

@@ -90,6 +90,7 @@ BOOST_AUTO_TEST_CASE(fbuffer)
fbuf.write("a", 1);
fbuf.write("a", 1);
fbuf.write("a", 1);
fbuf.write("", 0);
fflush(file);
rewind(file);

View File

@@ -154,8 +154,6 @@ 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"));
@@ -188,12 +186,6 @@ 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));
}
}
@@ -244,8 +236,6 @@ 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"));
@@ -282,12 +272,6 @@ 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));
}
}

View File

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

View File

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