Compare commits

...

212 Commits

Author SHA1 Message Date
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 d13d933eea138215791c209456f38b8055d70cba, reversing
changes made to 05f654fd64de96fdb91d043a70de86a8f6149e9a.
2024-10-24 16:35:11 +02: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
Takatoshi Kondo
1edfba0cd2 Update CHANGELOG. 2023-03-04 22:44:38 +09:00
Takatoshi Kondo
bc2c446e97
Merge pull request #1054 from redboltz/unify_project_name_cxx
Unify all package related names to msgpack-cxx.
2023-03-04 21:34:58 +09:00
Takatoshi Kondo
ec8895155c Unify all package related names to msgpack-cxx.
Update the version to 6.0.0.
2023-02-28 10:52:21 +09:00
Takatoshi Kondo
8824c626b4
Merge pull request #1048 from redboltz/fix_make_dist.sh_cxx
Fixed cmake config.
2023-01-10 21:36:31 +09:00
Takatoshi Kondo
960656648b Fixed cmake config. 2023-01-10 20:05:13 +09:00
Takatoshi Kondo
dcabd641b5
Merge pull request #1046 from redboltz/update_to_500_cxx
Update the version to 5.0.0.
2023-01-10 19:57:54 +09:00
Takatoshi Kondo
cfb543401a Update the version to 5.0.0. 2023-01-10 18:45:39 +09:00
Takatoshi Kondo
db4fcf9109
Merge pull request #1045 from traversaro/patch-2
Change CMake package name of C++ library to msgpackc-cxx
2023-01-10 18:32:38 +09:00
Silvio Traversaro
0726c3d930
Change CMake package name of C++ library to msgpackc-cxx 2023-01-05 15:40:38 +01:00
Silvio Traversaro
6c78b521b4
Change CMake package name of C++ library to msgpackc-cxx 2023-01-05 15:37:36 +01:00
Silvio Traversaro
f6d4704605
Change CMake package name of C++ library to msgpackc-cxx 2023-01-05 15:37:01 +01:00
Takatoshi Kondo
7c3ef8e7c5
Merge pull request #1040 from laitingsheng/cpp_master
Fix config for new MSVC preprocessor
2022-11-09 19:59:37 +09:00
Tinson Lai
8fac2a5ca9
Fix config for new MSVC preprocessor 2022-11-08 18:32:54 +08:00
Takatoshi Kondo
7e56a08074
Merge pull request #1039 from redboltz/update_to_413
Update the version to 4.1.3.
2022-11-02 13:46:28 +09:00
Takatoshi Kondo
d679ba57a0 Update the version to 4.1.3. 2022-11-02 12:55:54 +09:00
Takatoshi Kondo
2603c2a591
Merge pull request #1038 from redboltz/fix_1037
Fixed #1037.
2022-11-02 12:52:59 +09:00
Takatoshi Kondo
535bf33681 Updated zlib on CI. 2022-11-02 09:58:46 +09:00
Takatoshi Kondo
b051192ed6 Fixed #1037.
Added MSGPACK_NO_BOOST guard for direct inclusion of chrono adaptor,
2022-11-02 09:58:36 +09:00
Takatoshi Kondo
fb64ea0b68
Merge pull request #1033 from redboltz/upd_412
Update the version to 4.1.2.
2022-09-07 13:22:21 +09:00
Takatoshi Kondo
0b9a597360 Update the version to 4.1.2. 2022-09-07 12:55:10 +09:00
Takatoshi Kondo
d5cef62cb9
Merge pull request #1032 from AlexisTM/feature/prevent_usage_of_boost
Prevents the looking for boost if built without it for dependents
2022-09-02 16:10:02 +09:00
Alexis Paques
0b2c6d9d1a Prevent looking for Boost if we do not need it 2022-08-31 11:04:31 +00:00
Takatoshi Kondo
cef8a6fdfa
Merge pull request #1028 from redboltz/fix_1025
Fixed #1025.
2022-08-19 22:11:27 +09:00
Takatoshi Kondo
cd5ba5057e
Merge pull request #1030 from redboltz/fix_1029
Fixed #1029.
2022-08-19 22:10:46 +09:00
Takatoshi Kondo
5eabf7189a Fixed #1029.
Removed invalid `noexcept` from zone's constructor.
2022-08-19 09:34:07 +09:00
Takatoshi Kondo
12be5d06e3 Fixed #1025.
Propagate compiler options that are decided by cmake options to the
parent project.
2022-08-06 10:58:36 +09:00
Takatoshi Kondo
25c3947a91
Merge pull request #1011 from timblechmann/fix/make-some-headers-self-contained
make some headers self-contained
2022-07-10 19:55:31 +09:00
Takatoshi Kondo
d13d933eea
Merge pull request #1018 from GeorgFritze/cpp_master
pack double and float more size efficient
2022-06-13 23:02:38 +09:00
GeorgFritze
33ff3a45b8 fix undefined bahaviour in msgpack_basic tests 2022-06-13 10:58:45 +02:00
GeorgFritze
05de839b44 fix bug in pack_float and pack_double 2022-06-13 09:18:22 +02:00
GeorgFritze
d59e1d7716 update msgpack_basic test for compact double packaging
update pack_double and pack_float to avoid warnings
2022-06-07 09:46:39 +02:00
GeorgFritze
d5c837b612 style changes 2022-06-03 15:08:23 +02:00
GeorgFritze
3b405fcab3
Merge branch 'msgpack:cpp_master' into cpp_master 2022-06-02 10:41:36 +02:00
GeorgFritze
68acf21a8e pack double and float in a more size efficient way
check also for nan and numeric limits
2022-06-02 10:40:51 +02:00
Takatoshi Kondo
05f654fd64
Merge pull request #1021 from drdzyk/cpp_master
fix detection of linux based os
2022-05-25 20:24:05 +09:00
Stanislav Eismont
07c5b00c4a update zlib from 1.2.11 to 1.2.12 version to prevent CI failure. 1.2.11 version is no longer available 2022-05-25 13:31:04 +03:00
Stanislav Eismont
7bcb6aad05 fix detection of linux based os. According to https://sourceforge.net/p/predef/wiki/OperatingSystems/ 'linux' macro is obsolete, '__linux__' should be used instead. It turns out that 'linux' macro undefined when compiling project with e.g. '-std=c++11' compilation flag 2022-05-25 10:42:43 +03:00
Georg Fritze
6f0683bb46 pack double and float more size efficient 2022-05-13 13:04:17 +02:00
Tim Blechmann
8b87e62835 make some headers self-contained
some headers are not self-contained, as they depend on
symbols from headers which aren't included
2022-03-23 15:29:12 +08:00
Takatoshi Kondo
63511f29db
Merge pull request #1008 from redboltz/upd_411
Update version to 4.1.1.
2022-03-09 20:58:42 +09:00
Takatoshi Kondo
ff707d8fb5 Update version to 4.1.1. 2022-03-09 20:10:25 +09:00
Takatoshi Kondo
2c832ff91a
Merge pull request #1007 from redboltz/temp_fix_1005
Remove chrono support on MSGPACK_NO_BOOST.
2022-03-09 14:20:10 +09:00
Takatoshi Kondo
e596b6fe35 Remove chrono support on MSGPACK_NO_BOOST. 2022-03-09 12:55:17 +09:00
Takatoshi Kondo
34e411436b
Merge pull request #1003 from jamessan/config-installdir
Install version/config files under CMAKE_INSTALL_LIBDIR
2022-02-14 19:23:15 +09:00
James McCoy
b4d800e6e4
Install version/config files under CMAKE_INSTALL_LIBDIR
Prior to the c_master/cpp_master split, this is where the files were
installed (c.f., 6e7deb8091/CMakeLists.txt (L454))
but this was changed to use "lib/" directly when updating the C++-only
packaging.

Re-instate the use of CMAKE_INSTALL_LIBDIR so the user can control where
they are installed and they follow the typical convention for location.
2022-02-13 17:05:08 -05:00
Takatoshi Kondo
b350a00f6b
Merge pull request #1002 from redboltz/update_to_410
Update the version to 4.1.0.
2022-02-12 17:48:22 +09:00
Takatoshi Kondo
79db041e8e Update the version to 4.1.0. 2022-02-12 16:45:29 +09:00
Takatoshi Kondo
cd885d282a
Merge pull request #1001 from redboltz/minimal_support_for_no_boost
Minimall supported build without boost.
2022-02-12 16:39:44 +09:00
Takatoshi Kondo
066d509a68 Minimall supported build without boost.
To remove boost dependency, `-DMSGPACK_USE_BOOST=OFF` for cmake.
By default, `-DMSGPACK_USE_BOOST` is `ON`.
NOTE: In order to build tests `-DMSGPACK_USE_BOOST=ON` is required.

For C++ compiler, the option `-DMSGPACK_NO_BOOST` is required to remove
boost.
2022-02-07 22:32:59 +09:00
Takatoshi Kondo
59f2da6a3b
Merge pull request #995 from sukidog/cpp_master_issue_994
Cpp master issue 994
2021-11-10 18:36:41 +09:00
John Cortell
bae76b7cf6 Further adjustment to EXT case 2021-11-09 07:23:52 -06:00
John Cortell
f543d94521 adjust based on PR feedback 2021-11-08 09:18:46 -06:00
John Cortell
9ff1b5e939 Don't send binary values to output stream
The stringification of a msgpack object shouldn't write the
raw bytes of a binary value. It will likely make the result
unprintable. Just print that it's a binary blob and include
the size. E.g.,

{"data":BIN(1032256)}

EXT is handled similarly but without the size. We now also
print the size.

Issue 994
2021-11-08 08:44:15 -06:00
Takatoshi Kondo
1f663d121e Merge branch 'PhilJbt-patch-1' into cpp_master 2021-11-02 09:58:11 +09:00
Takatoshi Kondo
49bdd40eab Fixed other similar include problems. 2021-11-02 09:57:37 +09:00
Philippe Jaubert
683b6e42c6
Update iterator.hpp
Can be a problem depending on the project folder nomenclature.
2021-11-01 15:27:17 +01:00
Takatoshi Kondo
53bfbba863
Merge pull request #988 from redboltz/cpp_4.0.3
Updated the version to 4.0.3.
2021-10-23 13:53:46 +09:00
Takatoshi Kondo
63221f5524 Updated the version to 4.0.3. 2021-10-23 13:28:06 +09:00
Takatoshi Kondo
fb01067a05
Merge pull request #987 from redboltz/refine_enabler
Removed Enabler2.
2021-10-23 13:01:03 +09:00
Takatoshi Kondo
af9ce1b627 Fixed test warning. 2021-10-23 12:17:34 +09:00
Takatoshi Kondo
9416c7cc5c Removed Enabler2. 2021-10-23 12:03:16 +09:00
Takatoshi Kondo
241f001d17 Merge branch 'marascio-add-build-docs-option' into cpp_master 2021-09-23 11:07:08 +09:00
Takatoshi Kondo
e148b2b26d Minimized boost install. 2021-09-23 10:45:53 +09:00
Louis R. Marascio
b4dcae20cc Add option MSGPACK_BUILD_DOCS.
This option explicitly controls the generation of targets related to
Doxygen generation, rather than relying solely on whether Doxygen is
discovered.

It is enabled by default to preserve existing behavior, but if disabled
then no Doxygen targets will be generated. This is useful when the
library is included via CMake's `add_subdirectory()`.
2021-09-22 11:40:40 -05:00
Takatoshi Kondo
3bdbf0d2ee
Merge pull request #973 from redboltz/update_to_402
Updated the version to 4.0.2.
2021-08-31 10:06:48 +09:00
Takatoshi Kondo
d8324b58e9 Updated the version to 4.0.2. 2021-08-31 09:33:01 +09:00
Takatoshi Kondo
c0708dbcba
Merge pull request #972 from kovdan01/fix_fuzz_running
Fix #969
2021-08-31 09:24:20 +09:00
Takatoshi Kondo
5dc0a904de
Merge pull request #971 from kovdan01/add_boost_test_dyn_link
Add `MSGPACK_USE_STATIC_BOOST` cmake option (fix #970)
2021-08-31 09:07:53 +09:00
Daniil Kovalev
4ed6b45abd Add MSGPACK_USE_STATIC_BOOST cmake option 2021-08-30 23:01:49 +03:00
Daniil Kovalev
4ea4d69123 Fix #969 2021-08-30 21:45:50 +03:00
Takatoshi Kondo
0b8d6a6614
Merge pull request #968 from redboltz/updated_changelog
Updated to 4.0.1.
2021-08-30 10:39:02 +09:00
Takatoshi Kondo
1339343077 Updated to 4.0.1. 2021-08-30 09:27:08 +09:00
Takatoshi Kondo
4ca74c28fb
Merge pull request #967 from redboltz/update_to_401
Updated the version to 4.0.1
2021-08-30 09:24:41 +09:00
Takatoshi Kondo
5ef0108088 Updated the version to 4.0.1
Fixed missing file and directory in makedist.sh.
2021-08-30 08:51:50 +09:00
Takatoshi Kondo
b065560404
Merge pull request #966 from msgpack/update_to_cpp_4
Updated to version 4.0.0.
2021-08-29 22:53:50 +09:00
Takatoshi Kondo
93b41492fe Updated to version 4.0.0. 2021-08-29 22:20:28 +09:00
Takatoshi Kondo
c1b3d7530f
Merge pull request #965 from redboltz/port_962_to_cpp
Ported #962 to C++.
2021-08-29 22:12:36 +09:00
Takatoshi Kondo
ca9f25b51e Added file include.
Added cstdint header for uintptr_t (for C++11 or later)
Added stdint.h header for uintptr_t (for C++03)
2021-08-29 21:35:33 +09:00
Takatoshi Kondo
860f7fce55 Ported #962 to C++.
Improved alignment calculation logic.
Fixed test for zone.
Now, align parameter must be 2^n (n >=0). e.g. 1,2,4,8,16, ...
2021-08-29 13:46:51 +09:00
Takatoshi Kondo
76f5af0593
Merge pull request #951 from kovdan01/add_span_support
Modernize codebase
2021-08-29 11:10:37 +09:00
Daniil Kovalev
d04b1e7549
Fix empty string deserialization with API version 1 2021-08-28 17:36:39 +03:00
Daniil Kovalev
0fddfe8058
Use only one compiler per build (#8) 2021-08-22 17:12:44 +03:00
Daniil Kovalev
78814311cb
Update README.md 2021-08-17 10:30:05 +03:00
Daniil Kovalev
073394cbba
Enhance CI build time 2021-08-10 01:05:53 +03:00
Daniil Kovalev
25d6f84f3c Fix cmake to support versions 3.1 and above
VERSION_GREATER_EQUAL is available since cmake 3.7 only
2021-07-07 18:11:43 +03:00
Daniil Kovalev
4022c2fc00 Fix appveyor build 2021-07-04 13:25:25 +03:00
Daniil Kovalev
7b7615a6d9
Modernize codebase
- Enhance CMakeLists.txt files.
- Move to Boost Test from Google Test to support pre-C++11 compilers.
- Add more configurations on CI matrix builds.
- Other minor fixes
2021-07-01 18:17:20 +03:00
Daniil Kovalev
0af15e45de
Add tests for std::span adaptor 2021-05-28 15:14:47 -04:00
Daniil Kovalev
18ec42ccac Merge branch 'cpp_master' into add_span_support 2021-05-28 21:56:17 +03:00
Takatoshi Kondo
be4d971c62
Merge pull request #957 from redboltz/fix_956
Fixed #956.
2021-05-16 00:11:43 +09:00
Takatoshi Kondo
3feac1f51d Fixed #956.
Called memcpy only if STR/BIN size > 0.
2021-05-15 23:43:33 +09:00
Daniil Kovalev
2b78d50d13 Fix build with C++17 or lower 2021-05-10 22:48:19 +03:00
Daniil Kovalev
77045f13bb Add tests for std::span adaptor 2021-05-10 22:41:10 +03:00
Daniil Kovalev
388891edad Add support for more binary buffer types
Add support for the following types:
- `std::array<std::byte>`
- `std::span<char>`
- `std::span<unsigned char>`
- `std::span<std::byte>`
2021-05-10 16:06:26 +03:00
Takatoshi Kondo
fc3de9806e
Merge pull request #954 from kovdan01/fix_ub_in_v4raw
Fix UB in v4raw_ref::operator==
2021-05-10 21:45:57 +09:00
Takatoshi Kondo
54b2b23b25
Merge pull request #955 from kovdan01/enhance_sanitizers_on_ci
Set `-fno-sanitize-recover=all` compiler option
2021-05-10 21:45:03 +09:00
Daniil Kovalev
b9381f842e Set -fno-sanitize-recover=all compiler option
If sanitizer detects an error, it will lead to a non-zero exit code.
2021-05-10 15:11:41 +03:00
Daniil Kovalev
90677eb58c Fix UB in v4raw_ref::operator==
Behaviour of memcmp is undefined if any of pointers passed to it is null.
See https://en.cppreference.com/w/c/string/byte/memcmp for details.
UB was detected on test MSGPACK_V4RAW_REF.pack_unpack_fix_l with UB-sanitizer.
2021-05-09 15:43:14 +03:00
Takatoshi Kondo
dfbfd927b4
Merge pull request #952 from kovdan01/fix_name_conflicts
Fix name conflicts (C++)
2021-05-09 16:39:58 +09:00
Daniil Kovalev
e487321ed6 Delete unsupported cmake option -v 2021-05-08 18:24:07 +03:00
Daniil Kovalev
7c7f45fbea Install boost on Windows via vcpkg 2021-05-08 18:18:09 +03:00
Daniil Kovalev
7707c81c5d Fix boost download URL 2021-05-08 17:55:01 +03:00
Daniil Kovalev
a66da75bd4 Fix iovec-related tests 2021-05-08 17:10:47 +03:00
Daniil Kovalev
3944993686 Fix name conflicts
Previously `struct iovec` was explicitly defined on non-Unix systems,
which caused name conflicts when other libraries (e.g. Cyrus SASL) did the same.
Using `struct iovec` as `msgpack::iovec` solves the problem.
2021-05-08 16:26:25 +03:00
Takatoshi Kondo
6b6a05e07c
Merge pull request #924 from VorpalBlade/feature/boost-timer-optional
Implement issue #923: Make boost timer optional
2020-10-19 19:36:17 +09:00
Arvid Norlander
6c8ec25016 Fix issue with Appveyor. 2020-10-19 10:00:29 +02:00
Arvid Norlander
04726a5acf Implement issue #923: Make boost timer optional 2020-10-16 10:51:49 +02:00
Takatoshi Kondo
44aa90eb50
Merge pull request #919 from redboltz/fix_readme_cpp_11_17
Fixed misleading flag notation.
2020-10-01 18:44:09 +09:00
Takatoshi Kondo
ab36ce2654 Fixed misleading flag notation.
Added missing `make` command.
2020-09-29 16:32:39 +09:00
Takatoshi Kondo
780c504c44
Merge pull request #918 from ashish-billore/patch-1
Update README.md
2020-09-29 16:26:06 +09:00
Ashish Billore
d852e6e4fb
Update README.md
Minor rewording for setup instructions.
2020-09-29 15:12:13 +09:00
Takatoshi Kondo
65938a95e9
Merge pull request #916 from mkilivan/cpp_master
Let the compiler deduce the type
2020-09-22 22:24:53 +09:00
Murat Kilivan
b9d06fe207 Let the compiler deduce the type
It also provides a consistent coding style with the rest of C++11
examples.
2020-09-14 09:06:47 +01:00
Takatoshi Kondo
555cd3ff68
Merge pull request #912 from redboltz/add_boost_requirement
Added boost dependency to README.md.
2020-08-10 16:01:09 +09:00
Takatoshi Kondo
e88fa26f7a Added boost dependency to README.md. 2020-08-10 13:56:15 +09:00
Takatoshi Kondo
0d203644be
Merge pull request #906 from redboltz/fix_905
Fixed #905.
2020-08-07 10:31:07 +09:00
Takatoshi Kondo
d53d42a791 Added vcpkg update. 2020-08-01 11:47:33 +09:00
Takatoshi Kondo
14763a8b31 Fixed #905.
Added compiler version cheking for atomic test for older compilers on cmake.
2020-08-01 08:58:36 +09:00
Takatoshi Kondo
70912ffde4
Merge pull request #898 from redboltz/refine_assert
Replaced assert with BOOST_ASSERT.
2020-07-03 09:09:20 +09:00
Takatoshi Kondo
6598c6228f Replaced assert with BOOST_ASSERT.
Applied *buffer buf and len checking assert.
Avoided needless code execution if buf is nullptr.
2020-07-02 21:36:04 +09:00
Takatoshi Kondo
eb1e7e6e07
Merge pull request #897 from redboltz/re_enable_werror
Propagated CXXFLAGS.
2020-07-02 17:39:56 +09:00
Takatoshi Kondo
544978b343 Added conditional sanitize option. 2020-07-02 17:04:32 +09:00
Takatoshi Kondo
c8a053557c Propagated CXXFLAGS.
Fixed warnings.
2020-07-02 16:15:08 +09:00
Takatoshi Kondo
71687c4229
Merge pull request #895 from redboltz/add_f_sanitize_undefined_to_ci
Added -fsanitize=undefined option to ci.
2020-07-02 15:39:25 +09:00
Takatoshi Kondo
3557e6c9f9 Added -fsanitize=undefined option to ci. 2020-07-02 14:05:28 +09:00
Takatoshi Kondo
0e22de17b1 Merge branch 'ygj6-cpp_master' into cpp_master 2020-07-02 13:58:30 +09:00
Takatoshi Kondo
b0860a5f37 Fixed ptr size operation. 2020-07-02 13:34:00 +09:00
Takatoshi Kondo
447e8dfb07
Merge pull request #894 from redboltz/fix_fusion_warning
Fixed warning on fusion adaptor.
2020-07-02 09:48:56 +09:00
Takatoshi Kondo
8ee6df83cc Fixed warning on fusion adaptor. 2020-07-02 09:13:53 +09:00
Takatoshi Kondo
0168468ac8 Merge branch 'cpp_master' of https://github.com/ygj6/msgpack-c into cpp_master 2020-07-02 08:51:59 +09:00
yuangongji
ee29324fd5 check null pointer before using memcpy() 2020-07-01 20:44:15 +08:00
Takatoshi Kondo
194d1a470d
Merge pull request #893 from redboltz/fix_chrono_ub
Fixed undefined behavior in chrono converting.
2020-07-01 18:26:05 +09:00
Takatoshi Kondo
ebb5e0ceca Fixed undefined behavior in chrono converting.
Replaced static_cast with boost::numeric_cast to detect invalid cast
easier.
2020-07-01 16:22:01 +09:00
Takatoshi Kondo
f72c6c48f7
Merge pull request #892 from ygj6/dev
link lib32z1-dev when building 32-bit library
2020-07-01 12:47:56 +09:00
yuangongji
fc18087cdf link lib32z1-dev when building 32-bit library 2020-06-30 21:03:35 +08:00
Takatoshi Kondo
da2fc25f87
Merge pull request #888 from redboltz/fix_886_more_elegant
Improved clock adaptor.
2020-06-15 09:07:11 +09:00
Takatoshi Kondo
4629583662 Improved clock adaptor. 2020-06-14 18:47:03 +09:00
Takatoshi Kondo
c7b7e745b3
Merge pull request #887 from redboltz/impl_886
Added steady_clock and high_resolution_clock support.
2020-06-13 12:58:15 +09:00
Takatoshi Kondo
899d3319bf Removed code repeat. 2020-06-12 23:14:23 +09:00
Takatoshi Kondo
6eaf7fd38d Added steady_clock and high_resolution_clock support. 2020-06-12 22:16:19 +09:00
Takatoshi Kondo
01260a263d
Merge pull request #884 from redboltz/fix_gha_bardge
Replaced travis-ci badge with github actions badge.
2020-06-12 12:09:22 +09:00
Takatoshi Kondo
30ed4e35b7 Replaced travis-ci badge with github actions badge. 2020-06-12 11:33:13 +09:00
Takatoshi Kondo
44f2a6a56e
Merge pull request #883 from redboltz/support_complex
Added complex type support.
2020-06-12 10:08:24 +09:00
Takatoshi Kondo
3b80c45725 Added complex type support. 2020-06-10 13:26:40 +09:00
Takatoshi Kondo
6b197e7328
Merge pull request #882 from sharkcz/cpp-context
reduce boost::context requirement
2020-06-09 20:46:50 +09:00
Dan Horák
498fe28b43 reduce dependency on boost::context
The Boost Context module is required only for certain configurations, so adapt
the build system checks to it.
2020-06-09 12:48:19 +02:00
Takatoshi Kondo
ad9106e38b
Merge pull request #876 from ygj6/cpp_master
remove C library in cpp_master branch
2020-06-08 09:25:25 +09:00
yuangongji
7ca4ec95e5 update appveyor matrix and compatible with old msvc 2020-06-07 01:58:52 +08:00
yuangongji
2f5b137997 remove C part in source code 2020-06-05 18:12:03 +08:00
yuangongji
328be0b445 rename include/msgpack/*.h to include/msgpack/*.hpp
include/msgpack/sysdep.h => include/msgpack/sysdep.hpp
include/msgpack/unpack_define.h => include/msgpack/unpack_define.hpp
include/msgpack/version_master.h => include/msgpack/version_master.hpp

Use `git log --follow include/msgpack/filename.hpp` to see full log
2020-06-05 16:44:51 +08:00
yuangongji
689e6d053a remove C part files
remove the following files or folders:
ci/build_cmake_embedded.sh
example/c
example/cmake
include/msgpack/predef
include/msgpack/preprocessor.hpp
include/msgpack/preprocessor
include/msgpack/v1/preprocessor.hpp
include/msgpack.h
include/msgpack/fbuffer.h
include/msgpack/gcc_atomic.h
include/msgpack/object.h
include/msgpack/pack.h
include/msgpack/pack_define.h
include/msgpack/pack_template.h
include/msgpack/predef.h
include/msgpack/sbuffer.h
include/msgpack/timestamp.h
include/msgpack/unpack.h
include/msgpack/unpack_template.h
include/msgpack/util.h
include/msgpack/version.h
include/msgpack/vrefbuffer.h
include/msgpack/zbuffer.h
include/msgpack/zone.h
msgpack_vc8.sln
msgpack_vc8.vcproj
msgpack-config.cmake.in
msgpack.pc.in
src
test/fixint_c.cpp
test/msgpack_c.cpp
test/pack_unpack_c.cpp
test/streaming_c.cpp
.gitmodules
external
QUICKSTART-C.md
2020-06-05 16:44:51 +08:00
227 changed files with 6588 additions and 13309 deletions

View File

@ -1,23 +1,35 @@
#!/bin/sh
#!/bin/bash
usage()
{
cat <<EOL
-b - 32-bit or 64-bit library, maybe 32, 64 or both
-t - the toolset, maybe gcc, clang or both
-p - installation prefix
EOL
}
build_boost()
{
BASE=`pwd`/..
./b2 -j4 --toolset=$1 --prefix=${BASE}/usr --libdir="${BASE}/usr/$1/lib$2" --with-chrono --with-context --with-filesystem --with-system --with-timer address-model=$2 install
./b2 \
--toolset=$1 \
--prefix=$3/$2 \
--with-test \
--with-headers \
--with-chrono \
--with-context \
--with-filesystem \
--with-system \
--with-timer \
address-model=$2 \
install || exit 1
}
bit="64"
toolset="gcc"
prefix="$HOME/boost-prefix"
while getopts "b:t:" c; do
while getopts "b:t:p:" c; do
case "$c" in
b)
bit="$OPTARG"
@ -27,24 +39,28 @@ while getopts "b:t:" c; do
toolset="$OPTARG"
[ "$toolset" != "gcc" ] && [ "$toolset" != "clang" ] && [ "$toolset" != "both" ] && usage && exit 1
;;
p)
prefix="$OPTARG"
;;
?*)
echo "invalid arguments." && exit 1
;;
esac
done
wget https://dl.bintray.com/boostorg/release/1.71.0/source/boost_1_71_0.tar.bz2
tar xf boost_1_71_0.tar.bz2
cd boost_1_71_0
./bootstrap.sh
mkdir $prefix || exit 1
wget https://boostorg.jfrog.io/artifactory/main/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()
{
if [ "$bit" = "both" ]; then
build_boost $1 32
build_boost $1 64
build_boost $1 32 $prefix
build_boost $1 64 $prefix
else
build_boost $1 $bit
build_boost $1 $bit $prefix
fi
}

51
.github/depends/zlib.sh vendored Executable file
View File

@ -0,0 +1,51 @@
#!/bin/bash
usage()
{
cat <<EOL
-b - 32-bit or 64-bit library, maybe 32 or 64
-p - installation prefix
EOL
}
bit="64"
prefix="$HOME/zlib-prefix"
while getopts "b:t:p:" c; do
case "$c" in
b)
bit="$OPTARG"
[ "$bit" != "32" ] && [ "$bit" != "64" ] && [ "$bit" != "both" ] && usage && exit 1
;;
p)
prefix="$OPTARG"
;;
?*)
echo "invalid arguments." && exit 1
;;
esac
done
mkdir $prefix || exit 1
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()
{
cmake \
-D CMAKE_BUILD_TYPE=Release \
-D CMAKE_INSTALL_PREFIX=$2/$1 \
-D CMAKE_C_FLAGS="-m$1" \
-D CMAKE_SHARED_LINKER_FLAGS="-m$1" \
-B build$1 \
-S .
cmake --build build$1 --target install
}
if [ "$bit" = "both" ]; then
build 32 $prefix
build 64 $prefix
else
build $bit $prefix
fi

View File

@ -5,52 +5,64 @@ on:
types: [opened, synchronize]
push:
branches:
- master
- cpp_master
tags:
- '*'
jobs:
codecov:
timeout-minutes: 30
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: install depends
- name: Install build dependencies
run: |
sudo apt-get update
sudo apt-get install g++-multilib lcov
sudo apt-get install g++-10 cmake lcov -y
./ci/set_gcc_10.sh
- name: Cache boost
id: cache-boost
uses: actions/cache@v1
with:
path: usr
key: ${{ runner.os }}-boost-20200107
path: ~/boost-prefix/
key: ${{ runner.os }}-boost-1-85-0-2024-05-27
- name: Build boost
if: steps.cache-boost.outputs.cache-hit != 'true'
run: ./.github/depends/boost.sh -b both -t gcc
run: ./.github/depends/boost.sh -b 64 -t gcc -p $HOME/boost-prefix
- name: Cache zlib
id: cache-zlib
uses: actions/cache@v1
with:
path: ~/zlib-prefix/
key: ${{ runner.os }}-zlib-64-1-2-11-2021-08-09
- name: Build zlib
if: steps.cache-zlib.outputs.cache-hit != 'true'
run: ./.github/depends/zlib.sh -b 64 -p $HOME/zlib-prefix
- name: Compile tests
run: |
# install gtest
BASE=`pwd`
wget https://github.com/google/googletest/archive/release-1.7.0.zip -O googletest-release-1.7.0.zip
unzip -q googletest-release-1.7.0.zip
cd googletest-release-1.7.0
g++ -m64 src/gtest-all.cc -I. -Iinclude -c -fPIC
g++ -m64 src/gtest_main.cc -I. -Iinclude -c -fPIC
ar -rv libgtest.a gtest-all.o
ar -rv libgtest_main.a gtest_main.o
mkdir -p ${BASE}/usr/include
cp -r include/gtest ${BASE}/usr/include
mkdir -p ${BASE}/usr/lib
mv *.a ${BASE}/usr/lib
cd ..
mkdir build
cmake \
-D MSGPACK_CXX20=ON \
-D MSGPACK_32BIT=OFF \
-D MSGPACK_CHAR_SIGN=signed \
-D MSGPACK_USE_X3_PARSE=ON \
-D MSGPACK_BUILD_EXAMPLES=ON \
-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
mkdir build && cd build
CMAKE_LIBRARY_PATH="${BASE}/build" GTEST_ROOT="${BASE}/usr" CMAKE_PREFIX_PATH="${BASE}/usr/gcc/lib64/cmake" cmake -DMSGPACK_CXX17=ON -DMSGPACK_32BIT=OFF -DMSGPACK_BOOST=ON -DBUILD_SHARED_LIBS=ON -DMSGPACK_CHAR_SIGN=signed -DMSGPACK_USE_X3_PARSE=ON -DMSGPACK_ENABLE_CXX=ON -DMSGPACK_BUILD_EXAMPLES=ON -DMSGPACK_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Debug -DMSGPACK_GEN_COVERAGE=ON ..
make -j4
make test
- name: Upload coverage to Codecov
working-directory: build
run: |

View File

@ -5,300 +5,240 @@ on:
types: [opened, synchronize]
push:
branches:
- master
- cpp_master
tags:
- '*'
jobs:
macos:
name: ${{ format('macOS (pattern {0})', matrix.pattern) }}
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
pattern: [0, 1, 2, 3]
pattern: [0, 1, 2, 3, 4]
steps:
- uses: actions/checkout@v1
- 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@v1
uses: actions/cache@v3
with:
path: usr
key: ${{ runner.os }}-boost-20200107
path: ~/boost-prefix/
key: ${{ runner.os }}-boost-1-85-0-2024-05-27
- name: Build boost
if: steps.cache-boost.outputs.cache-hit != 'true'
run: ./.github/depends/boost.sh -b 64 -t clang
- name: build and test
env:
CC: clang
CXX: clang++
run: ./.github/depends/boost.sh -b 64 -t clang -p $HOME/boost-prefix
- name: Cache zlib
id: cache-zlib
uses: actions/cache@v3
with:
path: ~/zlib-prefix/
key: ${{ runner.os }}-zlib-1-2-13-2022-11-02
- name: Build zlib
if: steps.cache-zlib.outputs.cache-hit != 'true'
run: ./.github/depends/zlib.sh -b 64 -p $HOME/zlib-prefix
- name: Build and test
shell: bash
run: |
BASE=`pwd`;
# default configuration - overwrite its params later depending on matrix.pattern
export MSGPACK_CXX_VERSION="MSGPACK_CXX20=ON"
export ARCH=64
export API_VERSION=3
export CHAR_SIGN="signed"
export X3_PARSE="OFF"
export SANITIZE="-fsanitize=undefined -fno-sanitize-recover=all"
# matrix config
if [ ${{ matrix.pattern }} == 0 ]; then
ACTION="ci/build_cmake.sh"
export CXX17="ON"
export ARCH="64"
export BOOST="ON"
SHARED="ON"
export CHAR_SIGN="unsigned"
export API_VERSION="1"
fi
if [ ${{ matrix.pattern }} == 1 ]; then
ACTION="ci/build_cmake.sh"
export CXX17="ON"
export ARCH="64"
export BOOST="ON"
export SHARED="ON"
export CHAR_SIGN="signed"
export API_VERSION="3"
fi
if [ ${{ matrix.pattern }} == 2 ]; then
ACTION="ci/build_cmake.sh"
export CXX17="ON"
export ARCH="64"
export SHARED="ON"
export CHAR_SIGN="signed"
export API_VERSION="2"
fi
if [ ${{ matrix.pattern }} == 3 ]; then
ACTION="ci/build_cmake.sh"
export ARCH="64"
export SHARED="ON"
export CHAR_SIGN="unsigned"
export API_VERSION="2"
fi
# install gtest
wget https://github.com/google/googletest/archive/release-1.7.0.zip -O googletest-release-1.7.0.zip
unzip -q googletest-release-1.7.0.zip
cd googletest-release-1.7.0
$CXX -m${ARCH} src/gtest-all.cc -I. -Iinclude -c
$CXX -m${ARCH} src/gtest_main.cc -I. -Iinclude -c
ar -rv libgtest.a gtest-all.o
ar -rv libgtest_main.a gtest_main.o
mkdir -p ${BASE}/usr/include
cp -r include/gtest ${BASE}/usr/include
mkdir -p ${BASE}/usr/lib
mv *.a ${BASE}/usr/lib
cd ..
case ${{ matrix.pattern }} in
0)
export MSGPACK_CXX_VERSION="MSGPACK_CXX11=ON"
;;
1)
export API_VERSION=1
;;
2)
export API_VERSION=2
;;
3)
export X3_PARSE="ON"
;;
4)
export CHAR_SIGN="unsigned"
;;
esac
# build and test
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" CMAKE_LIBRARY_PATH="${BASE}/usr/lib:${BASE}/build" GTEST_ROOT="${BASE}/usr" CMAKE_PREFIX_PATH="${BASE}/usr/clang/lib${ARCH}/cmake" CFLAGS="-Werror -g" CXXFLAGS="-Werror -g" ${ACTION}
export CXX="clang++"
CMAKE_CXX_COMPILER="$CXX" CXXFLAGS="-Werror -g ${SANITIZE}" ci/build_cmake.sh || exit 1
cat Files.cmake| grep ".*\.[h|hpp]" | perl -pe 's/ //g' | sort > tmp1 && find include -name "*.h" -o -name "*.hpp" | sort > tmp2 && diff tmp1 tmp2
linux:
runs-on: ubuntu-18.04
name: ${{ format('Linux (pattern {0})', matrix.pattern) }}
runs-on: ubuntu-20.04
strategy:
fail-fast: false
matrix:
pattern: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11]
steps:
- uses: actions/checkout@v1
- name: install depends
run: |
sudo apt-get update
sudo apt-get install g++-multilib clang-8 valgrind
- name: Cache boost
id: cache-boost
uses: actions/cache@v1
with:
path: usr
key: ${{ runner.os }}-boost-20200107
- name: Build boost
if: steps.cache-boost.outputs.cache-hit != 'true'
run: ./.github/depends/boost.sh -b both -t gcc
- name: build and test
- uses: actions/checkout@v3
- name: Install build dependencies
shell: bash
run: |
BASE=`pwd`;
sudo apt-get update
sudo apt-get install g++-10 cmake valgrind -y
sudo apt-get install g++-10-multilib -y # for 32-bit compile
./ci/set_gcc_10.sh
# matrix config
if [ ${{ matrix.pattern }} == 0 ]; then
export CC=clang
export CXX=clang++
ACTION="ci/build_cmake.sh"
export ARCH="64"
export BOOST="ON"
export SHARED="ON"
export CHAR_SIGN="unsigned"
export API_VERSION="2"
fi
if [ ${{ matrix.pattern }} == 1 ]; then
export CC=clang
export CXX=clang++
ACTION="ci/build_cmake.sh"
export ARCH="32"
export SHARED="ON"
export CHAR_SIGN="signed"
export API_VERSION="2"
fi
if [ ${{ matrix.pattern }} == 2 ]; then
export CC=clang
export CXX=clang++
ACTION="ci/build_cmake.sh"
export CXX17="ON"
export ARCH="64"
export BOOST="ON"
export SHARED="ON"
export CHAR_SIGN="signed"
export API_VERSION="3"
export X3_PARSE="ON"
fi
if [ ${{ matrix.pattern }} == 3 ]; then
export CC=clang
export CXX=clang++
ACTION="ci/build_cmake.sh"
export CXX17="ON"
export ARCH="32"
export SHARED="OFF"
export CHAR_SIGN="unsigned"
export API_VERSION="2"
fi
if [ ${{ matrix.pattern }} == 4 ]; then
export CC=gcc
export CXX=g++
ACTION="ci/build_cmake.sh"
export CXX17="ON"
export ARCH="64"
export SHARED="ON"
export CHAR_SIGN="signed"
export API_VERSION="2"
fi
if [ ${{ matrix.pattern }} == 5 ]; then
export CC=gcc
export CXX=g++
ACTION="ci/build_cmake.sh"
export CXX17="ON"
export ARCH="32"
export BOOST="ON"
export SHARED="ON"
export CHAR_SIGN="unsigned"
export API_VERSION="3"
export X3_PARSE="ON"
fi
if [ ${{ matrix.pattern }} == 6 ]; then
export CC=gcc
export CXX=g++
ACTION="ci/build_cmake.sh"
export ARCH="64"
export SHARED="ON"
export CHAR_SIGN="unsigned"
export API_VERSION="2"
fi
if [ ${{ matrix.pattern }} == 7 ]; then
export CC=gcc
export CXX=g++
ACTION="ci/build_cmake.sh"
export ARCH="32"
export BOOST="ON"
export SHARED="OFF"
export CHAR_SIGN="signed"
export API_VERSION="1"
fi
if [ ${{ matrix.pattern }} == 8 ]; then
export CC=gcc
export CXX=g++
ACTION="ci/build_cmake.sh"
export ARCH="32"
export BOOST="ON"
export SHARED="OFF"
export CHAR_SIGN="signed"
export API_VERSION="2"
fi
if [ ${{ matrix.pattern }} == 9 ]; then
export CC=clang
export CXX=clang++
ACTION="ci/build_regression.sh"
export ARCH="64"
export SAN="UBSAN"
export MSGPACK_FUZZ_REGRESSION="ON"
export CTEST_OUTPUT_ON_FAILURE=1
fi
if [ ${{ matrix.pattern }} == 10 ]; then
export CC=clang
export CXX=clang++
ACTION="ci/build_regression.sh"
export ARCH="64"
export SAN="ASAN"
export MSGPACK_FUZZ_REGRESSION="ON"
export CTEST_OUTPUT_ON_FAILURE=1
fi
if [ ${{ matrix.pattern }} == 11 ]; then
export CC=gcc
export CXX=g++
ACTION="ci/build_cmake_embedded.sh"
export ARCH="64"
fi
- name: Cache boost
id: cache-boost
uses: actions/cache@v3
with:
path: ~/boost-prefix/
key: ${{ runner.os }}-boost-1-85-0-2024-05-27
# install gtest
wget https://github.com/google/googletest/archive/release-1.7.0.zip -O googletest-release-1.7.0.zip
unzip -q googletest-release-1.7.0.zip
cd googletest-release-1.7.0
$CXX -m${ARCH} src/gtest-all.cc -I. -Iinclude -c -fPIC
$CXX -m${ARCH} src/gtest_main.cc -I. -Iinclude -c -fPIC
ar -rv libgtest.a gtest-all.o
ar -rv libgtest_main.a gtest_main.o
mkdir -p ${BASE}/usr/include
cp -r include/gtest ${BASE}/usr/include
mkdir -p ${BASE}/usr/lib
mv *.a ${BASE}/usr/lib
cd ..
- name: Build boost
if: steps.cache-boost.outputs.cache-hit != 'true'
run: ./.github/depends/boost.sh -b both -t gcc -p $HOME/boost-prefix
# install zlib
if [ ${ARCH} == 32 ]; then
sudo apt-get install lib32z1-dev
fi
- name: Cache zlib
id: cache-zlib
uses: actions/cache@v3
with:
path: ~/zlib-prefix/
key: ${{ runner.os }}-zlib-1-2-13-2022-11-02
- name: Build zlib
if: steps.cache-zlib.outputs.cache-hit != 'true'
run: ./.github/depends/zlib.sh -b both -p $HOME/zlib-prefix
- name: Build and test
shell: bash
run: |
# default configuration - overwrite its params later depending on matrix.pattern
export MSGPACK_CXX_VERSION="MSGPACK_CXX20=ON"
export ARCH=64
export API_VERSION=3
export CHAR_SIGN="signed"
export X3_PARSE="OFF"
export SANITIZE="-fsanitize=undefined -fno-sanitize-recover=all"
export ACTION="ci/build_cmake.sh"
case ${{ matrix.pattern }} in
0)
export CXX="clang++-10"
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 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 MSGPACK_CXX_VERSION="MSGPACK_CXX20=ON"
export NO_BOOST="-DMSGPACK_NO_BOOST"
;;
5)
export CXX="g++-10"
export ARCH=32
;;
6)
export CXX="clang++-10"
export API_VERSION=2
;;
7)
export CXX="g++-10"
export API_VERSION=1
;;
8)
export CXX="clang++-10"
export CHAR_SIGN="unsigned"
;;
9)
export CXX="g++-10"
export X3_PARSE="ON"
;;
10)
export CXX="clang++-10"
export ACTION="ci/build_regression.sh"
;;
11)
export CXX="g++-10"
export ARCH=32
export CHAR_SIGN="unsigned"
export X3_PARSE="ON"
;;
esac
# build and test
CMAKE_CXX_COMPILER="${CXX}" CMAKE_C_COMPILER="${CC}" CMAKE_LIBRARY_PATH="${BASE}/usr/lib:${BASE}/build" GTEST_ROOT="${BASE}/usr" CMAKE_PREFIX_PATH="${BASE}/usr/gcc/lib${ARCH}/cmake" CFLAGS="-Werror -g" CXXFLAGS="-Werror -g" MSGPACK_SAN="${SAN}" ${ACTION}
CMAKE_CXX_COMPILER="$CXX" CXXFLAGS="-Werror -g ${SANITIZE} ${NO_BOOST}" ci/build_cmake.sh || exit 1
cat Files.cmake| grep ".*\.[h|hpp]" | perl -pe 's/ //g' | sort > tmp1 && find include -name "*.h" -o -name "*.hpp" | sort > tmp2 && diff tmp1 tmp2
windows:
runs-on: windows-2016
name: ${{ format('Windows cxx{0}', matrix.cxx) }}
runs-on: windows-2019
strategy:
fail-fast: false
matrix:
pattern: [0, 1, 2, 3]
# 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@v1
- name: Cache vcpkg
- uses: actions/checkout@v3
- name: Cache vcpkg dependencies
id: cache-vcpkg
uses: actions/cache@v1.0.3
uses: actions/cache@v3
with:
path: C:/vcpkg/installed/x64-windows
key: ${{ runner.os }}-vcpkg
- name: Build dependencies
key: ${{ runner.os }}-vcpkg-2021-08-09
- name: Install vcpkg dependencies
if: steps.cache-vcpkg.outputs.cache-hit != 'true'
shell: powershell
run: |
vcpkg install gtest:x64-windows
vcpkg update
vcpkg install zlib:x64-windows
vcpkg install boost-assert:x64-windows boost-numeric-conversion:x64-windows boost-variant:x64-windows boost-utility:x64-windows boost-fusion:x64-windows boost-optional:x64-windows boost-predef:x64-windows boost-preprocessor:x64-windows boost-timer:x64-windows boost-test:x64-windows
- name: Build and test
shell: powershell
run: |
if (${{ matrix.pattern }} -eq 0) {
$CPP11="-DMSGPACK_CXX11=OFF"
$BOOST="-DMSGPACK_BOOST=OFF"
}
if (${{ matrix.pattern }} -eq 1) {
$CPP11="-DMSGPACK_CXX11=OFF"
$BOOST="-DMSGPACK_BOOST=ON"
}
if (${{ matrix.pattern }} -eq 2) {
$CPP11="-DMSGPACK_CXX11=ON"
$BOOST="-DMSGPACK_BOOST=OFF"
}
if (${{ matrix.pattern }} -eq 3) {
$CPP11="-DMSGPACK_CXX11=ON"
$BOOST="-DMSGPACK_BOOST=ON"
}
$CPPVER="MSGPACK_CXX${{ matrix.cxx }}=ON"
$CUR=(Get-Location).Path
md build
cd build
cmake -A x64 -DBOOST_ROOT="$env:BOOST_ROOT_1_72_0" -DCMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" $CPP11 $BOOST "-DCMAKE_CXX_FLAGS=/D_VARIADIC_MAX=10 /EHsc /D_SILENCE_TR1_NAMESPACE_DEPRECATION_WARNING" ..
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
cmake --build . --config Release
$pathbak="$env:PATH"
$env:PATH="C:\vcpkg\installed\x64-windows\bin;$CUR\build\Release;$pathbak"
ctest -V
if ($LastExitCode -ne 0) { $host.SetShouldExit($LastExitCode) }
$env:PATH=$pathbak
cmake `
-A x64 `
-G "Visual Studio 16 2019" `
-D CMAKE_TOOLCHAIN_FILE="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" `
-D MSGPACK_BUILD_TESTS=ON `
-D $CPPVER `
-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 }
cmake --build build --config Release
if ($LastExitCode -ne 0) { exit $LastExitCode }
ctest -VV --test-dir build -C Release
if ($LastExitCode -ne 0) { exit $LastExitCode }

5
.gitignore vendored
View File

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

6
.gitmodules vendored
View File

@ -1,6 +0,0 @@
[submodule "external/boost/predef"]
path = external/boost/predef
url = https://github.com/boostorg/predef.git
[submodule "external/boost/preprocessor"]
path = external/boost/preprocessor
url = https://github.com/boostorg/preprocessor.git

View File

@ -1,3 +1,84 @@
# 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)
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)
# 2022-02-12 version 4.1.0 for C++
* Add experimental support for no boost dependency (#1001)
* For cmake, add `-DMSGPACK_USE_BOOST=OFF`. For C++ compiler add `-DMSGPACK_NO_BOOST`.
* Improve BIN console output (#995)
* Fix include notation (#991)
# 2021-10-23 version 4.0.3 for C++
* Remove Enabler2 template parameter from object adaptor (#987)
* Add MSGPACK_BUILD_DOCS cmake option (#983, #984)
# 2021-08-31 version 4.0.2 for C++
* Fix fuzzer interface function name (#972)
* Fix boost test link error and support both dynamin(default) and static link boost (#971)
# 2021-08-30 version 4.0.1 for C++
* Fix release tarball and its generation script (#967)
# 2021-08-29 version 4.0.0 for C++
* Improve zone alignment logic (#965)
* Fix v1 unpack logic for STR and BIN (#957, #951)
* Fix UB on memcmp with size 0 (#954)
* Fix `iovec` name conflict (#952)
* Add `std::array<std::byte>` `std::span<char>` `std::span<unsigned char>` `std::span<std::byte>` adaptors (#951)
* Improve documents (#918, #919, #951)
* Improve tests (#916)
* Introduce BOOST_ASSERT (#898)
* Improve build system (#897, #905, #924, #951)
* Improve Boost.Fusion support (#894)
* Check nullptr before call memcpy (#891)
* Refine and bugfix `std::chrono::time_point` adaptor (#888, #893)
* Improve CI (#884, #892, #895, #951, #955)
## << breaking changes >>
* Separate C++ part of the msgpack-c from C/C++ mixed msgpack-c (#876, #878)
* Require boost libraries. See README.md Dependency(#912)
# 2020-06-05 version 3.3.0
* Add json example for C (#870)
* Add both header and body packing functions for C (#870)

View File

@ -1,13 +1,18 @@
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12)
if(${CMAKE_VERSION} VERSION_GREATER "3.4")
CMAKE_MINIMUM_REQUIRED (VERSION 3.5)
else()
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.12)
IF ((CMAKE_VERSION VERSION_GREATER 3.1) OR
(CMAKE_VERSION VERSION_EQUAL 3.1))
CMAKE_POLICY(SET CMP0054 NEW)
ENDIF ()
endif()
IF ((CMAKE_VERSION VERSION_GREATER 3.1) OR
(CMAKE_VERSION VERSION_EQUAL 3.1))
CMAKE_POLICY(SET CMP0054 NEW)
ENDIF ()
PROJECT (msgpack-cxx LANGUAGES CXX)
PROJECT (msgpack)
ADD_LIBRARY (msgpack-cxx INTERFACE)
FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/version_master.h contents)
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})
SET (VERSION_MAJOR ${CMAKE_MATCH_1})
STRING (REGEX MATCH "#define MSGPACK_VERSION_MINOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents})
@ -17,195 +22,95 @@ SET (VERSION_REVISION ${CMAKE_MATCH_1})
SET (VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
LIST (APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
SET (prefix ${CMAKE_INSTALL_PREFIX})
SET (exec_prefix "\${prefix}")
SET (libdir "\${exec_prefix}/lib")
SET (includedir "\${prefix}/include")
SET (GNUCXX_STD_SUPPORT_VERSION "4.3")
OPTION (MSGPACK_CXX11 "Using c++11 compiler" OFF)
OPTION (MSGPACK_32BIT "32bit compile" OFF)
OPTION (MSGPACK_BOOST "Using boost libraries" 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)
IF (APPLE)
SET(CMAKE_MACOSX_RPATH ON)
SET(CMAKE_SKIP_BUILD_RPATH FALSE)
SET(CMAKE_BUILD_WITH_INSTALL_RPATH FALSE)
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
SET(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)
LIST(FIND CMAKE_PLATFORM_IMPLICIT_LINK_DIRECTORIES "${CMAKE_INSTALL_PREFIX}/lib" isSystemDir)
IF ("${isSystemDir}" STREQUAL "-1")
SET(CMAKE_INSTALL_RPATH "${CMAKE_INSTALL_PREFIX}/lib")
ENDIF ()
ENDIF ()
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)
IF (MSGPACK_USE_X3_PARSE)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_X3_PARSE -std=c++14 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_X3_PARSE -std=c++14 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_X3_PARSE ${CMAKE_CXX_FLAGS}")
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++14.")
ENDIF ()
ENDIF ()
IF (NOT (MSGPACK_CXX14 OR MSGPACK_CXX17 OR MSGPACK_CXX20))
MESSAGE (FATAL_ERROR "MSGPACK_USE_X3_PARSE requires MSGPACK_CXX14 or newer")
ENDIF ()
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_X3_PARSE ${CMAKE_CXX_FLAGS}")
ENDIF ()
IF (MSGPACK_CXX20)
SET (CMAKE_CXX_STANDARD 20)
ELSEIF (MSGPACK_CXX17)
SET (CMAKE_CXX_STANDARD 17)
ELSEIF (MSGPACK_CXX14)
SET (CMAKE_CXX_STANDARD 14)
ELSEIF (MSGPACK_CXX11)
SET (CMAKE_CXX_STANDARD 11)
ELSE ()
IF (MSGPACK_CXX17)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET (CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-std=c++17 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++17.")
ENDIF ()
ELSEIF (MSGPACK_CXX11)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 19)
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++11.")
ENDIF ()
ENDIF ()
ELSE ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
IF ((CMAKE_CXX_COMPILER_VERSION VERSION_GREATER ${GNUCXX_STD_SUPPORT_VERSION}) OR
(CMAKE_CXX_COMPILER_VERSION VERSION_EQUAL ${GNUCXX_STD_SUPPORT_VERSION}))
SET (CMAKE_CXX_FLAGS "-std=c++98 ${CMAKE_CXX_FLAGS}")
ENDIF ()
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-std=c++98 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_CXX_COMPILER_VERSION VERSION_GREATER 18)
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_CPP03 ${CMAKE_CXX_FLAGS}")
ENDIF ()
ENDIF ()
ENDIF ()
SET (CMAKE_CXX_STANDARD 98)
ENDIF ()
IF (MSGPACK_32BIT)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET (CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
SET (CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
SET (CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
TARGET_COMPILE_OPTIONS(msgpack-cxx INTERFACE -m32)
TARGET_LINK_OPTIONS(msgpack-cxx INTERFACE -m32)
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
TARGET_COMPILE_OPTIONS(msgpack-cxx INTERFACE -m32)
TARGET_LINK_OPTIONS(msgpack-cxx INTERFACE -m32)
ENDIF ()
ENDIF ()
OPTION (MSGPACK_BUILD_EXAMPLES "Build msgpack examples." ON)
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_BOOST)
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_BOOST ${CMAKE_CXX_FLAGS}")
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE (Boost REQUIRED COMPONENTS chrono context system timer)
INCLUDE_DIRECTORIES (
${Boost_INCLUDE_DIRS}
)
LINK_DIRECTORIES (
${Boost_LIBRARY_DIRS}
)
IF (MSGPACK_BOOST_DIR)
INCLUDE_DIRECTORIES (
${MSGPACK_BOOST_DIR}
)
ENDIF ()
IF (MSGPACK_USE_STATIC_BOOST)
MESSAGE (STATUS "Staticly linking with Boost")
SET (Boost_USE_STATIC_LIBS TRUE)
ELSE ()
MESSAGE (STATUS "Dynamically linking with Boost")
SET (Boost_USE_STATIC_LIBS FALSE)
ENDIF ()
FIND_PACKAGE (Boost REQUIRED)
ELSE ()
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_NO_BOOST)
ENDIF ()
IF (MSGPACK_CHAR_SIGN)
SET (CMAKE_C_FLAGS "-f${MSGPACK_CHAR_SIGN}-char ${CMAKE_C_FLAGS}")
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 (CMAKE_CXX_FLAGS "-DMSGPACK_DEFAULT_API_VERSION=3 ${CMAKE_CXX_FLAGS}")
SET (MSGPACK_DEFAULT_API_VERSION 3)
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_DEFAULT_API_VERSION=3)
ENDIF ()
FILE (GLOB_RECURSE PREDEF_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost/*.h)
FOREACH (F ${PREDEF_FILES})
SET(M "Converting ${F}")
MESSAGE(STATUS ${M})
FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/predef/include/boost/${F} CONTENT)
STRING(REPLACE "BOOST_" "MSGPACK_" CONTENT ${CONTENT})
STRING(REPLACE "boost/" "msgpack/" CONTENT ${CONTENT})
FILE (GENERATE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/${F} CONTENT ${CONTENT})
ENDFOREACH ()
FILE (GLOB_RECURSE PREPROCESSOR_FILES RELATIVE ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/preprocessor/include/boost ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/preprocessor/include/boost/*.hpp)
FOREACH (F ${PREPROCESSOR_FILES})
SET(M "Converting ${F}")
MESSAGE(STATUS ${M})
FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/external/boost/preprocessor/include/boost/${F} CONTENT)
STRING(REPLACE "BOOST_" "MSGPACK_" CONTENT ${CONTENT})
STRING(REPLACE "boost/" "msgpack/" CONTENT ${CONTENT})
FILE (GENERATE OUTPUT ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/${F} CONTENT ${CONTENT})
ENDFOREACH ()
FIND_PACKAGE (GTest)
FIND_PACKAGE (ZLIB)
FIND_PACKAGE (Threads)
IF (GTEST_FOUND AND ZLIB_FOUND AND THREADS_FOUND AND NOT "${MSGPACK_FUZZ_REGRESSION}" STREQUAL "ON")
OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON)
OPTION (MSGPACK_GEN_COVERAGE "Enable running gcov to get a test coverage report." OFF)
IF (MSGPACK_USE_STD_VARIANT_ADAPTOR)
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_USE_STD_VARIANT_ADAPTOR)
ENDIF ()
OPTION (MSGPACK_ENABLE_CXX "Enable C++ interface." ON)
OPTION (MSGPACK_CXX_ONLY "Build only C++ libraries (header-only)." OFF)
IF (MSGPACK_CXX_ONLY)
IF (DEFINED MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_SHARED)
MESSAGE(WARNING "MSGPACK_ENABLE_SHARED is overridden to OFF by MSGPACK_CXX_ONLY")
ENDIF ()
SET (MSGPACK_ENABLE_SHARED OFF)
IF (DEFINED MSGPACK_ENABLE_STATIC AND MSGPACK_ENABLE_STATIC)
MESSAGE(WARNING "MSGPACK_ENABLE_STATIC is overridden to OFF by MSGPACK_CXX_ONLY")
ENDIF ()
SET (MSGPACK_ENABLE_STATIC OFF)
IF (DEFINED MSGPACK_ENABLE_CXX AND NOT MSGPACK_ENABLE_CXX)
MESSAGE(WARNING "MSGPACK_ENABLE_CXX is overridden to ON by MSGPACK_CXX_ONLY")
ENDIF ()
SET (MSGPACK_ENABLE_CXX ON)
ELSE ()
IF (DEFINED BUILD_SHARED_LIBS)
IF (BUILD_SHARED_LIBS)
IF (DEFINED MSGPACK_ENABLE_SHARED AND NOT MSGPACK_ENABLE_SHARED)
MESSAGE(WARNING "MSGPACK_ENABLE_SHARED is overridden to ON by BUILD_SHARED_LIBS")
ENDIF ()
SET (MSGPACK_ENABLE_SHARED ON)
IF (DEFINED MSGPACK_ENABLE_STATIC AND MSGPACK_ENABLE_STATIC)
MESSAGE(WARNING "MSGPACK_ENABLE_STATIC is overridden to OFF by BUILD_SHARED_LIBS")
ENDIF ()
SET (MSGPACK_ENABLE_STATIC OFF)
ELSE ()
IF (DEFINED MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_SHARED)
MESSAGE(WARNING "MSGPACK_ENABLE_SHARED is overridden to OFF by BUILD_SHARED_LIBS")
ENDIF ()
SET (MSGPACK_ENABLE_SHARED OFF)
IF (DEFINED MSGPACK_ENABLE_STATIC AND NOT MSGPACK_ENABLE_STATIC)
MESSAGE(WARNING "MSGPACK_ENABLE_STATIC is overridden to ON by BUILD_SHARED_LIBS")
ENDIF ()
SET (MSGPACK_ENABLE_STATIC ON)
ENDIF ()
ELSE ()
IF (NOT DEFINED MSGPACK_ENABLE_SHARED)
SET (MSGPACK_ENABLE_SHARED ON)
ENDIF ()
IF (NOT DEFINED MSGPACK_ENABLE_STATIC)
SET (MSGPACK_ENABLE_STATIC ON)
ENDIF ()
SET (BUILD_SHARED_LIBS ${MSGPACK_ENABLE_SHARED})
ENDIF ()
ENDIF ()
INCLUDE (CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES ("
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
IF (CMAKE_CXX_COMPILER_VERSION VERSION_LESS 4.1)
INCLUDE (CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES ("
#include <bits/atomicity.h>
int atomic_sub(int i) { return __gnu_cxx::__exchange_and_add(&i, -1) - 1; }
int atomic_add(int i) { return __gnu_cxx::__exchange_and_add(&i, 1) + 1; }
@ -214,275 +119,150 @@ int main(int argc, char * argv[])
atomic_sub(1);
atomic_add(1);
}
" MSGPACK_ENABLE_GCC_CXX_ATOMIC)
INCLUDE (Files.cmake)
EXECUTE_PROCESS (
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/src/msgpack
)
CONFIGURE_FILE (
msgpack.pc.in
msgpack.pc
@ONLY
)
IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC)
ADD_LIBRARY (msgpackc
${msgpackc_SOURCES}
${msgpackc_HEADERS}
)
SET_TARGET_PROPERTIES (msgpackc PROPERTIES SOVERSION 2 VERSION 2.0.0)
TARGET_INCLUDE_DIRECTORIES (msgpackc
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
ENDIF ()
IF (MSGPACK_ENABLE_CXX AND ((CMAKE_VERSION VERSION_GREATER 3.0) OR (CMAKE_VERSION VERSION_EQUAL 3.0)))
ADD_LIBRARY (msgpackc-cxx INTERFACE)
TARGET_INCLUDE_DIRECTORIES (msgpackc-cxx
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
ENDIF ()
IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC)
ADD_LIBRARY (msgpackc-static STATIC
${msgpackc_SOURCES}
${msgpackc_HEADERS}
)
TARGET_INCLUDE_DIRECTORIES (msgpackc-static
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
PRIVATE
${CMAKE_CURRENT_SOURCE_DIR}
)
SET_TARGET_PROPERTIES (msgpackc-static PROPERTIES OUTPUT_NAME "msgpackc")
IF (MSGPACK_ENABLE_SHARED)
IF (MSVC)
SET_TARGET_PROPERTIES (msgpackc PROPERTIES IMPORT_SUFFIX "_import.lib")
ELSEIF (MINGW)
SET_TARGET_PROPERTIES (msgpackc PROPERTIES IMPORT_SUFFIX ".dll.a")
ENDIF ()
"
MSGPACK_ENABLE_GCC_CXX_ATOMIC)
ENDIF ()
ENDIF ()
# enable regression testing
IF ("${MSGPACK_FUZZ_REGRESSION}" STREQUAL "ON" AND "${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-DMSGPACK_USE_BOOST ${CMAKE_CXX_FLAGS}")
SET (Boost_USE_MULTITHREADED ON)
SET (Boost_USE_STATIC_RUNTIME OFF)
enable_testing ()
ADD_SUBDIRECTORY (fuzz)
SET (MSGPACK_BUILD_EXAMPLES OFF)
INCLUDE (Files.cmake)
TARGET_INCLUDE_DIRECTORIES (msgpack-cxx
INTERFACE
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>
$<INSTALL_INTERFACE:include>
)
IF (MSGPACK_USE_BOOST)
TARGET_LINK_LIBRARIES (msgpack-cxx INTERFACE Boost::boost)
ENDIF ()
IF (MSGPACK_GEN_COVERAGE)
IF (NOT MSGPACK_BUILD_TESTS)
MESSAGE(FATAL_ERROR "Coverage requires -DMSGPACK_BUILD_TESTS=ON")
ENDIF ()
STRING(TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_CMAKE_BUILD_TYPE)
STRING (TOUPPER "${CMAKE_BUILD_TYPE}" UPPER_CMAKE_BUILD_TYPE)
IF (NOT "${UPPER_CMAKE_BUILD_TYPE}" STREQUAL "DEBUG")
MESSAGE(FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug")
MESSAGE (FATAL_ERROR "Coverage requires -DCMAKE_BUILD_TYPE=Debug")
ENDIF ()
INCLUDE(CodeCoverage)
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${COVERAGE_FLAGS}")
INCLUDE (CodeCoverage)
SET (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${COVERAGE_FLAGS}")
SETUP_TARGET_FOR_COVERAGE(coverage make coverage test)
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 ()
# 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)
FIND_PROGRAM (CTEST_MEMORYCHECK_COMMAND NAMES valgrind)
INCLUDE (Dart)
ADD_SUBDIRECTORY (test)
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC)
SET_PROPERTY (TARGET msgpackc APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra -DPIC")
ENDIF ()
IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC)
SET_PROPERTY (TARGET msgpackc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra" )
ENDIF ()
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC)
SET_PROPERTY (TARGET msgpackc APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()
IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC)
SET_PROPERTY (TARGET msgpackc-static APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE ()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3 /WX")
ENDIF ()
ENDIF ()
IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_C_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
ELSE ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX")
ENDIF ()
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC90" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC10")
SET_SOURCE_FILES_PROPERTIES(${msgpackc_SOURCES} PROPERTIES LANGUAGE CXX)
# enable regression testing
IF (MSGPACK_FUZZ_REGRESSION)
ENABLE_TESTING ()
ADD_SUBDIRECTORY (fuzz)
ENDIF ()
IF ("${CMAKE_SYSTEM_PROCESSOR}" STREQUAL "sparc")
SET (CMAKE_C_FLAGS "-DMSGPACK_ZONE_ALIGN=8 ${CMAKE_C_FLAGS}")
SET (CMAKE_CXX_FLAGS "-DMSGPACK_ZONE_ALIGN=8 ${CMAKE_CXX_FLAGS}")
ENDIF ()
IF (NOT DEFINED CMAKE_INSTALL_BINDIR)
SET(CMAKE_INSTALL_BINDIR bin)
ENDIF ()
IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
SET(CMAKE_INSTALL_LIBDIR lib)
TARGET_COMPILE_DEFINITIONS(msgpack-cxx INTERFACE MSGPACK_ZONE_ALIGN=8)
ENDIF ()
IF (MSGPACK_BUILD_EXAMPLES)
ADD_SUBDIRECTORY (example)
ENDIF ()
IF (MSGPACK_ENABLE_SHARED OR MSGPACK_ENABLE_STATIC)
SET (MSGPACK_INSTALLTARGETS msgpackc)
ENDIF ()
IF (MSGPACK_ENABLE_CXX AND ((CMAKE_VERSION VERSION_GREATER 3.0) OR (CMAKE_VERSION VERSION_EQUAL 3.0)))
LIST (APPEND MSGPACK_INSTALLTARGETS msgpackc-cxx)
ENDIF ()
IF (MSGPACK_ENABLE_SHARED AND MSGPACK_ENABLE_STATIC)
LIST (APPEND MSGPACK_INSTALLTARGETS msgpackc-static)
ENDIF ()
INSTALL (TARGETS ${MSGPACK_INSTALLTARGETS} EXPORT msgpack-targets
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)
FOREACH (file ${msgpackc_HEADERS})
GET_FILENAME_COMPONENT (dir ${file} PATH)
INSTALL (FILES ${file} DESTINATION ${CMAKE_INSTALL_PREFIX}/${dir})
ENDFOREACH ()
IF (NOT MSGPACK_CXX_ONLY AND NOT MSVC)
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/msgpack.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
ENDIF ()
# Doxygen
FIND_PACKAGE (Doxygen)
IF (DOXYGEN_FOUND)
LIST (APPEND Doxyfile_c_CONTENT
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.h" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_c" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "EXTRACT_ALL = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "STRIP_FROM_PATH = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
)
IF (DOXYGEN_DOT_FOUND)
LIST (APPEND Doxyfile_c_CONTENT
COMMAND ${CMAKE_COMMAND} -E echo "HAVE_DOT = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
)
ENDIF ()
ADD_CUSTOM_TARGET (
doxygen_c
${Doxyfile_c_CONTENT}
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
VERBATIM
)
LIST (APPEND Doxyfile_cpp_CONTENT
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.hpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_cpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "EXTRACT_ALL = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "STRIP_FROM_PATH = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
)
IF (DOXYGEN_DOT_FOUND)
IF (MSGPACK_BUILD_DOCS)
FIND_PACKAGE (Doxygen)
IF (DOXYGEN_FOUND)
LIST (APPEND Doxyfile_cpp_CONTENT
COMMAND ${CMAKE_COMMAND} -E echo "HAVE_DOT = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.hpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_cpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "EXTRACT_ALL = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "STRIP_FROM_PATH = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
)
IF (DOXYGEN_DOT_FOUND)
LIST (APPEND Doxyfile_cpp_CONTENT
COMMAND ${CMAKE_COMMAND} -E echo "HAVE_DOT = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
)
ENDIF ()
ADD_CUSTOM_TARGET (
doxygen
${Doxyfile_cpp_CONTENT}
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C++\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
VERBATIM
)
ENDIF ()
ADD_CUSTOM_TARGET (
doxygen_cpp
${Doxyfile_cpp_CONTENT}
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C++\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
VERBATIM
)
ADD_CUSTOM_TARGET (
doxygen
DEPENDS doxygen_c doxygen_cpp
)
ENDIF ()
include (GNUInstallDirs)
# Install library.
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}"
)
# Install headers from source tree.
INSTALL (DIRECTORY include/
DESTINATION include
COMPONENT msgpack-cxx
)
INCLUDE (CMakePackageConfigHelpers)
SET (CMAKE_INSTALL_CMAKEDIR "${CMAKE_INSTALL_LIBDIR}/cmake/msgpack")
IF (NOT (CMAKE_VERSION VERSION_LESS 3.14))
SET (extra_version_file_args ARCH_INDEPENDENT)
ENDIF ()
SET (cmake_config_path "${CMAKE_INSTALL_LIBDIR}/cmake/msgpack-cxx")
# Configure the main package file from source tree.
CONFIGURE_PACKAGE_CONFIG_FILE (
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}
)
IF (NOT CMAKE_VERSION VERSION_LESS 3.0)
EXPORT (EXPORT msgpack-targets
FILE "${CMAKE_CURRENT_BINARY_DIR}/msgpack-targets.cmake"
)
ENDIF ()
CONFIGURE_PACKAGE_CONFIG_FILE (msgpack-config.cmake.in
msgpack-config.cmake
INSTALL_DESTINATION "${CMAKE_INSTALL_CMAKEDIR}"
# Install the generated package version file and the main package file.
INSTALL (FILES
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-cxx-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-cxx-config-version.cmake"
DESTINATION "${cmake_config_path}"
COMPONENT msgpack-cxx
)
IF (NOT MSGPACK_CXX_ONLY)
INSTALL (EXPORT msgpack-targets
FILE
msgpack-targets.cmake
DESTINATION
"${CMAKE_INSTALL_CMAKEDIR}"
)
INSTALL (
FILES
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-config.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/msgpack-config-version.cmake"
DESTINATION
"${CMAKE_INSTALL_CMAKEDIR}"
)
ENDIF ()
# This installs package in install tree for using installed targets.
INSTALL (
EXPORT msgpack-cxx-targets
FILE msgpack-cxx-targets.cmake
DESTINATION "${cmake_config_path}"
COMPONENT msgpack-cxx
)

File diff suppressed because it is too large Load Diff

View File

@ -1,191 +0,0 @@
# Implementation Status
The serialization library is production-ready.
Currently, RPC implementation is not available.
# Install
## Install with package manager
### MacOS with MacPorts
On MacOS, you can install MessagePack for C using MacPorts.
```
$ sudo port install msgpack
```
You might need to run `sudo port selfupdate` before installing to update the package repository.
You can also install via Homebrew.
```
$ brew install msgpack
```
### FreeBSD with Ports Collection
On FreeBSD, you can use Ports Collection. Install [net/msgpack](http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/msgpack/) package.
### Gentoo Linux with Portage
On Gentoo Linux, you can use emerge. Install [dev-libs/msgpack](http://gentoo-portage.com/dev-libs/msgpack) package.
### Windows with vcpkg
There are several package managers available, and vcpkg is typical.
```
$ vcpkg install msgpack:x64-windows
```
## Install with source code
### Build with cmake
You need to install cmake (2.8.12 or higher) first.
```
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ mkdir build
$ cd build
$ cmake ..
$ cmake --build .
$ cmake --build . --target install
```
### Build with autotools
In versions 1.4.2 and below, you can use `autotools` to build on UNIX-like platforms.
```
$ wget https://github.com/msgpack/msgpack-c/archive/cpp-1.3.0.tar.gz
$ tar zxvf msgpack-1.3.0.tar.gz
$ cd msgpack-1.3.0
$ ./bootstrap # If the 'configure' script already exists, you can omit this step.
$ ./configure
$ make
$ sudo make install
```
# Serialization QuickStart for C
## First program
Include `msgpack.h` header and link `msgpack` library to use MessagePack on your program.
```c
#include <msgpack.h>
#include <stdio.h>
int main(void) {
/* creates buffer and serializer instance. */
msgpack_sbuffer* buffer = msgpack_sbuffer_new();
msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
/* serializes ["Hello", "MessagePack"]. */
msgpack_pack_array(pk, 2);
msgpack_pack_bin(pk, 5);
msgpack_pack_bin_body(pk, "Hello", 5);
msgpack_pack_bin(pk, 11);
msgpack_pack_bin_body(pk, "MessagePack", 11);
/* deserializes it. */
msgpack_unpacked msg;
msgpack_unpacked_init(&msg);
msgpack_unpack_return ret = msgpack_unpack_next(&msg, buffer->data, buffer->size, NULL);
/* prints the deserialized object. */
msgpack_object obj = msg.data;
msgpack_object_print(stdout, obj); /*=> ["Hello", "MessagePack"] */
/* cleaning */
msgpack_sbuffer_free(buffer);
msgpack_packer_free(pk);
}
```
## Simple program with a loop
```c
#include <msgpack.h>
#include <stdio.h>
int main(void) {
/* creates buffer and serializer instance. */
msgpack_sbuffer* buffer = msgpack_sbuffer_new();
msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
int j;
for(j = 0; j<23; j++) {
/* NB: the buffer needs to be cleared on each iteration */
msgpack_sbuffer_clear(buffer);
/* serializes ["Hello", "MessagePack"]. */
msgpack_pack_array(pk, 3);
msgpack_pack_bin(pk, 5);
msgpack_pack_bin_body(pk, "Hello", 5);
msgpack_pack_bin(pk, 11);
msgpack_pack_bin_body(pk, "MessagePack", 11);
msgpack_pack_int(pk, j);
/* deserializes it. */
msgpack_unpacked msg;
msgpack_unpacked_init(&msg);
msgpack_unpack_return ret = msgpack_unpack_next(&msg, buffer->data, buffer->size, NULL);
/* prints the deserialized object. */
msgpack_object obj = msg.data;
msgpack_object_print(stdout, obj); /*=> ["Hello", "MessagePack"] */
puts("");
}
/* cleaning */
msgpack_sbuffer_free(buffer);
msgpack_packer_free(pk);
}
```
## Streaming feature
```c
#include <msgpack.h>
#include <stdio.h>
int main(void) {
/* serializes multiple objects using msgpack_packer. */
msgpack_sbuffer* buffer = msgpack_sbuffer_new();
msgpack_packer* pk = msgpack_packer_new(buffer, msgpack_sbuffer_write);
msgpack_pack_int(pk, 1);
msgpack_pack_int(pk, 2);
msgpack_pack_int(pk, 3);
/* deserializes these objects using msgpack_unpacker. */
msgpack_unpacker pac;
msgpack_unpacker_init(&pac, MSGPACK_UNPACKER_INIT_BUFFER_SIZE);
/* feeds the buffer. */
msgpack_unpacker_reserve_buffer(&pac, buffer->size);
memcpy(msgpack_unpacker_buffer(&pac), buffer->data, buffer->size);
msgpack_unpacker_buffer_consumed(&pac, buffer->size);
/* now starts streaming deserialization. */
msgpack_unpacked result;
msgpack_unpacked_init(&result);
while(msgpack_unpacker_next(&pac, &result)) {
msgpack_object_print(stdout, result.data);
puts("");
}
/* results:
* $ gcc stream.cc -lmsgpackc -o stream
* $ ./stream
* 1
* 2
* 3
*/
}
```

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>

196
README.md
View File

@ -1,8 +1,8 @@
`msgpack` for C/C++
`msgpack` for C++
===================
Version 3.3.0 [![Build Status](https://travis-ci.org/msgpack/msgpack-c.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-c) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/master?svg=true)](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master)
[![codecov](https://codecov.io/gh/msgpack/msgpack-c/branch/master/graph/badge.svg)](https://codecov.io/gh/msgpack/msgpack-c)
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://codecov.io/gh/msgpack/msgpack-c/branch/cpp_master)
It's like JSON but smaller and faster.
@ -18,51 +18,6 @@ addition to the strings themselves.
Example
-------
In C:
```c
#include <msgpack.h>
#include <stdio.h>
int main(void)
{
/* msgpack::sbuffer is a simple buffer implementation. */
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
/* serialize values into the buffer using msgpack_sbuffer_write callback function. */
msgpack_packer pk;
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_array(&pk, 3);
msgpack_pack_int(&pk, 1);
msgpack_pack_true(&pk);
msgpack_pack_str(&pk, 7);
msgpack_pack_str_body(&pk, "example", 7);
/* deserialize the buffer into msgpack_object instance. */
/* deserialized object is valid during the msgpack_zone instance alive. */
msgpack_zone mempool;
msgpack_zone_init(&mempool, 2048);
msgpack_object deserialized;
msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized);
/* print the deserialized object. */
msgpack_object_print(stdout, deserialized);
puts("");
msgpack_zone_destroy(&mempool);
msgpack_sbuffer_destroy(&sbuf);
return 0;
}
```
See [`QUICKSTART-C.md`](./QUICKSTART-C.md) for more details.
In C++:
```c++
#include <msgpack.hpp>
#include <string>
@ -108,76 +63,145 @@ int main()
See [`QUICKSTART-CPP.md`](./QUICKSTART-CPP.md) for more details.
Dependency
----------
msgpack-c requires [boost library](https://www.boost.org/).
C++ version of msgpack-c itself is a header-only library and depends only on
boost headers. Tests depend on boost unit test framework and are linked with
it, so if you want to build them, you need to have this dependency installed.
Experimental support for removing boost dependency
For cmake:
```
cmake -DMSGPACK_USE_BOOST=OFF ..
```
NOTE: `-DMSGPACK_BUILD_TESTS=ON` doesn't work with `-DMSGPACK_USE_BOOST=OFF`.
For C++ compiler
```
clang++ -DMSGPACK_NO_BOOST your_code.cpp
```
Usage
-----
### C++ Header Only Library
- If you build your project with cmake, you can find msgpack-c with a
canonical cmake-way:
When you use msgpack on C++, you can just add
msgpack-c/include to your include path:
```cmake
# ...
find_package(msgpack REQUIRED)
# ...
target_link_libraries(your_target_name <PRIVATE/PUBLIC/INTERFACE> msgpack-cxx)
# ...
```
g++ -I msgpack-c/include your_source_file.cpp
This will search for `msgpack` cmake package in a system prefix and in
prefixes from `CMAKE_PREFIX_PATH`. Note that msgpack-c depends on boost
headers, and `msgpack` cmake package depends on `Boost` cmake package. The
library is header-only and `target_link_libraries` command just adds path
to msgpack-c headers to your compiler's include path.
If you want to use C version of msgpack, you need to build it. You can
also install the C and C++ versions of msgpack.
A usage example can be found at [test-install](test-install) directory.
### Building and Installing
- If you do not use cmake, you can just add path yo msgpack-c and boost
headers to your include path:
#### Install from git repository
```bash
g++ -I msgpack-c/include -I path_to_boost your_source_file.cpp
```
##### Using the Terminal (CLI)
Building and Installing
-----------------------
### Install from git repository
#### Using the Terminal (CLI)
You will need:
- `gcc >= 4.1.0`
- `cmake >= 2.8.0`
- `gcc >= 4.1.0`
- `cmake >= 3.1.0`
C and C++03:
C++03:
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ cmake .
$ make
$ sudo make install
```bash
git clone https://github.com/msgpack/msgpack-c.git
cd msgpack-c
git checkout cpp_master
cmake .
sudo cmake --build . --target install
```
If you want to setup C++11 or C++17 version of msgpack instead,
execute the following commands:
If you want to build tests with different C++ version, you can use
`MSGPACK_CXX11`, `MSGPACK_CXX14`, `MSGPACK_CXX17`, `MSGPACK_CXX20` options.
Just replace the line
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ cmake -DMSGPACK_CXX[11|17]=ON .
$ sudo make install
```bash
cmake .
```
`MSGPACK_CXX[11|17]` flags are not affected to installing files. Just switching test cases. All files are installed in every settings.
with a line like that:
When you use the C part of `msgpack-c`, you need to build and link the library. By default, both static/shared libraries are built. If you want to build only static library, set `BUILD_SHARED_LIBS=OFF` to cmake. If you want to build only shared library, set `BUILD_SHARED_LIBS=ON`.
```bash
cmake -DMSGPACK_CXX20=ON .
```
Note that these flags do not affect installation. They just switch test cases.
All files are installed in every settings.
If you don't have superuser permissions or don't want to install the library
to a system-wide prefix, you can use `CMAKE_INSTALL_PREFIX` option like that:
```bash
cmake -DCMAKE_INSTALL_PREFIX=/your/custom/prefix .
```
Other useful options:
- `MSGPACK_BUILD_TESTS` (default `OFF`): build tests
- `MSGPACK_BUILD_EXAMPLES` (default `OFF`): build examples
- `MSGPACK_32BIT` (default `OFF`): 32bit compile
- `MSGPACK_USE_X3_PARSE` (default `OFF`): use Boost X3 parse
(note that it requires C++14 or newer)
- `MSGPACK_CHAR_SIGN` (not set explicitly by default): char sign to use (signed or unsigned)
- `MSGPACK_USE_STATIC_BOOST` (default `OFF`): statically link with boost libraries
#### GUI on Windows
Clone msgpack-c git repository.
Clone msgpack-c git repository with the command:
$ git clone https://github.com/msgpack/msgpack-c.git
```
git clone https://github.com/msgpack/msgpack-c.git
```
or using GUI git client.
or using GUI git client (e.g. [tortoise git](https://code.google.com/p/tortoisegit/)).
e.g.) tortoise git https://code.google.com/p/tortoisegit/
1. Checkout to `cpp_master` branch
1. Launch [cmake GUI client](http://www.cmake.org/cmake/resources/software.html).
2. Launch [cmake GUI client](http://www.cmake.org/cmake/resources/software.html).
2. Set 'Where is the source code:' text box and 'Where to build
the binaries:' text box.
3. Set 'Where is the source code:' text box and
'Where to build the binaries:' text box.
3. Click 'Configure' button.
4. Click 'Configure' button.
4. Choose your Visual Studio version.
5. Choose your Visual Studio version.
5. Click 'Generate' button.
6. Click 'Generate' button.
6. Open the created msgpack.sln on Visual Studio.
7. Open the created msgpack.sln on Visual Studio.
7. Build all.
8. Build all.
### Documentation
Documentation
-------------
You can get additional information including the tutorial on the
[wiki](https://github.com/msgpack/msgpack-c/wiki).

View File

@ -1,62 +1,56 @@
version: 3.3.0.{build}
version: 7.0.0.{build}
branches:
only:
- master
- cpp_master
image:
- Visual Studio 2015
environment:
global:
BOOST_ROOT: C:\Libraries\boost_1_67_0
matrix:
- cpp11: -DMSGPACK_CXX11=OFF
boost: -DMSGPACK_BOOST=OFF
msvc: '"Visual Studio 10 2010"'
- cpp11: -DMSGPACK_CXX11=OFF
boost: -DMSGPACK_BOOST=OFF
msvc: '"Visual Studio 11 2012"'
- cpp11: -DMSGPACK_CXX11=OFF
boost: -DMSGPACK_BOOST=OFF
msvc: '"Visual Studio 12 2013"'
- cpp11: -DMSGPACK_CXX11=ON
boost: -DMSGPACK_BOOST=ON
msvc: '"Visual Studio 14 2015"'
- cpp11: -DMSGPACK_CXX11=OFF
boost: -DMSGPACK_BOOST=ON
msvc: '"Visual Studio 14 2015"'
- cpp11: -DMSGPACK_CXX11=ON
boost: -DMSGPACK_BOOST=OFF
msvc: '"Visual Studio 14 2015"'
- cpp11: -DMSGPACK_CXX11=OFF
boost: -DMSGPACK_BOOST=OFF
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
cpp11: -DMSGPACK_CXX11=ON
msvc: '"Visual Studio 14 2015"'
boost_prefix: C:\Libraries\boost_1_69_0
boost_subdir: lib32-msvc-14.0
build_script:
- appveyor DownloadFile https://github.com/google/googletest/archive/release-1.7.0.zip -FileName googletest-release-1.7.0.zip
- 7z x googletest-release-1.7.0.zip > NUL
- cd googletest-release-1.7.0
- md build
- cd build
- cmake -G %msvc% -DBUILD_SHARED_LIBS=ON -DCMAKE_CXX_FLAGS=/D_VARIADIC_MAX=10 ..
- cmake --build . --config Release
- cd ..
- cd ..
- 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 > NUL
- 7z x zlib-1.2.11.tar > NUL
- cd zlib-1.2.11
- md build
- cd build
- cmake -G %msvc% ..
- cmake --build . --config Release
- copy zconf.h ..
- cd ..
- cd ..
- md build
- cd build
- cmake -G %msvc% %cpp11% %boost% %x3_parse% -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.11\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.11 -DCMAKE_CXX_FLAGS='"/D_VARIADIC_MAX=10 /EHsc"' ..
- cmake --build . --config Release -v
- ps: |
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
cd build
cmake `
-G $env:msvc `
-D CMAKE_INSTALL_PREFIX="$env:APPVEYOR_BUILD_FOLDER\zlib-1.3.1\prefix" `
..
if ($LastExitCode -ne 0) { exit $LastExitCode }
cmake --build . --target install --config Release
if ($LastExitCode -ne 0) { exit $LastExitCode }
cd ..\..
md build
md prefix
cd build
cmake `
-G $env:msvc `
$env:cpp11 `
-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.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" `
..
if ($LastExitCode -ne 0) { exit $LastExitCode }
cmake --build . --config Release
if ($LastExitCode -ne 0) { exit $LastExitCode }
test_script:
- set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.11\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release
- ctest -V
- 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

@ -1,23 +1,11 @@
#!/bin/bash
mkdir build
build_dir="$CXX-build"
prefix_dir="`pwd`/$CXX-prefix"
mkdir $build_dir || exit 1
mkdir $prefix_dir || exit 1
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cd build
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
if [ "${ARCH}" == "32" ]
then
if [ "${ARCH}" == "32" ]; then
export BIT32="ON"
export ARCH_FLAG="-m32"
else
@ -25,41 +13,26 @@ else
export ARCH_FLAG="-m64"
fi
cmake -DMSGPACK_CXX11=${CXX11} -DMSGPACK_CXX17=${CXX17} -DMSGPACK_32BIT=${BIT32} -DMSGPACK_BOOST=${BOOST} -DBUILD_SHARED_LIBS=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DMSGPACK_DEFAULT_API_VERSION=${API_VERSION} -DMSGPACK_USE_X3_PARSE=${X3_PARSE} -DCMAKE_CXX_FLAGS=${ARCH_FLAG} ..
cmake \
-D CMAKE_PREFIX_PATH="${HOME}/boost-prefix/${ARCH};${HOME}/zlib-prefix/${ARCH}" \
-D MSGPACK_BUILD_TESTS=ON \
-D ${MSGPACK_CXX_VERSION} \
-D MSGPACK_32BIT=${BIT32} \
-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 \
-S . || exit 1
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cmake --build $build_dir --target install || exit 1
make
ctest -VV --test-dir $build_dir || exit 1
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
ctest -VV
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make install DESTDIR=`pwd`/install
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
if [ "${ARCH}" != "32" ] && [ `uname` = "Linux" ]
then
ctest -T memcheck | tee memcheck.log
if [ "${ARCH}" != "32" ] && [ `uname` = "Linux" ]; then
ctest -T memcheck --test-dir $build_dir | tee memcheck.log
ret=${PIPESTATUS[0]}
if [ $ret -ne 0 ]
@ -74,39 +47,15 @@ then
fi
fi
if [ "${ARCH}" != "32" ]
then
mkdir install-test
if [ "${ARCH}" != "32" ]; then
cd test-install || exit 1
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
mkdir $build_dir
cmake \
-D CMAKE_PREFIX_PATH="$prefix_dir;${HOME}/boost-prefix/${ARCH}" \
-B $build_dir \
-S . || exit 1
cmake --build $build_dir --target all || exit 1
cd install-test
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cmake -DCMAKE_PREFIX_PATH=`pwd`/../install/usr/local/lib/cmake ../../example/cmake
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
$build_dir/test-install || exit 1
fi
exit 0

View File

@ -1,59 +0,0 @@
#!/bin/bash
cd example/cmake
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
rm -f msgpack-c
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
ln -s ../.. msgpack-c
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
mkdir build
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cd build
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cmake -DEXAMPLE_MSGPACK_EMBEDDED=ON ..
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make example example-static
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
exit 0

View File

@ -1,20 +1,7 @@
#!/bin/bash
mkdir -p build
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cd build
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
build_dir="$CXX-build"
mkdir $build_dir || exit 1
if [ "${ARCH}" == "32" ]
then
@ -22,28 +9,17 @@ then
exit 1
fi
cmake -DMSGPACK_FUZZ_REGRESSION="ON" -DMSGPACK_CXX11="ON" -DMSGPACK_BOOST=${BOOST} -DMSGPACK_SAN=${MSGPACK_SAN} -v ..
cmake \
-D CMAKE_PREFIX_PATH="${HOME}/boost-prefix/${ARCH};${HOME}/zlib-prefix/${ARCH}" \
-D MSGPACK_FUZZ_REGRESSION="ON" \
-D ${MSGPACK_CXX_VERSION} \
-D MSGPACK_CHAR_SIGN=${CHAR_SIGN} \
-D MSGPACK_DEFAULT_API_VERSION=${API_VERSION} \
-D MSGPACK_USE_X3_PARSE=${X3_PARSE} \
-D CMAKE_CXX_FLAGS="${CXXFLAGS}" \
-B $build_dir \
-S . || exit 1
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
cmake --build $build_dir --target all || exit 1
make
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
make test
ret=$?
if [ $ret -ne 0 ]
then
exit $ret
fi
exit 0
ctest -VV --test-dir $build_dir || exit 1

17
ci/set_gcc_10.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
version=10
priority=100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-${version} ${priority}
sudo update-alternatives --install /usr/bin/gcc-ar gcc-ar /usr/bin/gcc-ar-${version} ${priority}
sudo update-alternatives --install /usr/bin/gcc-nm gcc-nm /usr/bin/gcc-nm-${version} ${priority}
sudo update-alternatives --install /usr/bin/gcc-ranlib gcc-ranlib /usr/bin/gcc-ranlib-${version} ${priority}
sudo update-alternatives --install /usr/bin/gcov gcov /usr/bin/gcov-${version} ${priority}
sudo update-alternatives --install /usr/bin/gcov-dump gcov-dump /usr/bin/gcov-dump-${version} ${priority}
sudo update-alternatives --install /usr/bin/gcov-tool gcov-tool /usr/bin/gcov-tool-${version} ${priority}
sudo update-alternatives --install /usr/bin/lto-dump lto-dump /usr/bin/lto-dump-${version} ${priority}
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-${version} ${priority}
sudo update-alternatives --install /usr/bin/cc cc /usr/bin/gcc-${version} ${priority}
sudo update-alternatives --install /usr/bin/c++ c++ /usr/bin/g++-${version} ${priority}

View File

@ -4,52 +4,52 @@ FIND_PROGRAM(LCOV_PATH lcov)
FIND_PROGRAM(GENHTML_PATH genhtml)
IF(NOT GCOV_PATH)
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
MESSAGE(FATAL_ERROR "gcov not found! Aborting...")
ENDIF()
IF(NOT CMAKE_COMPILER_IS_GNUCC)
# Clang version 3.0.0 and greater now supports gcov as well.
MESSAGE(STATUS "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.")
IF(NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" AND NOT "${CMAKE_C_COMPILER_ID}" STREQUAL "AppleClang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
ENDIF()
IF(NOT CMAKE_COMPILER_IS_GNUCC AND NOT CMAKE_COMPILER_IS_GNUCXX)
# Clang version 3.0.0 and greater now supports gcov as well.
MESSAGE(STATUS "Compiler is not GNU gcc! Clang Version 3.0.0 and greater supports gcov as well, but older versions don't.")
IF(NOT "${CMAKE_C_COMPILER_ID}" MATCHES "Clang" AND NOT "${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
MESSAGE(FATAL_ERROR "Compiler is not GNU gcc! Aborting...")
ENDIF()
ENDIF()
SET(COVERAGE_FLAGS "-g -O0 --coverage")
FUNCTION(SETUP_TARGET_FOR_COVERAGE _targetname _testrunner _outputname)
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF()
IF(NOT LCOV_PATH)
MESSAGE(FATAL_ERROR "lcov not found! Aborting...")
ENDIF()
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF()
IF(NOT GENHTML_PATH)
MESSAGE(FATAL_ERROR "genhtml not found! Aborting...")
ENDIF()
# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Setup target
ADD_CUSTOM_TARGET(${_targetname}
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Cleanup lcov
${LCOV_PATH} --directory . --zerocounters
# Run tests
COMMAND ${_testrunner} ${ARGV3}
# Run tests
COMMAND ${_testrunner} ${ARGV3}
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info --base-directory ${CMAKE_SOURCE_DIR} --no-external --quiet
COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/test/*' '*/fuzz/*' --output-file ${_outputname}.info.cleaned --quiet
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned --prefix ${CMAKE_SOURCE_DIR}
# COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
# Capturing lcov counters and generating report
COMMAND ${LCOV_PATH} --directory . --capture --output-file ${_outputname}.info --base-directory ${CMAKE_SOURCE_DIR} --no-external --quiet
COMMAND ${LCOV_PATH} --remove ${_outputname}.info '*/test/*' '*/fuzz/*' --output-file ${_outputname}.info.cleaned --quiet
COMMAND ${GENHTML_PATH} -o ${_outputname} ${_outputname}.info.cleaned --prefix ${CMAKE_SOURCE_DIR}
# COMMAND ${CMAKE_COMMAND} -E remove ${_outputname}.info ${_outputname}.info.cleaned
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
WORKING_DIRECTORY ${CMAKE_BINARY_DIR}
COMMENT "Resetting code coverage counters to zero.\nProcessing code coverage counters and generating report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)
# Show info where to find the report
ADD_CUSTOM_COMMAND(TARGET ${_targetname} POST_BUILD
COMMAND ;
COMMENT "Open ./${_outputname}/index.html in your browser to view the coverage report."
)
ENDFUNCTION()

View File

@ -10,7 +10,15 @@
#ifndef MSGPACK_V1_CPP03_ZONE_HPP
#define MSGPACK_V1_CPP03_ZONE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/cpp_config.hpp"
#include "msgpack/zone_decl.hpp"
#include "msgpack/assert.hpp"
#include <stdint.h>
#include <cstdlib>
#include <memory>
#include <vector>
<% GENERATION_LIMIT = 15 %>
namespace msgpack {
@ -130,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);
@ -186,16 +194,17 @@ 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)
{
}
inline char* zone::get_aligned(char* ptr, size_t align)
{
MSGPACK_ASSERT(align != 0 && (align & (align - 1)) == 0); // align must be 2^n (n >= 0)
return
reinterpret_cast<char*>(
reinterpret_cast<size_t>(
(ptr + (align - 1))) / align * align);
reinterpret_cast<uintptr_t>(ptr + (align - 1)) & ~static_cast<uintptr_t>(align - 1)
);
}
inline void* zone::allocate_align(size_t size, size_t align)

View File

@ -1,9 +1,9 @@
IF (NOT MSGPACK_CXX_ONLY)
ADD_SUBDIRECTORY (c)
ENDIF ()
IF (MSGPACK_ENABLE_CXX)
ADD_SUBDIRECTORY (cpp03)
ADD_SUBDIRECTORY (cpp11)
ADD_SUBDIRECTORY (cpp03)
ADD_SUBDIRECTORY (cpp11)
IF (MSGPACK_USE_BOOST)
ADD_SUBDIRECTORY (boost)
ADD_SUBDIRECTORY (x3)
IF (MSGPACK_USE_X3_PARSE)
ADD_SUBDIRECTORY (x3)
ENDIF ()
ENDIF ()

View File

@ -1,21 +1,16 @@
IF (MSGPACK_BOOST)
LIST (APPEND exec_PROGRAMS
msgpack_variant_capitalize.cpp
msgpack_variant_mapbased.cpp
)
IF (MSGPACK_CXX11 OR MSGPACK_CXX17)
FIND_PACKAGE (Threads REQUIRED)
LIST (APPEND exec_PROGRAMS
asio_send_recv.cpp
)
IF (ZLIB_FOUND)
INCLUDE_DIRECTORIES (
${ZLIB_INCLUDE_DIRS}
)
LIST (APPEND exec_PROGRAMS
asio_send_recv_zlib.cpp
)
ENDIF ()
FIND_PACKAGE (Boost REQUIRED)
FIND_PACKAGE (Threads REQUIRED)
FIND_PACKAGE (ZLIB REQUIRED)
LIST (APPEND exec_PROGRAMS
msgpack_variant_capitalize.cpp
msgpack_variant_mapbased.cpp
)
IF (MSGPACK_CXX11 OR MSGPACK_CXX14 OR MSGPACK_CXX17 OR MSGPACK_CXX20)
LIST (APPEND exec_PROGRAMS asio_send_recv.cpp)
IF (ZLIB_FOUND)
LIST (APPEND exec_PROGRAMS asio_send_recv_zlib.cpp)
ENDIF ()
ENDIF ()
@ -25,24 +20,18 @@ FOREACH (source_file ${exec_PROGRAMS})
${source_file_we}
${source_file}
)
TARGET_INCLUDE_DIRECTORIES (${source_file_we}
PRIVATE
$<TARGET_PROPERTY:msgpackc-cxx,INTERFACE_INCLUDE_DIRECTORIES>
)
TARGET_LINK_LIBRARIES (${source_file_we}
${Boost_SYSTEM_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
Threads::Threads
)
IF (ZLIB_FOUND)
TARGET_LINK_LIBRARIES (${source_file_we}
${ZLIB_LIBRARIES}
)
ENDIF()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE ZLIB::ZLIB)
ENDIF ()
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")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()

View File

@ -85,12 +85,12 @@ int main() {
}
std::cout << bytes_transferred << " bytes read." << std::endl;
print(std::string(std::string(&buf[0], buf.size())));
strm.avail_in = bytes_transferred;
strm.avail_in = static_cast<uInt>(bytes_transferred);
do {
strm.next_in = reinterpret_cast<unsigned char*>(&buf[0]) + (bytes_transferred - strm.avail_in);
int zret;
unp.reserve_buffer(window_size);
strm.avail_out = window_size;
strm.avail_out = static_cast<uInt>(window_size);
strm.next_out = reinterpret_cast<unsigned char*>(unp.buffer());
do {
zret = inflate(&strm, Z_NO_FLUSH);

View File

@ -1,44 +0,0 @@
FIND_PACKAGE (cJSON)
LIST (APPEND exec_PROGRAMS
boundary.c
lib_buffer_unpack.c
simple_c.c
speed_test_uint32_array.c
speed_test_uint64_array.c
user_buffer_unpack.c
)
IF (cJSON_FOUND)
LIST (APPEND exec_PROGRAMS jsonconv.c)
ENDIF ()
FOREACH (source_file ${exec_PROGRAMS})
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
ADD_EXECUTABLE (
${source_file_we}
${source_file}
)
TARGET_LINK_LIBRARIES (${source_file_we}
msgpackc
)
IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_C_COMPILER_ID}" STREQUAL "GNU")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wall -Wextra")
ENDIF ()
IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()
IF ("${CMAKE_C_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_C_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W3 /WX" CMAKE_C_FLAGS "${CMAKE_C_FLAGS}")
ELSE ()
SET(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /W3 /WX")
ENDIF ()
ENDIF ()
ENDFOREACH ()
IF (cJSON_FOUND)
TARGET_LINK_LIBRARIES (jsonconv ${CJSON_LIBRARIES})
TARGET_INCLUDE_DIRECTORIES(jsonconv PRIVATE ${CJSON_INCLUDE_DIRS})
ENDIF ()

View File

@ -1,296 +0,0 @@
/* gcc boundary.c -o boundary -Wconversion -Wpointer-sign */
#include <msgpack.h>
#include <stdio.h>
#include <assert.h>
static inline unsigned char atohex(char a)
{
int x;
if (a >= 'a') {
x = a - 'a' + 10;
} else if (a >= 'A') {
x = a - 'A' + 10;
} else {
x = a - '0';
}
assert(x >= 0 && x < 16);
return (unsigned char)x;
}
// Return 0 if equal
static inline int bytesncmp(char *data, const char *bytes, size_t len)
{
size_t n = len >> 1;
size_t i = 0;
int diff;
for (; i < n; i++) {
diff = (unsigned char)data[i] - (atohex(bytes[2 * i]) << 4) - atohex(bytes[2 * i + 1]);
if (diff != 0) {
return diff;
}
}
return 0;
}
int main()
{
msgpack_sbuffer sbuf;
msgpack_packer *x;
size_t offset = 0;
char data[65536];
msgpack_timestamp ts[] = {
{ 0xFFFFFFFF, 0 },
{ 0x100000000, 0 },
{ 0x3FFFFFFFF, 0 },
{ 0x400000000, 0 },
{ INT64_MAX, UINT32_MAX }
};
#define check_sbuffer(b) \
do { \
size_t len = strlen(#b); \
assert((sbuf.size - offset) * 2 == len); \
assert(bytesncmp(sbuf.data + offset, #b, len) == 0); \
offset = sbuf.size; \
} while (0)
msgpack_sbuffer_init(&sbuf);
x = msgpack_packer_new(&sbuf, msgpack_sbuffer_write);
msgpack_pack_fix_uint8(x, 0); check_sbuffer(cc00); /* cc 00 */
msgpack_pack_fix_uint8(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_fix_uint16(x, 0); check_sbuffer(cd0000); /* cd 00 00 */
msgpack_pack_fix_uint16(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */
msgpack_pack_fix_uint32(x, 0); check_sbuffer(ce00000000); /* ce 00 00 00 00 */
msgpack_pack_fix_uint32(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */
msgpack_pack_fix_uint64(x, 0); check_sbuffer(cf0000000000000000); /* cf 00 00 00 00 00 00 00 00 */
msgpack_pack_fix_uint64(x, 0xFFFFFFFFFFFFFFFF); check_sbuffer(cfffffffffffffffff); /* cf ff ff ff ff ff ff ff ff */
msgpack_pack_uint8(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_uint8(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_uint8(x, 0x80); check_sbuffer(cc80); /* cc 80 */
msgpack_pack_uint8(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_uint16(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_uint16(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_uint16(x, 0x80); check_sbuffer(cc80); /* cc 80 */
msgpack_pack_uint16(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_uint16(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */
msgpack_pack_uint16(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */
msgpack_pack_uint32(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_uint32(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_uint32(x, 0x80); check_sbuffer(cc80); /* cc 80 */
msgpack_pack_uint32(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_uint32(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */
msgpack_pack_uint32(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */
msgpack_pack_uint32(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */
msgpack_pack_uint32(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */
msgpack_pack_uint64(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_uint64(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_uint64(x, 0x80); check_sbuffer(cc80); /* cc 80 */
msgpack_pack_uint64(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_uint64(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */
msgpack_pack_uint64(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */
msgpack_pack_uint64(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */
msgpack_pack_uint64(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */
msgpack_pack_uint64(x, 0x100000000); check_sbuffer(cf0000000100000000); /* cf 00 00 00 01 00 00 00 00 */
msgpack_pack_uint64(x, 0xFFFFFFFFFFFFFFFF); check_sbuffer(cfffffffffffffffff); /* cf ff ff ff ff ff ff ff ff */
msgpack_pack_fix_int8(x, 0x7F); check_sbuffer(d07f); /* d0 7f */
msgpack_pack_fix_int8(x, -0x7F-1); check_sbuffer(d080); /* d0 80 */
msgpack_pack_fix_int16(x, 0x7FFF); check_sbuffer(d17fff); /* d1 7f ff */
msgpack_pack_fix_int16(x, -0x7FFF-1); check_sbuffer(d18000); /* d1 80 00 */
msgpack_pack_fix_int32(x, 0x7FFFFFFF); check_sbuffer(d27fffffff); /* d2 7f ff ff ff */
msgpack_pack_fix_int32(x, -0x7FFFFFFF-1); check_sbuffer(d280000000); /* d2 80 00 00 00 */
msgpack_pack_fix_int64(x, 0x7FFFFFFFFFFFFFFF); check_sbuffer(d37fffffffffffffff); /* d3 7f ff ff ff ff ff ff ff */
msgpack_pack_fix_int64(x, -0x7FFFFFFFFFFFFFFF-1); check_sbuffer(d38000000000000000); /* d3 80 00 00 00 00 00 00 00 */
msgpack_pack_int8(x, -0x7F-1); check_sbuffer(d080); /* d0 80 */
msgpack_pack_int8(x, -0x21); check_sbuffer(d0df); /* d0 df */
msgpack_pack_int8(x, -0x20); check_sbuffer(e0); /* e0 */
msgpack_pack_int8(x, -1); check_sbuffer(ff); /* ff */
msgpack_pack_int8(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_int8(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_int16(x, -0x7FFF-1); check_sbuffer(d18000); /* d1 80 00 */
msgpack_pack_int16(x, -0x81); check_sbuffer(d1ff7f); /* d1 ff 7f */
msgpack_pack_int16(x, -0x80); check_sbuffer(d080); /* d0 80 */
msgpack_pack_int16(x, -0x21); check_sbuffer(d0df); /* d0 df */
msgpack_pack_int16(x, -0x20); check_sbuffer(e0); /* e0 */
msgpack_pack_int16(x, -0x1); check_sbuffer(ff); /* ff */
msgpack_pack_int16(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_int16(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_int16(x, 0x80); check_sbuffer(cc80); /* cc 80 */
msgpack_pack_int16(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_int16(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */
msgpack_pack_int16(x, 0x7FFF); check_sbuffer(cd7fff); /* cd 7f ff */
msgpack_pack_int32(x, -0x7FFFFFFF-1); check_sbuffer(d280000000); /* d2 80 00 00 00 */
msgpack_pack_int32(x, -0x8001); check_sbuffer(d2ffff7fff); /* d2 ff ff 7f ff */
msgpack_pack_int32(x, -0x8000); check_sbuffer(d18000); /* d1 80 00 */
msgpack_pack_int32(x, -0x81); check_sbuffer(d1ff7f); /* d1 ff 7f */
msgpack_pack_int32(x, -0x80); check_sbuffer(d080); /* d0 80 */
msgpack_pack_int32(x, -0x21); check_sbuffer(d0df); /* d0 df */
msgpack_pack_int32(x, -0x20); check_sbuffer(e0); /* e0 */
msgpack_pack_int32(x, -0x1); check_sbuffer(ff); /* ff */
msgpack_pack_int32(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_int32(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_int32(x, 0x80); check_sbuffer(cc80); /* cc 80 */
msgpack_pack_int32(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_int32(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */
msgpack_pack_int32(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */
msgpack_pack_int32(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */
msgpack_pack_int32(x, 0x7FFFFFFF); check_sbuffer(ce7fffffff); /* ce 7f ff ff ff */
msgpack_pack_int64(x, -0x7FFFFFFFFFFFFFFF-1); check_sbuffer(d38000000000000000); /* d3 80 00 00 00 00 00 00 00 */
msgpack_pack_int64(x, -((1LL<<31)+1)); check_sbuffer(d3ffffffff7fffffff); /* d3 ff ff ff ff 7f ff ff ff */
msgpack_pack_int64(x, -(1LL<<31)); check_sbuffer(d280000000); /* d2 80 00 00 00 */
msgpack_pack_int64(x, -0x8001); check_sbuffer(d2ffff7fff); /* d2 ff ff 7f ff */
msgpack_pack_int64(x, -0x8000); check_sbuffer(d18000); /* d1 80 00 */
msgpack_pack_int64(x, -0x81); check_sbuffer(d1ff7f); /* d1 ff 7f */
msgpack_pack_int64(x, -0x80); check_sbuffer(d080); /* d0 80 */
msgpack_pack_int64(x, -0x21); check_sbuffer(d0df); /* d0 df */
msgpack_pack_int64(x, -0x20); check_sbuffer(e0); /* e0 */
msgpack_pack_int64(x, -0x1); check_sbuffer(ff); /* ff */
msgpack_pack_int64(x, 0); check_sbuffer(00); /* 00 */
msgpack_pack_int64(x, 0x7F); check_sbuffer(7f); /* 7f */
msgpack_pack_int64(x, 0x80); check_sbuffer(cc80); /* cc 80 */
msgpack_pack_int64(x, 0xFF); check_sbuffer(ccff); /* cc ff */
msgpack_pack_int64(x, 0x100); check_sbuffer(cd0100); /* cd 01 00 */
msgpack_pack_int64(x, 0xFFFF); check_sbuffer(cdffff); /* cd ff ff */
msgpack_pack_int64(x, 0x10000); check_sbuffer(ce00010000); /* ce 00 01 00 00 */
msgpack_pack_int64(x, 0xFFFFFFFF); check_sbuffer(ceffffffff); /* ce ff ff ff ff */
msgpack_pack_int64(x, 0x100000000); check_sbuffer(cf0000000100000000); /* cf 00 00 00 01 00 00 00 00 */
msgpack_pack_int64(x, 0x7FFFFFFFFFFFFFFF); check_sbuffer(cf7fffffffffffffff); /* cf 7f ff ff ff ff ff ff ff */
msgpack_pack_nil(x); check_sbuffer(c0); /* c0 */
msgpack_pack_false(x); check_sbuffer(c2); /* c2 */
msgpack_pack_true(x); check_sbuffer(c3); /* c3 */
msgpack_pack_float(x, 1.0); check_sbuffer(ca3f800000); /* ca 3f 80 00 00 */
msgpack_pack_double(x, 1.0); check_sbuffer(cb3ff0000000000000); /* cb 3f f0 00 00 00 00 00 00 */
msgpack_pack_unsigned_char(x, UINT8_MAX); /* same as msgpack_pack_uint8() */
msgpack_pack_unsigned_short(x, (unsigned short)UINT64_MAX);
msgpack_pack_unsigned_int(x, (unsigned int)UINT64_MAX);
msgpack_pack_unsigned_long(x, (unsigned long)UINT64_MAX);
msgpack_pack_unsigned_long_long(x, (unsigned long long)UINT64_MAX);
msgpack_pack_signed_char(x, INT8_MAX); /* same as msgpack_pack_int8() */
#define check_sbuffer_n(b) \
do { \
size_t len = strlen(#b); \
assert(bytesncmp(sbuf.data + offset, #b, len) == 0); \
offset = sbuf.size; \
} while (0)
#define fill_str(n) msgpack_pack_str_body(x, data, n)
offset = sbuf.size;
msgpack_pack_str(x, 0); /* "" */ check_sbuffer(a0); /* a0 */
msgpack_pack_str(x, 31);
fill_str(31); check_sbuffer_n(bf); /* bf ... */
msgpack_pack_str(x, 32);
fill_str(32); check_sbuffer_n(d920); /* d9 20 ... */
msgpack_pack_str(x, 255);
fill_str(255); check_sbuffer_n(d9ff); /* d9 ff ... */
msgpack_pack_str(x, 256);
fill_str(256); check_sbuffer_n(da0100); /* da 01 00 ... */
msgpack_pack_str(x, 65535);
fill_str(65535); check_sbuffer_n(daffff); /* da ff ff ... */
msgpack_pack_str(x, 65536);
fill_str(65536); check_sbuffer_n(db00010000); /* db 00 01 00 00 ... */
#define fill_map(n) \
do { \
size_t i = 0; \
for (; i < n * 2; i++) { msgpack_pack_int8(x, 0x1); } \
} while (0);
msgpack_pack_map(x, 0); /* {} */ check_sbuffer(80); /* 80 */
msgpack_pack_map(x, 1);
fill_map(1); check_sbuffer_n(81); /* 81 ... */
msgpack_pack_map(x, 15);
fill_map(15); check_sbuffer_n(8f); /* 8f ... */
msgpack_pack_map(x, 16);
fill_map(16); check_sbuffer_n(de0010); /* de 00 10 ... */
msgpack_pack_map(x, 65535);
fill_map(65535); check_sbuffer_n(deffff); /* de ff ff ... */
msgpack_pack_map(x, 65536);
fill_map(65536); check_sbuffer_n(df00010000); /* df 00 01 00 00 ... */
#define fill_array(n) \
do { \
size_t i = 0; \
for (; i < n; i++) { msgpack_pack_int8(x, 0x1); } \
} while (0);
msgpack_pack_array(x, 0); /* [] */ check_sbuffer(90); /* 90 */
msgpack_pack_array(x, 1);
fill_array(1); check_sbuffer_n(91); /* 91 ... */
msgpack_pack_array(x, 15);
fill_array(15); check_sbuffer_n(9f); /* 9f ... */
msgpack_pack_array(x, 16);
fill_array(16); check_sbuffer_n(dc0010); /* dc 00 10 ... */
msgpack_pack_array(x, 65535);
fill_array(65535); check_sbuffer_n(dcffff); /* dc ff ff ... */
msgpack_pack_array(x, 65536);
fill_array(65536); check_sbuffer_n(dd00010000); /* dd 00 01 00 00 ... */
#define fill_bin(n) msgpack_pack_bin_body(x, data, n)
msgpack_pack_bin(x, 0); check_sbuffer(c400); /* c4 00 */
msgpack_pack_bin(x, 1);
fill_bin(1); check_sbuffer_n(c401); /* c4 01 ... */
msgpack_pack_bin(x, 255);
fill_bin(255); check_sbuffer_n(c4ff); /* c4 ff ... */
msgpack_pack_bin(x, 256);
fill_bin(256); check_sbuffer_n(c50100); /* c5 01 00 ... */
msgpack_pack_bin(x, 65535);
fill_bin(65535); check_sbuffer_n(c5ffff); /* c5 ff ff ... */
msgpack_pack_bin(x, 65536);
fill_bin(65536); check_sbuffer_n(c600010000); /* c6 00 01 00 00 ... */
#define fill_ext(n) msgpack_pack_ext_body(x, data, n)
msgpack_pack_ext(x, 1, 0x7F);
fill_ext(1); check_sbuffer_n(d47f); /* d4 7f ... */
msgpack_pack_ext(x, 2, 0x7F);
fill_ext(2); check_sbuffer_n(d57f); /* d5 7f ... */
msgpack_pack_ext(x, 4, 0x7F);
fill_ext(4); check_sbuffer_n(d67f); /* d6 7f ... */
msgpack_pack_ext(x, 8, 0x7F);
fill_ext(8); check_sbuffer_n(d77f); /* d7 7f ... */
msgpack_pack_ext(x, 16, 0x7F);
fill_ext(16); check_sbuffer_n(d87f); /* d8 7f ... */
msgpack_pack_ext(x, 0, 0x7F); check_sbuffer(c7007f); /* c7 00 7f */
msgpack_pack_ext(x, 3, 0x7F);
fill_ext(3); check_sbuffer_n(c7037f); /* c7 03 7f */
msgpack_pack_ext(x, 5, 0x7F);
fill_ext(5); check_sbuffer_n(c7057f); /* c7 05 7f */
msgpack_pack_ext(x, 17, 0x7F);
fill_ext(17); check_sbuffer_n(c7117f); /* c7 11 7f */
msgpack_pack_ext(x, 255, 0x7F);
fill_ext(255); check_sbuffer_n(c7ff7f); /* c7 ff 7f ... */
msgpack_pack_ext(x, 256, 0x7F);
fill_ext(256); check_sbuffer_n(c801007f); /* c8 01 00 7f ... */
msgpack_pack_ext(x, 65535, 0x7F);
fill_ext(65535); check_sbuffer_n(c8ffff7f); /* c8 ff ff 7f ... */
msgpack_pack_ext(x, 65536, 0x7F);
fill_ext(65536); check_sbuffer_n(c9000100007f); /* c9 00 01 00 00 7f ... */
msgpack_pack_timestamp(x, ts); check_sbuffer(d6ffffffffff); /* d6 ff ff ff ff ff */
msgpack_pack_timestamp(x, ts + 1); check_sbuffer(d7ff0000000100000000); /* d7 ff 00 00 00 01 00 00 00 00 */
msgpack_pack_timestamp(x, ts + 2); check_sbuffer(d7ff00000003ffffffff); /* d7 ff 00 00 00 03 ff ff ff ff */
msgpack_pack_timestamp(x, ts + 3); check_sbuffer(c70cff000000000000000400000000); /* c7 0c ff 00 00 00 00 00 00 00 04 00 00 00 00 */
msgpack_pack_timestamp(x, ts + 4); check_sbuffer(c70cffffffffff7fffffffffffffff); /* c7 0c ff ff ff ff ff 7f ff ff ff ff ff ff ff */
msgpack_sbuffer_destroy(&sbuf);
msgpack_packer_free(x);
return 0;
}

View File

@ -1,419 +0,0 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <msgpack.h>
#include <cjson/cJSON.h>
#if defined(_MSC_VER)
#if _MSC_VER >= 1800
#include <inttypes.h>
#else
#define PRIu64 "I64u"
#define PRIi64 "I64i"
#define PRIi8 "i"
#endif
#else
#include <inttypes.h>
#endif
#if defined(_KERNEL_MODE)
# undef snprintf
# define snprintf _snprintf
#endif
#define DEBUG(...) printf(__VA_ARGS__)
static char *format_string(const char *input)
{
const char *inptr;
char *output;
char *outptr;
size_t output_length = 0;
/* numbers of additional characters*/
size_t escape_characters = 0;
if (input == NULL) {
return NULL;
}
for (inptr = input; *inptr; inptr++) {
switch (*inptr) {
case '\"':
case '\\':
case '\b':
case '\f':
case '\n':
case '\r':
case '\t':
/* one character escape sequence */
escape_characters++;
break;
default:
break;
}
}
output_length = (size_t)(inptr - input) + escape_characters;
output = (char *)malloc(output_length + 1);
if (output == NULL) {
return NULL;
}
/* no add characters*/
if (escape_characters == 0) {
memcpy(output, input, output_length);
output[output_length] = '\0';
return output;
}
outptr = output;
/* copy string */
for (inptr = input; *inptr != '\0'; (void)inptr++, outptr++) {
if ((*inptr > 31) && (*inptr != '\"') && (*inptr != '\\')) {
/* normal character, copy */
*outptr = *inptr;
} else {
/* character needs to be escaped */
*outptr++ = '\\';
switch (*inptr)
{
case '\\':
*outptr = '\\';
break;
case '\"':
*outptr = '\"';
break;
case '\b':
*outptr = 'b';
break;
case '\f':
*outptr = 'f';
break;
case '\n':
*outptr = 'n';
break;
case '\r':
*outptr = 'r';
break;
case '\t':
*outptr = 't';
break;
default:
break;
}
}
}
output[output_length] = '\0';
return output;
}
/*
* Pack cJSON object.
* return 0 success, others failed
*/
static int parse_cjson_object(msgpack_packer *pk, cJSON *node)
{
int ret, sz, i;
cJSON *child;
char *strvalue;
if (node == NULL) {
return -1;
}
switch (node->type & 0xFF) {
case cJSON_Invalid:
return -1;
case cJSON_False:
return msgpack_pack_false(pk);
case cJSON_True:
return msgpack_pack_true(pk);
case cJSON_NULL:
return msgpack_pack_nil(pk);
case cJSON_String:
strvalue = format_string(node->valuestring);
if (strvalue != NULL) {
ret = msgpack_pack_str_with_body(pk, strvalue, strlen(strvalue));
free(strvalue);
return ret;
} else {
return -1;
}
case cJSON_Number:
if (isnan(node->valuedouble) || isinf(node->valuedouble)) {
ret = msgpack_pack_nil(pk);
} else if (node->valuedouble == node->valueint) {
ret = msgpack_pack_int(pk, node->valueint);
} else {
ret = msgpack_pack_double(pk, node->valuedouble);
}
return ret;
case cJSON_Array:
sz = cJSON_GetArraySize(node);
if (msgpack_pack_array(pk, sz) != 0) {
return -1;
}
for (i = 0; i < sz; i++) {
if (parse_cjson_object(pk, cJSON_GetArrayItem(node, i)) != 0) {
return -1;
}
}
return 0;
case cJSON_Object:
sz = cJSON_GetArraySize(node);
if (msgpack_pack_map(pk, sz) != 0) {
return -1;
}
for (i = 0; i < sz; i++) {
child = cJSON_GetArrayItem(node, i);
strvalue = format_string(child->string);
if (strvalue == NULL) {
return -1;
}
if (msgpack_pack_str_with_body(pk, strvalue, strlen(strvalue)) != 0) {
free(strvalue);
return -1;
}
free(strvalue);
if (parse_cjson_object(pk, child) != 0) {
return -1;
}
}
return 0;
default:
DEBUG("unknown type.\n");
return -1;
}
return 0;
}
/*
* Pack json string to msgpack format data.
* return 0 success, -1 failed
*/
int msgpack_pack_jsonstr(msgpack_packer *pk, const char *jsonstr)
{
int status;
cJSON *node;
const char *end = NULL;
if (pk == NULL || jsonstr == NULL) {
return -1;
}
node = cJSON_ParseWithOpts(jsonstr, &end, 1);
if (node == NULL) {
DEBUG("parse error: unexpected string `%s`\n", end);
return -1;
}
status = parse_cjson_object(pk, node);
cJSON_Delete(node);
return status;
}
static int bytes_contain_zero(const msgpack_object_bin *bin)
{
size_t i;
for (i = 0; i < bin->size; i++) {
if (bin->ptr[i] == 0) {
return 1;
}
}
return 0;
}
#define PRINT_JSONSTR_CALL(ret, func, aux_buffer, aux_buffer_size, ...) \
ret = func(aux_buffer, aux_buffer_size, __VA_ARGS__); \
if (ret <= 0) \
return ret; \
if (ret > aux_buffer_size) \
return 0; \
aux_buffer = aux_buffer + ret; \
aux_buffer_size = aux_buffer_size - ret
/*
* Convert msgpack format data to json string.
* return >0: success, 0: length of buffer not enough, -1: failed
*/
size_t msgpack_object_print_jsonstr(char *buffer, size_t length, const msgpack_object o)
{
char *aux_buffer = buffer;
size_t aux_buffer_size = length;
size_t ret;
switch (o.type) {
case MSGPACK_OBJECT_NIL:
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "null");
break;
case MSGPACK_OBJECT_BOOLEAN:
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, (o.via.boolean ? "true" : "false"));
break;
case MSGPACK_OBJECT_POSITIVE_INTEGER:
#if defined(PRIu64)
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%" PRIu64, o.via.u64);
#else
if (o.via.u64 > ULONG_MAX) {
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%lu", ULONG_MAX);
} else {
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%lu", (unsigned long)o.via.u64);
}
#endif
break;
case MSGPACK_OBJECT_NEGATIVE_INTEGER:
#if defined(PRIi64)
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%" PRIi64, o.via.i64);
#else
if (o.via.i64 > LONG_MAX) {
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%ld", LONG_MAX);
} else if (o.via.i64 < LONG_MIN) {
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%ld", LONG_MIN);
} else {
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%ld", (signed long)o.via.i64);
}
#endif
break;
case MSGPACK_OBJECT_FLOAT32:
case MSGPACK_OBJECT_FLOAT64:
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "%f", o.via.f64);
break;
case MSGPACK_OBJECT_STR:
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\"%.*s\"", (int)o.via.str.size, o.via.str.ptr);
break;
case MSGPACK_OBJECT_BIN:
if (bytes_contain_zero(&o.via.bin)) {
DEBUG("the value contains zero\n");
return -1;
}
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "\"%.*s\"", (int)o.via.bin.size, o.via.bin.ptr);
break;
case MSGPACK_OBJECT_EXT:
DEBUG("not support type: MSGPACK_OBJECT_EXT.\n");
return -1;
case MSGPACK_OBJECT_ARRAY:
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "[");
if (o.via.array.size != 0) {
msgpack_object *p = o.via.array.ptr;
msgpack_object *const pend = o.via.array.ptr + o.via.array.size;
PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, *p);
++p;
for (; p < pend; ++p) {
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ",");
PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, *p);
}
}
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "]");
break;
case MSGPACK_OBJECT_MAP:
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "{");
if (o.via.map.size != 0) {
msgpack_object_kv *p = o.via.map.ptr;
msgpack_object_kv *const pend = o.via.map.ptr + o.via.map.size;
for (; p < pend; ++p) {
if (p->key.type != MSGPACK_OBJECT_STR) {
DEBUG("the key of in a map must be string.\n");
return -1;
}
if (p != o.via.map.ptr) {
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ",");
}
PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, p->key);
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, ":");
PRINT_JSONSTR_CALL(ret, msgpack_object_print_jsonstr, aux_buffer, aux_buffer_size, p->val);
}
}
PRINT_JSONSTR_CALL(ret, snprintf, aux_buffer, aux_buffer_size, "}");
break;
default:
DEBUG("unknown type.\n");
return -1;
}
return length - aux_buffer_size;
}
#undef PRINT_JSONSTR_CALL
static void test(const char *name, const char *input, const char *expect)
{
msgpack_sbuffer sbuf;
{
// pack
msgpack_packer pk;
msgpack_sbuffer_init(&sbuf);
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
if (msgpack_pack_jsonstr(&pk, input) < 0) {
msgpack_sbuffer_destroy(&sbuf);
printf("%s: invalid json string.\n", name);
return;
}
}
{
// unpack
#define MAX_JSONLEN 1024
msgpack_zone z;
msgpack_object obj;
size_t jsonstrlen = MAX_JSONLEN - 1;
char jsonparsed[MAX_JSONLEN];
msgpack_zone_init(&z, jsonstrlen);
msgpack_unpack(sbuf.data, sbuf.size, NULL, &z, &obj);
jsonstrlen = msgpack_object_print_jsonstr(jsonparsed, jsonstrlen, obj);
jsonparsed[jsonstrlen] = '\0';
//compare input and output
if (expect == NULL) {
expect = input;
}
if (strcmp(expect, jsonparsed) == 0) {
printf("%s: ok\n", name);
} else {
printf("%s: failed\n", name);
}
msgpack_zone_destroy(&z);
}
msgpack_sbuffer_destroy(&sbuf);
}
int main()
{
test("null", "null", NULL);
test("boolean", "false", NULL);
test("single string", "\"frsyuki\"", NULL);
test("single number", "\"100\"", NULL);
test("space", "[{\"valuespace\":\"\",\"\":\"keyspace\"},\"\",[\"\"]]", NULL);
test("quote", "\"My name is Tom (\\\"Bee\\\") Kobe\"", NULL);
test("escape", "\"\\\\b\\f\\n\\r\\t\"", NULL);
test("escape2", "\"\b\f\n\r\t\"", "\"\\b\\f\\n\\r\\t\"");
test("map", "{\"name\":\"Tom (\\\"Bee\\\") Kobe\",\"type\":\"image\",\"data\":{\"width\":360,\"height\":460,\"title\":\"View me\",\"ips\":[116,943,256,711]}}", NULL);
test("array", "[\"Sunday\",\"Monday\",\"Tuesday\",\"Wednesday\",\"Thursday\",\"Friday\",\"Saturday\"]", NULL);
test("number array", "[[101,121,-33],[119,911,171],[0,2,-3]]", NULL);
test("mix array", "[{\"name\":\"Tom\",\"city\":\"London\",\"country\":\"UK\",\"longitude\":23},{\"name\":\"Jack\",\"city\":\"Birmingham\",\"country\":\"UK\",\"longitude\":-22}]", NULL);
test("unicode", "\"\\u5C71\\u5DDD\\u7570\\u57DF\\u98A8\\u6708\\u540C\\u5929\"", "\"山川異域風月同天\"");
test("utf8", "\"山川異域風月同天\"", NULL);
test("double", "12.34", "12.340000");
return 0;
}

View File

@ -1,127 +0,0 @@
#include <msgpack.h>
#include <stdio.h>
#include <assert.h>
typedef struct receiver {
msgpack_sbuffer sbuf;
size_t rest;
} receiver;
void receiver_init(receiver *r) {
msgpack_packer pk;
msgpack_sbuffer_init(&r->sbuf);
msgpack_packer_init(&pk, &r->sbuf, msgpack_sbuffer_write);
/* 1st object */
msgpack_pack_array(&pk, 3);
msgpack_pack_int(&pk, 1);
msgpack_pack_true(&pk);
msgpack_pack_str(&pk, 7);
msgpack_pack_str_body(&pk, "example", 7);
/* 2nd object */
msgpack_pack_str(&pk, 6);
msgpack_pack_str_body(&pk, "second", 6);
/* 3rd object */
msgpack_pack_array(&pk, 2);
msgpack_pack_int(&pk, 42);
msgpack_pack_false(&pk);
r->rest = r->sbuf.size;
}
size_t receiver_recv(receiver *r, char* buf, size_t try_size) {
size_t off = r->sbuf.size - r->rest;
size_t actual_size = try_size;
if (actual_size > r->rest) actual_size = r->rest;
memcpy(buf, r->sbuf.data + off, actual_size);
r->rest -= actual_size;
return actual_size;
}
size_t receiver_to_unpacker(receiver* r, size_t request_size,
msgpack_unpacker *unpacker)
{
size_t recv_len;
// make sure there's enough room, or expand the unpacker accordingly
if (msgpack_unpacker_buffer_capacity(unpacker) < request_size) {
msgpack_unpacker_reserve_buffer(unpacker, request_size);
assert(msgpack_unpacker_buffer_capacity(unpacker) >= request_size);
}
recv_len = receiver_recv(r, msgpack_unpacker_buffer(unpacker),
request_size);
msgpack_unpacker_buffer_consumed(unpacker, recv_len);
return recv_len;
}
#define EACH_RECV_SIZE 4
void unpack(receiver* r) {
/* buf is allocated by unpacker. */
msgpack_unpacker* unp = msgpack_unpacker_new(100);
msgpack_unpacked result;
msgpack_unpack_return ret;
size_t recv_len;
int recv_count = 0;
int i = 0;
msgpack_unpacked_init(&result);
while (true) {
recv_len = receiver_to_unpacker(r, EACH_RECV_SIZE, unp);
if (recv_len == 0) break; // (reached end of input)
#if defined(_MSC_VER) || defined(__MINGW32__)
printf("receive count: %d %Id bytes received.\n", recv_count++, recv_len);
#else // defined(_MSC_VER) || defined(__MINGW32__)
printf("receive count: %d %zd bytes received.\n", recv_count++, recv_len);
#endif // defined(_MSC_VER) || defined(__MINGW32__)
ret = msgpack_unpacker_next(unp, &result);
while (ret == MSGPACK_UNPACK_SUCCESS) {
msgpack_object obj = result.data;
/* Use obj. */
printf("Object no %d:\n", ++i);
msgpack_object_print(stdout, obj);
printf("\n");
/* If you want to allocate something on the zone, you can use zone. */
/* msgpack_zone* zone = result.zone; */
/* The lifetime of the obj and the zone, */
ret = msgpack_unpacker_next(unp, &result);
}
if (ret == MSGPACK_UNPACK_PARSE_ERROR) {
printf("The data in the buf is invalid format.\n");
msgpack_unpacked_destroy(&result);
return;
}
}
msgpack_unpacked_destroy(&result);
msgpack_unpacker_free(unp);
}
int main(void) {
receiver r;
receiver_init(&r);
unpack(&r);
return 0;
}
/* Output */
/*
receive count: 0 4 bytes received.
receive count: 1 4 bytes received.
receive count: 2 4 bytes received.
Object no 1:
[1, true, "example"]
receive count: 3 4 bytes received.
receive count: 4 4 bytes received.
Object no 2:
"second"
receive count: 5 1 bytes received.
Object no 3:
[42, false]
*/

View File

@ -1,47 +0,0 @@
#include <msgpack.h>
#include <stdio.h>
void print(char const* buf,size_t len)
{
size_t i = 0;
for(; i < len ; ++i)
printf("%02x ", 0xff & buf[i]);
printf("\n");
}
int main(void)
{
msgpack_sbuffer sbuf;
msgpack_packer pk;
msgpack_zone mempool;
msgpack_object deserialized;
/* msgpack::sbuffer is a simple buffer implementation. */
msgpack_sbuffer_init(&sbuf);
/* serialize values into the buffer using msgpack_sbuffer_write callback function. */
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
msgpack_pack_array(&pk, 3);
msgpack_pack_int(&pk, 1);
msgpack_pack_true(&pk);
msgpack_pack_str(&pk, 7);
msgpack_pack_str_body(&pk, "example", 7);
print(sbuf.data, sbuf.size);
/* deserialize the buffer into msgpack_object instance. */
/* deserialized object is valid during the msgpack_zone instance alive. */
msgpack_zone_init(&mempool, 2048);
msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized);
/* print the deserialized object. */
msgpack_object_print(stdout, deserialized);
puts("");
msgpack_zone_destroy(&mempool);
msgpack_sbuffer_destroy(&sbuf);
return 0;
}

View File

@ -1,36 +0,0 @@
#include <msgpack.h>
void test()
{
size_t size = 10000000;
msgpack_sbuffer buf;
msgpack_packer * pk;
size_t upk_pos = 0;
msgpack_unpacked msg;
msgpack_sbuffer_init(&buf);
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
msgpack_pack_array(pk, size);
{
size_t idx = 0;
for (; idx < size; ++idx)
msgpack_pack_uint32(pk, 1);
}
msgpack_packer_free(pk);
msgpack_unpacked_init(&msg);
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos) == MSGPACK_UNPACK_SUCCESS) {
}
msgpack_sbuffer_destroy(&buf);
}
int main(void)
{
int i = 0;
for (; i < 10; ++i) test();
return 0;
}

View File

@ -1,37 +0,0 @@
#include <msgpack.h>
void test()
{
uint64_t test_u64 = 0xFFF0000000000001LL;
size_t size = 10000000;
msgpack_sbuffer buf;
msgpack_packer * pk;
size_t upk_pos = 0;
msgpack_unpacked msg;
msgpack_sbuffer_init(&buf);
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
msgpack_pack_array(pk, size);
{
size_t idx = 0;
for (; idx < size; ++idx)
msgpack_pack_uint64(pk, test_u64);
}
msgpack_packer_free(pk);
msgpack_unpacked_init(&msg);
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos) == MSGPACK_UNPACK_SUCCESS) {
}
msgpack_sbuffer_destroy(&buf);
}
int main(void)
{
int i = 0;
for (; i < 10; ++i) test();
return 0;
}

View File

@ -1,81 +0,0 @@
#include <msgpack.h>
#include <stdio.h>
#include <assert.h>
#define UNPACKED_BUFFER_SIZE 2048
void prepare(msgpack_sbuffer* sbuf) {
msgpack_packer pk;
msgpack_packer_init(&pk, sbuf, msgpack_sbuffer_write);
/* 1st object */
msgpack_pack_array(&pk, 3);
msgpack_pack_int(&pk, 1);
msgpack_pack_true(&pk);
msgpack_pack_str(&pk, 7);
msgpack_pack_str_body(&pk, "example", 7);
/* 2nd object */
msgpack_pack_str(&pk, 6);
msgpack_pack_str_body(&pk, "second", 6);
/* 3rd object */
msgpack_pack_array(&pk, 2);
msgpack_pack_int(&pk, 42);
msgpack_pack_false(&pk);
}
void unpack(char const* buf, size_t len) {
/* buf is allocated by client. */
msgpack_unpacked result;
size_t off = 0;
msgpack_unpack_return ret;
int i = 0;
char unpacked_buffer[UNPACKED_BUFFER_SIZE];
msgpack_unpacked_init(&result);
ret = msgpack_unpack_next(&result, buf, len, &off);
while (ret == MSGPACK_UNPACK_SUCCESS) {
msgpack_object obj = result.data;
/* Use obj. */
printf("Object no %d:\n", ++i);
msgpack_object_print(stdout, obj);
printf("\n");
msgpack_object_print_buffer(unpacked_buffer, UNPACKED_BUFFER_SIZE, obj);
printf("%s\n", unpacked_buffer);
/* If you want to allocate something on the zone, you can use zone. */
/* msgpack_zone* zone = result.zone; */
/* The lifetime of the obj and the zone, */
ret = msgpack_unpack_next(&result, buf, len, &off);
}
msgpack_unpacked_destroy(&result);
if (ret == MSGPACK_UNPACK_CONTINUE) {
printf("All msgpack_object in the buffer is consumed.\n");
}
else if (ret == MSGPACK_UNPACK_PARSE_ERROR) {
printf("The data in the buf is invalid format.\n");
}
}
int main(void) {
msgpack_sbuffer sbuf;
msgpack_sbuffer_init(&sbuf);
prepare(&sbuf);
unpack(sbuf.data, sbuf.size);
msgpack_sbuffer_destroy(&sbuf);
return 0;
}
/* Output */
/*
Object no 1:
[1, true, "example"]
Object no 2:
"second"
Object no 3:
[42, false]
All msgpack_object in the buffer is consumed.
*/

View File

@ -1,17 +0,0 @@
cmake_minimum_required (VERSION 3.0)
project (example)
if(EXAMPLE_MSGPACK_EMBEDDED)
add_subdirectory(msgpack-c)
set(msgpack_DIR ${CMAKE_CURRENT_BINARY_DIR}/msgpack-c)
endif()
find_package(msgpack REQUIRED)
add_executable (${PROJECT_NAME} ${CMAKE_CURRENT_LIST_DIR}/../c/simple_c.c)
target_link_libraries(${PROJECT_NAME} msgpackc)
if(TARGET msgpackc-static)
add_executable (${PROJECT_NAME}-static ${CMAKE_CURRENT_LIST_DIR}/../c/simple_c.c)
target_link_libraries(${PROJECT_NAME}-static msgpackc-static)
endif()

View File

@ -1,3 +1,7 @@
FIND_PACKAGE (Threads REQUIRED)
FIND_PACKAGE (Boost COMPONENTS timer)
LIST (APPEND exec_PROGRAMS
class_intrusive.cpp
class_intrusive_map.cpp
@ -22,11 +26,14 @@ IF (NOT MSVC)
)
ENDIF ()
IF (MSGPACK_BOOST)
LIST (APPEND with_boost_lib_PROGRAMS
speed_test.cpp
speed_test_nested_array.cpp
)
IF (MSGPACK_USE_BOOST)
IF (Boost_TIMER_LIBRARY)
LIST (APPEND with_boost_lib_PROGRAMS
speed_test.cpp
speed_test_nested_array.cpp
)
ENDIF ()
ENDIF ()
FOREACH (source_file ${exec_PROGRAMS})
@ -35,11 +42,10 @@ FOREACH (source_file ${exec_PROGRAMS})
${source_file_we}
${source_file}
)
TARGET_INCLUDE_DIRECTORIES (${source_file_we}
PRIVATE
$<TARGET_PROPERTY:msgpackc-cxx,INTERFACE_INCLUDE_DIRECTORIES>
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
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")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
@ -57,14 +63,11 @@ FOREACH (source_file ${with_pthread_PROGRAMS})
${source_file_we}
${source_file}
)
TARGET_INCLUDE_DIRECTORIES (${source_file_we}
PRIVATE
$<TARGET_PROPERTY:msgpackc-cxx,INTERFACE_INCLUDE_DIRECTORIES>
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
Threads::Threads
)
TARGET_LINK_LIBRARIES (${source_file_we}
${CMAKE_THREAD_LIBS_INIT}
)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
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")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
@ -77,36 +80,26 @@ FOREACH (source_file ${with_pthread_PROGRAMS})
ENDFOREACH ()
FOREACH (source_file ${with_boost_lib_PROGRAMS})
INCLUDE_DIRECTORIES (
../include
${Boost_INCLUDE_DIRS}
)
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
ADD_EXECUTABLE (
${source_file_we}
${source_file}
)
TARGET_INCLUDE_DIRECTORIES (${source_file_we}
PRIVATE
$<TARGET_PROPERTY:msgpackc-cxx,INTERFACE_INCLUDE_DIRECTORIES>
)
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
TARGET_LINK_LIBRARIES (${source_file_we}
${Boost_TIMER_LIBRARY}
${Boost_CHRONO_LIBRARY}
${Boost_SYSTEM_LIBRARY}
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
Boost::timer
)
IF (NOT MSVC AND NOT APPLE)
TARGET_LINK_LIBRARIES (${source_file_we}
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
rt
)
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
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 -Werror -O3")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()

View File

@ -1,8 +1,4 @@
IF (MSGPACK_CXX11 OR MSGPACK_CXX17)
INCLUDE_DIRECTORIES (
../include
)
IF (MSGPACK_CXX11 OR MSGPACK_CXX14 OR MSGPACK_CXX17)
LIST (APPEND exec_PROGRAMS
container.cpp
non_def_con_class.cpp
@ -20,15 +16,14 @@ IF (MSGPACK_CXX11 OR MSGPACK_CXX17)
${source_file_we}
${source_file}
)
TARGET_INCLUDE_DIRECTORIES (${source_file_we}
PRIVATE
$<TARGET_PROPERTY:msgpackc-cxx,INTERFACE_INCLUDE_DIRECTORIES>
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
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")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()

View File

@ -25,8 +25,9 @@ void array() {
std::stringstream ss;
msgpack::pack(ss, a);
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
msgpack::object obj = oh.get();
auto const& str = ss.str();
auto oh = msgpack::unpack(str.data(), str.size());
auto obj = oh.get();
std::cout << obj << std::endl;
assert((obj.as<std::array<int, 5>>()) == a);

View File

@ -1,32 +1,27 @@
IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
INCLUDE_DIRECTORIES (
../include
)
FIND_PACKAGE (Boost REQUIRED COMPONENTS context)
FIND_PACKAGE (Threads REQUIRED)
LIST (APPEND exec_PROGRAMS
unpack.cpp
parse.cpp
)
IF (MSGPACK_BOOST)
LIST (APPEND with_boost_PROGRAMS
stream_unpack.cpp
)
ENDIF ()
LIST (APPEND with_boost_PROGRAMS
stream_unpack.cpp
)
FOREACH (source_file ${exec_PROGRAMS})
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
ADD_EXECUTABLE (
${source_file_we}
${source_file}
)
TARGET_INCLUDE_DIRECTORIES (${source_file_we}
PRIVATE
$<TARGET_PROPERTY:msgpackc-cxx,INTERFACE_INCLUDE_DIRECTORIES>
)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
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")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()
@ -44,20 +39,16 @@ IF (MSGPACK_USE_X3_PARSE AND MSGPACK_DEFAULT_API_VERSION VERSION_GREATER 1)
${source_file_we}
${source_file}
)
TARGET_INCLUDE_DIRECTORIES (${source_file_we}
PRIVATE
$<TARGET_PROPERTY:msgpackc-cxx,INTERFACE_INCLUDE_DIRECTORIES>
TARGET_LINK_LIBRARIES (${source_file_we} PRIVATE
msgpack-cxx
Boost::context
Threads::Threads
)
TARGET_LINK_LIBRARIES (${source_file_we}
${Boost_CONTEXT_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
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")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-mismatched-tags")
ENDIF ()

@ -1 +0,0 @@
Subproject commit 560ff5298ead78276872604f1ee6523e63a4fa90

@ -1 +0,0 @@
Subproject commit 56090c56b5c78418b6dbe8c3c2ba576395152f83

View File

@ -1,36 +1,30 @@
FIND_PACKAGE (GTest REQUIRED)
FIND_PACKAGE (ZLIB REQUIRED)
FIND_PACKAGE (Boost REQUIRED COMPONENTS system filesystem)
INCLUDE_DIRECTORIES (
${GTEST_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
${Boost_INCLUDE_DIRS}
)
FIND_PACKAGE (Threads REQUIRED)
FIND_PACKAGE (Boost REQUIRED COMPONENTS filesystem unit_test_framework)
LIST (APPEND check_PROGRAMS
regression_runner.cpp
)
LINK_DIRECTORIES (
${Boost_LIBRARY_DIRS}
)
FOREACH (source_file ${check_PROGRAMS})
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
ADD_EXECUTABLE (
${source_file_we}
${source_file}
)
TARGET_COMPILE_DEFINITIONS (${source_file_we} PRIVATE
$<IF:$<BOOL:${MSGPACK_USE_STATIC_BOOST}>,,BOOST_TEST_DYN_LINK>)
TARGET_LINK_LIBRARIES (${source_file_we}
msgpackc
${GTEST_BOTH_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
${Boost_LIBRARIES}
msgpack-cxx
Threads::Threads
Boost::filesystem
Boost::unit_test_framework
)
ADD_TEST (${source_file_we} ${source_file_we})
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
IF ("${CMAKE_CXX_COMPILER_ID}" MATCHES "Clang")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -Wextra -Wno-mismatched-tags -g")
IF ("${MSGPACK_SAN}" STREQUAL "ASAN")
SET (CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -fno-omit-frame-pointer -fsanitize=address")

View File

@ -1,50 +1,49 @@
#include <boost/filesystem.hpp>
#include <gtest/gtest.h>
// Use parameterized tests instead of modern data-driven test cases
// because BOOST_DATA_TEST_CASE requires C++11 or newer. See:
// - https://www.boost.org/doc/libs/1_76_0/libs/test/doc/html/boost_test/tests_organization/test_cases/param_test.html
// - https://www.boost.org/doc/libs/1_76_0/libs/test/doc/html/boost_test/tests_organization/test_cases/test_case_generation.html
#include <boost/test/included/unit_test.hpp>
#include <boost/test/parameterized_test.hpp>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
#include "unpack_pack_fuzzer.cpp"
using ::testing::TestWithParam;
using ::testing::ValuesIn;
std::vector<std::string> ListDirectory(const std::string& path) {
std::vector<std::string> v;
boost::filesystem::path p(path);
boost::filesystem::directory_iterator f{p};
boost::filesystem::directory_iterator f(p);
if(boost::filesystem::is_directory(p)) {
while (f != boost::filesystem::directory_iterator{}) {
if (boost::filesystem::is_directory(p)) {
while (f != boost::filesystem::directory_iterator()) {
v.push_back((*f++).path().string());
}
}
return v;
}
class UnpackPackFuzzerRegressionTest : public ::testing::TestWithParam<std::string> {
public:
};
TEST_P(UnpackPackFuzzerRegressionTest, Returns0) {
auto fpath = GetParam();
std::ifstream in(fpath, std::ifstream::binary);
void UnpackPackFuzzerRegressionTest(const std::string& fpath) {
std::ifstream in(fpath.c_str(), std::ios_base::binary);
if (!in) {
FAIL() << fpath << " not found";
BOOST_FAIL(fpath + " not found");
}
in.seekg(0, in.end);
size_t length = in.tellg();
in.seekg(0, in.beg);
std::vector<char> bytes(length);
in.read(bytes.data(), bytes.size());
assert(in);
EXPECT_EQ(0, LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t *>(bytes.data()),
bytes.size()));
BOOST_REQUIRE(in);
BOOST_REQUIRE_EQUAL(0, LLVMFuzzerTestOneInput(reinterpret_cast<const uint8_t *>(bytes.data()), bytes.size()));
}
INSTANTIATE_TEST_CASE_P(UnpackPackFuzzerRegressions,
UnpackPackFuzzerRegressionTest,
::testing::ValuesIn(ListDirectory("../../fuzz/unpack_pack_fuzzer_regressions")));
boost::unit_test::test_suite* init_unit_test_suite(int /*argc*/, char* /*argv*/[])
{
std::vector<std::string> files = ListDirectory("../../fuzz/unpack_pack_fuzzer_regressions");
boost::unit_test::framework::master_test_suite().add(BOOST_PARAM_TEST_CASE(&UnpackPackFuzzerRegressionTest, files.begin(), files.end()));
return 0;
}

View File

@ -1,5 +1,9 @@
#include <msgpack.hpp>
// The function's signature must NOT be changed since other projects rely on it:
// - libFuzzer
// - AFL++
// - Google's oss-fuzz (uses the previous two ones)
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
try {
// NOTE(derwolfe): by default the limits are set at 2^32-1 length. I'm
@ -7,8 +11,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
const int test_limit = 1000;
msgpack::object_handle unpacked = msgpack::unpack(reinterpret_cast<const char *>(data),
size,
nullptr,
nullptr,
MSGPACK_NULLPTR,
MSGPACK_NULLPTR,
msgpack::unpack_limit(test_limit,
test_limit,
test_limit,

View File

@ -1,24 +0,0 @@
/*
* MessagePack for C
*
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
*
* 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)
*/
/**
* @defgroup msgpack MessagePack C
* @{
* @}
*/
#include "msgpack/util.h"
#include "msgpack/object.h"
#include "msgpack/zone.h"
#include "msgpack/pack.h"
#include "msgpack/unpack.h"
#include "msgpack/sbuffer.h"
#include "msgpack/vrefbuffer.h"
#include "msgpack/version.h"

View File

@ -0,0 +1,15 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2020 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_TYPE_COMPLEX_HPP
#define MSGPACK_TYPE_COMPLEX_HPP
#include "msgpack/v1/adaptor/complex.hpp"
#endif // MSGPACK_TYPE_COMPLEX_HPP

View File

@ -0,0 +1,16 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2021 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_TYPE_CPP17_ARRAY_BYTE_HPP
#define MSGPACK_TYPE_CPP17_ARRAY_BYTE_HPP
#include "msgpack/v1/adaptor/cpp17/array_byte.hpp"
#endif // MSGPACK_TYPE_CPP17_ARRAY_BYTE_HPP

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

@ -0,0 +1,16 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2021 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_TYPE_CPP20_SPAN_HPP
#define MSGPACK_TYPE_CPP20_SPAN_HPP
#include "msgpack/v1/adaptor/cpp20/span.hpp"
#endif // MSGPACK_TYPE_CPP20_SPAN_HPP

View File

@ -10,37 +10,18 @@
#ifndef MSGPACK_DEFINE_DECL_HPP
#define MSGPACK_DEFINE_DECL_HPP
// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp
#if defined(MSGPACK_NO_BOOST)
// MSGPACK_PP_VARIADICS is defined in msgpack/preprocessor/config/config.hpp
// http://www.boost.org/libs/preprocessor/doc/ref/variadics.html
// However, supporting compiler detection is not complete. msgpack-c requires
// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly.
// variadic macro arguments support. So MSGPACK_PP_VARIADICS is defined here explicitly.
#if !defined(MSGPACK_PP_VARIADICS)
#define MSGPACK_PP_VARIADICS
#endif
#include <msgpack/preprocessor.hpp>
#include "msgpack/versioning.hpp"
// for MSGPACK_ADD_ENUM
#include "msgpack/adaptor/int.hpp"
#define MSGPACK_DEFINE_ARRAY(...) \
template <typename Packer> \
void msgpack_pack(Packer& msgpack_pk) const \
{ \
msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \
} \
void msgpack_unpack(msgpack::object const& msgpack_o) \
{ \
msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \
}\
template <typename MSGPACK_OBJECT> \
void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
{ \
msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \
}
#define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
#define MSGPACK_NVP(name, value) (name) (value)
@ -85,6 +66,85 @@
#define MSGPACK_BASE_MAP(base) \
(MSGPACK_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
#else // defined(MSGPACK_NO_BOOST)
// BOOST_PP_VARIADICS is defined in boost/preprocessor/config/config.hpp
// http://www.boost.org/libs/preprocessor/doc/ref/variadics.html
// However, supporting compiler detection is not complete. msgpack-c requires
// variadic macro arguments support. So BOOST_PP_VARIADICS is defined here explicitly.
#if !defined(BOOST_PP_VARIADICS)
#define BOOST_PP_VARIADICS
#endif
#include <boost/preprocessor.hpp>
#define MSGPACK_BASE_ARRAY(base) (*const_cast<base *>(static_cast<base const*>(this)))
#define MSGPACK_NVP(name, value) (name) (value)
#define MSGPACK_DEFINE_MAP_EACH_PROC(r, data, elem) \
BOOST_PP_IF( \
BOOST_PP_IS_BEGIN_PARENS(elem), \
elem, \
(BOOST_PP_STRINGIZE(elem))(elem) \
)
#define MSGPACK_DEFINE_MAP_IMPL(...) \
BOOST_PP_SEQ_TO_TUPLE( \
BOOST_PP_SEQ_FOR_EACH( \
MSGPACK_DEFINE_MAP_EACH_PROC, \
0, \
BOOST_PP_VARIADIC_TO_SEQ(__VA_ARGS__) \
) \
)
#define MSGPACK_DEFINE_MAP(...) \
template <typename Packer> \
void msgpack_pack(Packer& msgpack_pk) const \
{ \
msgpack::type::make_define_map \
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
.msgpack_pack(msgpack_pk); \
} \
void msgpack_unpack(msgpack::object const& msgpack_o) \
{ \
msgpack::type::make_define_map \
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
.msgpack_unpack(msgpack_o); \
}\
template <typename MSGPACK_OBJECT> \
void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
{ \
msgpack::type::make_define_map \
MSGPACK_DEFINE_MAP_IMPL(__VA_ARGS__) \
.msgpack_object(msgpack_o, msgpack_z); \
}
#define MSGPACK_BASE_MAP(base) \
(BOOST_PP_STRINGIZE(base))(*const_cast<base *>(static_cast<base const*>(this)))
#endif // defined(MSGPACK_NO_BOOST)
#include "msgpack/versioning.hpp"
// for MSGPACK_ADD_ENUM
#include "msgpack/adaptor/int.hpp"
#define MSGPACK_DEFINE_ARRAY(...) \
template <typename Packer> \
void msgpack_pack(Packer& msgpack_pk) const \
{ \
msgpack::type::make_define_array(__VA_ARGS__).msgpack_pack(msgpack_pk); \
} \
void msgpack_unpack(msgpack::object const& msgpack_o) \
{ \
msgpack::type::make_define_array(__VA_ARGS__).msgpack_unpack(msgpack_o); \
}\
template <typename MSGPACK_OBJECT> \
void msgpack_object(MSGPACK_OBJECT* msgpack_o, msgpack::zone& msgpack_z) const \
{ \
msgpack::type::make_define_array(__VA_ARGS__).msgpack_object(msgpack_o, msgpack_z); \
}
// MSGPACK_ADD_ENUM must be used in the global namespace.
#define MSGPACK_ADD_ENUM(enum_name) \
namespace msgpack { \

View File

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

View File

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

View File

@ -0,0 +1,26 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2022 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_ASSERT_HPP
#define MSGPACK_ASSERT_HPP
#if defined(MSGPACK_NO_BOOST)
#include <cassert>
#define MSGPACK_ASSERT assert
#else // defined(MSGPACK_NO_BOOST)
#include <boost/assert.hpp>
#define MSGPACK_ASSERT BOOST_ASSERT
#endif // defined(MSGPACK_NO_BOOST)
#endif // MSGPACK_ASSERT_HPP

View File

@ -0,0 +1,18 @@
#ifndef MSGPACK_CPP_VERSION_HPP
#define MSGPACK_CPP_VERSION_HPP
#if defined(_MSC_VER)
# if _MSC_VER < 1900
# define MSGPACK_USE_CPP03
# endif
#elif (__cplusplus < 201103L)
# define MSGPACK_USE_CPP03
#endif
#if defined(_MSVC_LANG)
# define MSGPACK_CPP_VERSION _MSVC_LANG
#else
# define MSGPACK_CPP_VERSION __cplusplus
#endif
#endif // MSGPACK_CPP_VERSION_HPP

View File

@ -1,38 +0,0 @@
/*
* MessagePack for C FILE* buffer adaptor
*
* Copyright (C) 2013 Vladimir Volodko
*
* 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_FBUFFER_H
#define MSGPACK_FBUFFER_H
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup msgpack_fbuffer FILE* buffer
* @ingroup msgpack_buffer
* @{
*/
static inline int msgpack_fbuffer_write(void* data, const char* buf, size_t len)
{
return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1;
}
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* msgpack/fbuffer.h */

View File

@ -1,25 +0,0 @@
/*
* 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_GCC_ATOMIC_H
#define MSGPACK_GCC_ATOMIC_H
#if defined(__cplusplus)
extern "C" {
#endif
typedef int _msgpack_atomic_counter_t;
int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr);
int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr);
#if defined(__cplusplus)
}
#endif
#endif // MSGPACK_GCC_ATOMIC_H

View File

@ -13,7 +13,6 @@
#if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
#include "msgpack/gcc_atomic.h"
#include <bits/atomicity.h>
int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr)

View File

@ -11,8 +11,8 @@
#ifndef MSGPACK_ITERATOR_HPP
#define MSGPACK_ITERATOR_HPP
#include <msgpack/iterator_decl.hpp>
#include "msgpack/iterator_decl.hpp"
#include <msgpack/v1/iterator.hpp>
#include "msgpack/v1/iterator.hpp"
#endif // MSGPACK_ITERATOR_HPP

View File

@ -11,8 +11,8 @@
#ifndef MSGPACK_ITERATOR_DECL_HPP
#define MSGPACK_ITERATOR_DECL_HPP
#include <msgpack/v1/iterator_decl.hpp>
#include <msgpack/v2/iterator_decl.hpp>
#include <msgpack/v3/iterator_decl.hpp>
#include "msgpack/v1/iterator_decl.hpp"
#include "msgpack/v2/iterator_decl.hpp"
#include "msgpack/v3/iterator_decl.hpp"
#endif // MSGPACK_ITERATOR_DECL_HPP

View File

@ -1,118 +0,0 @@
/*
* MessagePack for C dynamic typing routine
*
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
*
* 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_OBJECT_H
#define MSGPACK_OBJECT_H
#include "zone.h"
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup msgpack_object Dynamically typed object
* @ingroup msgpack
* @{
*/
typedef enum {
MSGPACK_OBJECT_NIL = 0x00,
MSGPACK_OBJECT_BOOLEAN = 0x01,
MSGPACK_OBJECT_POSITIVE_INTEGER = 0x02,
MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x03,
MSGPACK_OBJECT_FLOAT32 = 0x0a,
MSGPACK_OBJECT_FLOAT64 = 0x04,
MSGPACK_OBJECT_FLOAT = 0x04,
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
MSGPACK_OBJECT_DOUBLE = MSGPACK_OBJECT_FLOAT, /* obsolete */
#endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */
MSGPACK_OBJECT_STR = 0x05,
MSGPACK_OBJECT_ARRAY = 0x06,
MSGPACK_OBJECT_MAP = 0x07,
MSGPACK_OBJECT_BIN = 0x08,
MSGPACK_OBJECT_EXT = 0x09
} msgpack_object_type;
struct msgpack_object;
struct msgpack_object_kv;
typedef struct {
uint32_t size;
struct msgpack_object* ptr;
} msgpack_object_array;
typedef struct {
uint32_t size;
struct msgpack_object_kv* ptr;
} msgpack_object_map;
typedef struct {
uint32_t size;
const char* ptr;
} msgpack_object_str;
typedef struct {
uint32_t size;
const char* ptr;
} msgpack_object_bin;
typedef struct {
int8_t type;
uint32_t size;
const char* ptr;
} msgpack_object_ext;
typedef union {
bool boolean;
uint64_t u64;
int64_t i64;
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
double dec; /* obsolete*/
#endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */
double f64;
msgpack_object_array array;
msgpack_object_map map;
msgpack_object_str str;
msgpack_object_bin bin;
msgpack_object_ext ext;
} msgpack_object_union;
typedef struct msgpack_object {
msgpack_object_type type;
msgpack_object_union via;
} msgpack_object;
typedef struct msgpack_object_kv {
msgpack_object key;
msgpack_object val;
} msgpack_object_kv;
#if !defined(_KERNEL_MODE)
MSGPACK_DLLEXPORT
void msgpack_object_print(FILE* out, msgpack_object o);
#endif
MSGPACK_DLLEXPORT
int msgpack_object_print_buffer(char *buffer, size_t buffer_size, msgpack_object o);
MSGPACK_DLLEXPORT
bool msgpack_object_equal(const msgpack_object x, const msgpack_object y);
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* msgpack/object.h */

View File

@ -1,174 +0,0 @@
/*
* MessagePack for C packing routine
*
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
*
* 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_PACK_H
#define MSGPACK_PACK_H
#include "pack_define.h"
#include "object.h"
#include "timestamp.h"
#include <stdlib.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup msgpack_buffer Buffers
* @ingroup msgpack
* @{
* @}
*/
/**
* @defgroup msgpack_pack Serializer
* @ingroup msgpack
* @{
*/
typedef int (*msgpack_packer_write)(void* data, const char* buf, size_t len);
typedef struct msgpack_packer {
void* data;
msgpack_packer_write callback;
} msgpack_packer;
static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback);
static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback);
static void msgpack_packer_free(msgpack_packer* pk);
static int msgpack_pack_char(msgpack_packer* pk, char d);
static int msgpack_pack_signed_char(msgpack_packer* pk, signed char d);
static int msgpack_pack_short(msgpack_packer* pk, short d);
static int msgpack_pack_int(msgpack_packer* pk, int d);
static int msgpack_pack_long(msgpack_packer* pk, long d);
static int msgpack_pack_long_long(msgpack_packer* pk, long long d);
static int msgpack_pack_unsigned_char(msgpack_packer* pk, unsigned char d);
static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d);
static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d);
static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d);
static int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d);
static int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d);
static int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d);
static int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d);
static int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d);
static int msgpack_pack_int8(msgpack_packer* pk, int8_t d);
static int msgpack_pack_int16(msgpack_packer* pk, int16_t d);
static int msgpack_pack_int32(msgpack_packer* pk, int32_t d);
static int msgpack_pack_int64(msgpack_packer* pk, int64_t d);
static int msgpack_pack_fix_uint8(msgpack_packer* pk, uint8_t d);
static int msgpack_pack_fix_uint16(msgpack_packer* pk, uint16_t d);
static int msgpack_pack_fix_uint32(msgpack_packer* pk, uint32_t d);
static int msgpack_pack_fix_uint64(msgpack_packer* pk, uint64_t d);
static int msgpack_pack_fix_int8(msgpack_packer* pk, int8_t d);
static int msgpack_pack_fix_int16(msgpack_packer* pk, int16_t d);
static int msgpack_pack_fix_int32(msgpack_packer* pk, int32_t d);
static int msgpack_pack_fix_int64(msgpack_packer* pk, int64_t d);
static int msgpack_pack_float(msgpack_packer* pk, float d);
static int msgpack_pack_double(msgpack_packer* pk, double d);
static int msgpack_pack_nil(msgpack_packer* pk);
static int msgpack_pack_true(msgpack_packer* pk);
static int msgpack_pack_false(msgpack_packer* pk);
static int msgpack_pack_array(msgpack_packer* pk, size_t n);
static int msgpack_pack_map(msgpack_packer* pk, size_t n);
static int msgpack_pack_str(msgpack_packer* pk, size_t l);
static int msgpack_pack_str_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_str_with_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_v4raw(msgpack_packer* pk, size_t l);
static int msgpack_pack_v4raw_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_bin(msgpack_packer* pk, size_t l);
static int msgpack_pack_bin_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_bin_with_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_ext(msgpack_packer* pk, size_t l, int8_t type);
static int msgpack_pack_ext_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_ext_with_body(msgpack_packer* pk, const void* b, size_t l, int8_t type);
static int msgpack_pack_timestamp(msgpack_packer* pk, const msgpack_timestamp* d);
MSGPACK_DLLEXPORT
int msgpack_pack_object(msgpack_packer* pk, msgpack_object d);
/** @} */
#define msgpack_pack_inline_func(name) \
inline int msgpack_pack ## name
#define msgpack_pack_inline_func_cint(name) \
inline int msgpack_pack ## name
#define msgpack_pack_inline_func_fixint(name) \
inline int msgpack_pack_fix ## name
#define msgpack_pack_user msgpack_packer*
#define msgpack_pack_append_buffer(user, buf, len) \
return (*(user)->callback)((user)->data, (const char*)buf, len)
#include "pack_template.h"
inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback)
{
pk->data = data;
pk->callback = callback;
}
inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback)
{
msgpack_packer* pk = (msgpack_packer*)calloc(1, sizeof(msgpack_packer));
if(!pk) { return NULL; }
msgpack_packer_init(pk, data, callback);
return pk;
}
inline void msgpack_packer_free(msgpack_packer* pk)
{
free(pk);
}
inline int msgpack_pack_str_with_body(msgpack_packer* pk, const void* b, size_t l)
{
int ret = msgpack_pack_str(pk, l);
if (ret != 0) { return ret; }
return msgpack_pack_str_body(pk, b, l);
}
inline int msgpack_pack_bin_with_body(msgpack_packer* pk, const void* b, size_t l)
{
int ret = msgpack_pack_bin(pk, l);
if (ret != 0) { return ret; }
return msgpack_pack_bin_body(pk, b, l);
}
inline int msgpack_pack_ext_with_body(msgpack_packer* pk, const void* b, size_t l, int8_t type)
{
int ret = msgpack_pack_ext(pk, l, type);
if (ret != 0) { return ret; }
return msgpack_pack_ext_body(pk, b, l);
}
#ifdef __cplusplus
}
#endif
#endif /* msgpack/pack.h */

View File

@ -1,18 +0,0 @@
/*
* MessagePack unpacking routine template
*
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
*
* 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_PACK_DEFINE_H
#define MSGPACK_PACK_DEFINE_H
#include "msgpack/sysdep.h"
#include <limits.h>
#include <string.h>
#endif /* msgpack/pack_define.h */

View File

@ -1,945 +0,0 @@
/*
* MessagePack packing routine template
*
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
*
* 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)
*/
#if MSGPACK_ENDIAN_LITTLE_BYTE
#define TAKE8_8(d) ((uint8_t*)&d)[0]
#define TAKE8_16(d) ((uint8_t*)&d)[0]
#define TAKE8_32(d) ((uint8_t*)&d)[0]
#define TAKE8_64(d) ((uint8_t*)&d)[0]
#elif MSGPACK_ENDIAN_BIG_BYTE
#define TAKE8_8(d) ((uint8_t*)&d)[0]
#define TAKE8_16(d) ((uint8_t*)&d)[1]
#define TAKE8_32(d) ((uint8_t*)&d)[3]
#define TAKE8_64(d) ((uint8_t*)&d)[7]
#else
#error msgpack-c supports only big endian and little endian
#endif
#ifndef msgpack_pack_inline_func
#error msgpack_pack_inline_func template is not defined
#endif
#ifndef msgpack_pack_user
#error msgpack_pack_user type is not defined
#endif
#ifndef msgpack_pack_append_buffer
#error msgpack_pack_append_buffer callback is not defined
#endif
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable : 4204) /* nonstandard extension used: non-constant aggregate initializer */
#endif
/*
* Integer
*/
#define msgpack_pack_real_uint8(x, d) \
do { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
} else { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} while(0)
#define msgpack_pack_real_uint16(x, d) \
do { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
} else if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} while(0)
#define msgpack_pack_real_uint32(x, d) \
do { \
if(d < (1<<8)) { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
} else { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else { \
if(d < (1<<16)) { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} \
} while(0)
#define msgpack_pack_real_uint64(x, d) \
do { \
if(d < (1ULL<<8)) { \
if(d < (1ULL<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
} else { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else { \
if(d < (1ULL<<16)) { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else if(d < (1ULL<<32)) { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else { \
/* unsigned 64 */ \
unsigned char buf[9]; \
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} \
} \
} while(0)
#define msgpack_pack_real_int8(x, d) \
do { \
if(d < -(1<<5)) { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
} \
} while(0)
#define msgpack_pack_real_int16(x, d) \
do { \
if(d < -(1<<5)) { \
if(d < -(1<<7)) { \
/* signed 16 */ \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
} else { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} \
} while(0)
#define msgpack_pack_real_int32(x, d) \
do { \
if(d < -(1<<5)) { \
if(d < -(1<<15)) { \
/* signed 32 */ \
unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else if(d < -(1<<7)) { \
/* signed 16 */ \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
} else { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else if(d < (1<<16)) { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} \
} while(0)
#define msgpack_pack_real_int64(x, d) \
do { \
if(d < -(1LL<<5)) { \
if(d < -(1LL<<15)) { \
if(d < -(1LL<<31)) { \
/* signed 64 */ \
unsigned char buf[9]; \
buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} else { \
/* signed 32 */ \
unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} else { \
if(d < -(1<<7)) { \
/* signed 16 */ \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
} else { \
if(d < (1LL<<16)) { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} else { \
if(d < (1LL<<32)) { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else { \
/* unsigned 64 */ \
unsigned char buf[9]; \
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} \
} \
} \
} while(0)
#ifdef msgpack_pack_inline_func_fixint
msgpack_pack_inline_func_fixint(_uint8)(msgpack_pack_user x, uint8_t d)
{
unsigned char buf[2] = {0xcc, TAKE8_8(d)};
msgpack_pack_append_buffer(x, buf, 2);
}
msgpack_pack_inline_func_fixint(_uint16)(msgpack_pack_user x, uint16_t d)
{
unsigned char buf[3];
buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3);
}
msgpack_pack_inline_func_fixint(_uint32)(msgpack_pack_user x, uint32_t d)
{
unsigned char buf[5];
buf[0] = 0xce; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func_fixint(_uint64)(msgpack_pack_user x, uint64_t d)
{
unsigned char buf[9];
buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9);
}
msgpack_pack_inline_func_fixint(_int8)(msgpack_pack_user x, int8_t d)
{
unsigned char buf[2] = {0xd0, TAKE8_8(d)};
msgpack_pack_append_buffer(x, buf, 2);
}
msgpack_pack_inline_func_fixint(_int16)(msgpack_pack_user x, int16_t d)
{
unsigned char buf[3];
buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3);
}
msgpack_pack_inline_func_fixint(_int32)(msgpack_pack_user x, int32_t d)
{
unsigned char buf[5];
buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func_fixint(_int64)(msgpack_pack_user x, int64_t d)
{
unsigned char buf[9];
buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9);
}
#undef msgpack_pack_inline_func_fixint
#endif
msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d)
{
msgpack_pack_real_uint8(x, d);
}
msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d)
{
msgpack_pack_real_uint16(x, d);
}
msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d)
{
msgpack_pack_real_uint32(x, d);
}
msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d)
{
msgpack_pack_real_uint64(x, d);
}
msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d)
{
msgpack_pack_real_int8(x, d);
}
msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d)
{
msgpack_pack_real_int16(x, d);
}
msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d)
{
msgpack_pack_real_int32(x, d);
}
msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
{
msgpack_pack_real_int64(x, d);
}
msgpack_pack_inline_func(_char)(msgpack_pack_user x, char d)
{
#if defined(CHAR_MIN)
#if CHAR_MIN < 0
msgpack_pack_real_int8(x, d);
#else
msgpack_pack_real_uint8(x, d);
#endif
#else
#error CHAR_MIN is not defined
#endif
}
msgpack_pack_inline_func(_signed_char)(msgpack_pack_user x, signed char d)
{
msgpack_pack_real_int8(x, d);
}
msgpack_pack_inline_func(_unsigned_char)(msgpack_pack_user x, unsigned char d)
{
msgpack_pack_real_uint8(x, d);
}
#ifdef msgpack_pack_inline_func_cint
msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d)
{
#if defined(SIZEOF_SHORT)
#if SIZEOF_SHORT == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_SHORT == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(SHRT_MAX)
#if SHRT_MAX == 0x7fff
msgpack_pack_real_int16(x, d);
#elif SHRT_MAX == 0x7fffffff
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(short) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(short) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d)
{
#if defined(SIZEOF_INT)
#if SIZEOF_INT == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_INT == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(INT_MAX)
#if INT_MAX == 0x7fff
msgpack_pack_real_int16(x, d);
#elif INT_MAX == 0x7fffffff
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(int) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(int) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d)
{
#if defined(SIZEOF_LONG)
#if SIZEOF_LONG == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_LONG == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(LONG_MAX)
#if LONG_MAX == 0x7fffL
msgpack_pack_real_int16(x, d);
#elif LONG_MAX == 0x7fffffffL
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(long) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(long) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d)
{
#if defined(SIZEOF_LONG_LONG)
#if SIZEOF_LONG_LONG == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_LONG_LONG == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(LLONG_MAX)
#if LLONG_MAX == 0x7fffL
msgpack_pack_real_int16(x, d);
#elif LLONG_MAX == 0x7fffffffL
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(long long) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(long long) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d)
{
#if defined(SIZEOF_SHORT)
#if SIZEOF_SHORT == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_SHORT == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(USHRT_MAX)
#if USHRT_MAX == 0xffffU
msgpack_pack_real_uint16(x, d);
#elif USHRT_MAX == 0xffffffffU
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned short) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned short) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d)
{
#if defined(SIZEOF_INT)
#if SIZEOF_INT == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_INT == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(UINT_MAX)
#if UINT_MAX == 0xffffU
msgpack_pack_real_uint16(x, d);
#elif UINT_MAX == 0xffffffffU
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned int) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned int) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d)
{
#if defined(SIZEOF_LONG)
#if SIZEOF_LONG == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_LONG == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(ULONG_MAX)
#if ULONG_MAX == 0xffffUL
msgpack_pack_real_uint16(x, d);
#elif ULONG_MAX == 0xffffffffUL
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned long) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned long) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
{
#if defined(SIZEOF_LONG_LONG)
#if SIZEOF_LONG_LONG == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_LONG_LONG == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(ULLONG_MAX)
#if ULLONG_MAX == 0xffffUL
msgpack_pack_real_uint16(x, d);
#elif ULLONG_MAX == 0xffffffffUL
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned long long) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned long long) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
#undef msgpack_pack_inline_func_cint
#endif
/*
* Float
*/
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
{
unsigned char buf[5];
union { float f; uint32_t i; } mem;
mem.f = d;
buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
{
unsigned char buf[9];
union { double f; uint64_t i; } mem;
mem.f = d;
buf[0] = 0xcb;
#if defined(TARGET_OS_IPHONE)
// ok
#elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
// https://github.com/msgpack/msgpack-perl/pull/1
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
#endif
_msgpack_store64(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 9);
}
/*
* Nil
*/
msgpack_pack_inline_func(_nil)(msgpack_pack_user x)
{
static const unsigned char d = 0xc0;
msgpack_pack_append_buffer(x, &d, 1);
}
/*
* Boolean
*/
msgpack_pack_inline_func(_true)(msgpack_pack_user x)
{
static const unsigned char d = 0xc3;
msgpack_pack_append_buffer(x, &d, 1);
}
msgpack_pack_inline_func(_false)(msgpack_pack_user x)
{
static const unsigned char d = 0xc2;
msgpack_pack_append_buffer(x, &d, 1);
}
/*
* Array
*/
msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x90 | (uint8_t)n;
msgpack_pack_append_buffer(x, &d, 1);
} else if(n < 65536) {
unsigned char buf[3];
buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
msgpack_pack_append_buffer(x, buf, 5);
}
}
/*
* Map
*/
msgpack_pack_inline_func(_map)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x80 | (uint8_t)n;
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(n < 65536) {
unsigned char buf[3];
buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
msgpack_pack_append_buffer(x, buf, 5);
}
}
/*
* Str
*/
msgpack_pack_inline_func(_str)(msgpack_pack_user x, size_t l)
{
if(l < 32) {
unsigned char d = 0xa0 | (uint8_t)l;
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(l < 256) {
unsigned char buf[2];
buf[0] = 0xd9; buf[1] = (uint8_t)l;
msgpack_pack_append_buffer(x, buf, 2);
} else if(l < 65536) {
unsigned char buf[3];
buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
msgpack_pack_append_buffer(x, buf, 5);
}
}
msgpack_pack_inline_func(_str_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
/*
* Raw (V4)
*/
msgpack_pack_inline_func(_v4raw)(msgpack_pack_user x, size_t l)
{
if(l < 32) {
unsigned char d = 0xa0 | (uint8_t)l;
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(l < 65536) {
unsigned char buf[3];
buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
msgpack_pack_append_buffer(x, buf, 5);
}
}
msgpack_pack_inline_func(_v4raw_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
/*
* Bin
*/
msgpack_pack_inline_func(_bin)(msgpack_pack_user x, size_t l)
{
if(l < 256) {
unsigned char buf[2];
buf[0] = 0xc4; buf[1] = (uint8_t)l;
msgpack_pack_append_buffer(x, buf, 2);
} else if(l < 65536) {
unsigned char buf[3];
buf[0] = 0xc5; _msgpack_store16(&buf[1], (uint16_t)l);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xc6; _msgpack_store32(&buf[1], (uint32_t)l);
msgpack_pack_append_buffer(x, buf, 5);
}
}
msgpack_pack_inline_func(_bin_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
/*
* Ext
*/
msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type)
{
switch(l) {
case 1: {
unsigned char buf[2];
buf[0] = 0xd4;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 2: {
unsigned char buf[2];
buf[0] = 0xd5;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 4: {
unsigned char buf[2];
buf[0] = 0xd6;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 8: {
unsigned char buf[2];
buf[0] = 0xd7;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 16: {
unsigned char buf[2];
buf[0] = 0xd8;
buf[1] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
default:
if(l < 256) {
unsigned char buf[3];
buf[0] = 0xc7;
buf[1] = (unsigned char)l;
buf[2] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 3);
} else if(l < 65536) {
unsigned char buf[4];
buf[0] = 0xc8;
_msgpack_store16(&buf[1], l);
buf[3] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 4);
} else {
unsigned char buf[6];
buf[0] = 0xc9;
_msgpack_store32(&buf[1], l);
buf[5] = (unsigned char)type;
msgpack_pack_append_buffer(x, buf, 6);
}
break;
}
}
msgpack_pack_inline_func(_ext_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
msgpack_pack_inline_func(_timestamp)(msgpack_pack_user x, const msgpack_timestamp* d)
{
if ((((int64_t)d->tv_sec) >> 34) == 0) {
uint64_t data64 = ((uint64_t) d->tv_nsec << 34) | (uint64_t)d->tv_sec;
if ((data64 & 0xffffffff00000000L) == 0) {
// timestamp 32
char buf[4];
uint32_t data32 = (uint32_t)data64;
msgpack_pack_ext(x, 4, -1);
_msgpack_store32(buf, data32);
msgpack_pack_append_buffer(x, buf, 4);
} else {
// timestamp 64
char buf[8];
msgpack_pack_ext(x, 8, -1);
_msgpack_store64(buf, data64);
msgpack_pack_append_buffer(x, buf, 8);
}
} else {
// timestamp 96
char buf[12];
_msgpack_store32(&buf[0], d->tv_nsec);
_msgpack_store64(&buf[4], d->tv_sec);
msgpack_pack_ext(x, 12, -1);
msgpack_pack_append_buffer(x, buf, 12);
}
}
#undef msgpack_pack_inline_func
#undef msgpack_pack_user
#undef msgpack_pack_append_buffer
#undef TAKE8_8
#undef TAKE8_16
#undef TAKE8_32
#undef TAKE8_64
#undef msgpack_pack_real_uint8
#undef msgpack_pack_real_uint16
#undef msgpack_pack_real_uint32
#undef msgpack_pack_real_uint64
#undef msgpack_pack_real_int8
#undef msgpack_pack_real_int16
#undef msgpack_pack_real_int32
#undef msgpack_pack_real_int64
#if defined(_MSC_VER)
# pragma warning(pop)
#endif

View File

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

View File

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

View File

@ -1,110 +0,0 @@
/*
* MessagePack for C simple buffer implementation
*
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
*
* 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_SBUFFER_H
#define MSGPACK_SBUFFER_H
#include <stdlib.h>
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup msgpack_sbuffer Simple buffer
* @ingroup msgpack_buffer
* @{
*/
typedef struct msgpack_sbuffer {
size_t size;
char* data;
size_t alloc;
} msgpack_sbuffer;
static inline void msgpack_sbuffer_init(msgpack_sbuffer* sbuf)
{
memset(sbuf, 0, sizeof(msgpack_sbuffer));
}
static inline void msgpack_sbuffer_destroy(msgpack_sbuffer* sbuf)
{
free(sbuf->data);
}
static inline msgpack_sbuffer* msgpack_sbuffer_new(void)
{
return (msgpack_sbuffer*)calloc(1, sizeof(msgpack_sbuffer));
}
static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf)
{
if(sbuf == NULL) { return; }
msgpack_sbuffer_destroy(sbuf);
free(sbuf);
}
#ifndef MSGPACK_SBUFFER_INIT_SIZE
#define MSGPACK_SBUFFER_INIT_SIZE 8192
#endif
static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
{
msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data;
if(sbuf->alloc - sbuf->size < len) {
void* tmp;
size_t nsize = (sbuf->alloc) ?
sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
while(nsize < sbuf->size + len) {
size_t tmp_nsize = nsize * 2;
if (tmp_nsize <= nsize) {
nsize = sbuf->size + len;
break;
}
nsize = tmp_nsize;
}
tmp = realloc(sbuf->data, nsize);
if(!tmp) { return -1; }
sbuf->data = (char*)tmp;
sbuf->alloc = nsize;
}
memcpy(sbuf->data + sbuf->size, buf, len);
sbuf->size += len;
return 0;
}
static inline char* msgpack_sbuffer_release(msgpack_sbuffer* sbuf)
{
char* tmp = sbuf->data;
sbuf->size = 0;
sbuf->data = NULL;
sbuf->alloc = 0;
return tmp;
}
static inline void msgpack_sbuffer_clear(msgpack_sbuffer* sbuf)
{
sbuf->size = 0;
}
/** @} */
#ifdef __cplusplus
}
#endif
#endif /* msgpack/sbuffer.h */

View File

@ -7,8 +7,8 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef MSGPACK_SYSDEP_H
#define MSGPACK_SYSDEP_H
#ifndef MSGPACK_SYSDEP_HPP
#define MSGPACK_SYSDEP_HPP
#include <stdlib.h>
#include <stddef.h>
@ -26,6 +26,13 @@
typedef unsigned __int32 uint32_t;
typedef signed __int64 int64_t;
typedef unsigned __int64 uint64_t;
# if defined(_WIN64)
typedef signed __int64 intptr_t;
typedef unsigned __int64 uintptr_t;
# else
typedef signed __int32 intptr_t;
typedef unsigned __int32 uintptr_t;
# endif
#elif defined(_MSC_VER) // && _MSC_VER >= 1600
# include <stdint.h>
#else
@ -60,11 +67,7 @@
#endif
#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
# if defined(__cplusplus)
# define _msgpack_atomic_counter_header "msgpack/gcc_atomic.hpp"
# else
# define _msgpack_atomic_counter_header "msgpack/gcc_atomic.h"
# endif
# define _msgpack_atomic_counter_header "msgpack/gcc_atomic.hpp"
#else
typedef unsigned int _msgpack_atomic_counter_t;
@ -74,27 +77,35 @@
#ifdef _WIN32
# ifdef __cplusplus
/* numeric_limits<T>::min,max */
# ifdef max
# undef max
# endif
# ifdef min
# undef min
# endif
# ifdef max
# undef max
# endif
# ifdef min
# undef min
# endif
#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
#endif
#if !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
#if defined(MSGPACK_NO_BOOST)
#include <msgpack/predef/other/endian.h>
#else // defined(MSGPACK_NO_BOOST)
#include <boost/predef/other/endian.h>
#define MSGPACK_ENDIAN_LITTLE_BYTE BOOST_ENDIAN_LITTLE_BYTE
#define MSGPACK_ENDIAN_BIG_BYTE BOOST_ENDIAN_BIG_BYTE
#endif // defined(MSGPACK_NO_BOOST)
#endif // !defined(MSGPACK_ENDIAN_LITTLE_BYTE) && !defined(MSGPACK_ENDIAN_BIG_BYTE)
#if MSGPACK_ENDIAN_LITTLE_BYTE
@ -188,27 +199,8 @@
*/
#if !defined(__cplusplus) && defined(_MSC_VER)
# if !defined(_KERNEL_MODE)
# if !defined(FALSE)
# define FALSE (0)
# endif
# if !defined(TRUE)
# define TRUE (!FALSE)
# endif
# endif
# if _MSC_VER >= 1800
# include <stdbool.h>
# else
# define bool int
# define true TRUE
# define false FALSE
# endif
# define inline __inline
#endif
#ifdef __APPLE__
# include <TargetConditionals.h>
#endif
#endif /* msgpack/sysdep.h */
#endif /* msgpack/sysdep.hpp */

View File

@ -1,58 +0,0 @@
/*
* MessagePack for C TimeStamp
*
* Copyright (C) 2018 KONDO Takatoshi
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef MSGPACK_TIMESTAMP_H
#define MSGPACK_TIMESTAMP_H
#include <msgpack/object.h>
#ifdef __cplusplus
extern "C" {
#endif
typedef struct msgpack_timestamp {
int64_t tv_sec;
uint32_t tv_nsec;
} msgpack_timestamp;
static inline bool msgpack_object_to_timestamp(const msgpack_object* obj, msgpack_timestamp* ts) {
if (obj->type != MSGPACK_OBJECT_EXT) return false;
if (obj->via.ext.type != -1) return false;
switch (obj->via.ext.size) {
case 4:
ts->tv_nsec = 0;
{
uint32_t v;
_msgpack_load32(uint32_t, obj->via.ext.ptr, &v);
ts->tv_sec = v;
}
return true;
case 8: {
uint64_t value;
_msgpack_load64(uint64_t, obj->via.ext.ptr, &value);
ts->tv_nsec = (uint32_t)(value >> 34);
ts->tv_sec = value & 0x00000003ffffffffLL;
return true;
}
case 12:
_msgpack_load32(uint32_t, obj->via.ext.ptr, &ts->tv_nsec);
_msgpack_load64(int64_t, obj->via.ext.ptr + 4, &ts->tv_sec);
return true;
default:
return false;
}
}
#ifdef __cplusplus
}
#endif
#endif /* msgpack/timestamp.h */

View File

@ -8,6 +8,7 @@
#include "adaptor/fixint.hpp"
#include "adaptor/float.hpp"
#include "adaptor/int.hpp"
#include "adaptor/complex.hpp"
#include "adaptor/list.hpp"
#include "adaptor/map.hpp"
#include "adaptor/nil.hpp"
@ -35,7 +36,9 @@
#include "adaptor/cpp11/array.hpp"
#include "adaptor/cpp11/array_char.hpp"
#include "adaptor/cpp11/array_unsigned_char.hpp"
#include "adaptor/cpp11/chrono.hpp"
#include "adaptor/cpp11/forward_list.hpp"
#include "adaptor/cpp11/reference_wrapper.hpp"
#include "adaptor/cpp11/shared_ptr.hpp"
@ -53,18 +56,29 @@
#include "adaptor/cpp17/string_view.hpp"
#endif // MSGPACK_HAS_INCLUDE(<string_view>)
#include "adaptor/cpp17/array_byte.hpp"
#include "adaptor/cpp17/byte.hpp"
#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>)
#endif // defined(MSGPACK_USE_CPP03)
#if defined(MSGPACK_USE_BOOST)
#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"
#endif // defined(MSGPACK_USE_BOOST)
#endif // !defined(MSGPACK_NO_BOOST)

View File

@ -1,281 +0,0 @@
/*
* MessagePack for C unpacking routine
*
* Copyright (C) 2008-2009 FURUHASHI Sadayuki
*
* 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_UNPACKER_H
#define MSGPACK_UNPACKER_H
#include "zone.h"
#include "object.h"
#include <string.h>
#ifdef __cplusplus
extern "C" {
#endif
/**
* @defgroup msgpack_unpack Deserializer
* @ingroup msgpack
* @{
*/
typedef struct msgpack_unpacked {
msgpack_zone* zone;
msgpack_object data;
} msgpack_unpacked;
typedef enum {
MSGPACK_UNPACK_SUCCESS = 2,
MSGPACK_UNPACK_EXTRA_BYTES = 1,
MSGPACK_UNPACK_CONTINUE = 0,
MSGPACK_UNPACK_PARSE_ERROR = -1,
MSGPACK_UNPACK_NOMEM_ERROR = -2
} msgpack_unpack_return;
MSGPACK_DLLEXPORT
msgpack_unpack_return
msgpack_unpack_next(msgpack_unpacked* result,
const char* data, size_t len, size_t* off);
/** @} */
/**
* @defgroup msgpack_unpacker Streaming deserializer
* @ingroup msgpack
* @{
*/
typedef struct msgpack_unpacker {
char* buffer;
size_t used;
size_t free;
size_t off;
size_t parsed;
msgpack_zone* z;
size_t initial_buffer_size;
void* ctx;
} msgpack_unpacker;
#ifndef MSGPACK_UNPACKER_INIT_BUFFER_SIZE
#define MSGPACK_UNPACKER_INIT_BUFFER_SIZE (64*1024)
#endif
/**
* Initializes a streaming deserializer.
* The initialized deserializer must be destroyed by msgpack_unpacker_destroy(msgpack_unpacker*).
*/
MSGPACK_DLLEXPORT
bool msgpack_unpacker_init(msgpack_unpacker* mpac, size_t initial_buffer_size);
/**
* Destroys a streaming deserializer initialized by msgpack_unpacker_init(msgpack_unpacker*, size_t).
*/
MSGPACK_DLLEXPORT
void msgpack_unpacker_destroy(msgpack_unpacker* mpac);
/**
* Creates a streaming deserializer.
* The created deserializer must be destroyed by msgpack_unpacker_free(msgpack_unpacker*).
*/
MSGPACK_DLLEXPORT
msgpack_unpacker* msgpack_unpacker_new(size_t initial_buffer_size);
/**
* Frees a streaming deserializer created by msgpack_unpacker_new(size_t).
*/
MSGPACK_DLLEXPORT
void msgpack_unpacker_free(msgpack_unpacker* mpac);
#ifndef MSGPACK_UNPACKER_RESERVE_SIZE
#define MSGPACK_UNPACKER_RESERVE_SIZE (32*1024)
#endif
/**
* Reserves free space of the internal buffer.
* Use this function to fill the internal buffer with
* msgpack_unpacker_buffer(msgpack_unpacker*),
* msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and
* msgpack_unpacker_buffer_consumed(msgpack_unpacker*).
*/
static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size);
/**
* Gets pointer to the free space of the internal buffer.
* Use this function to fill the internal buffer with
* msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t),
* msgpack_unpacker_buffer_capacity(const msgpack_unpacker*) and
* msgpack_unpacker_buffer_consumed(msgpack_unpacker*).
*/
static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac);
/**
* Gets size of the free space of the internal buffer.
* Use this function to fill the internal buffer with
* msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t),
* msgpack_unpacker_buffer(const msgpack_unpacker*) and
* msgpack_unpacker_buffer_consumed(msgpack_unpacker*).
*/
static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac);
/**
* Notifies the deserializer that the internal buffer filled.
* Use this function to fill the internal buffer with
* msgpack_unpacker_reserve_buffer(msgpack_unpacker*, size_t),
* msgpack_unpacker_buffer(msgpack_unpacker*) and
* msgpack_unpacker_buffer_capacity(const msgpack_unpacker*).
*/
static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size);
/**
* Deserializes one object.
* Returns true if it successes. Otherwise false is returned.
* @param pac pointer to an initialized msgpack_unpacked object.
*/
MSGPACK_DLLEXPORT
msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac);
/**
* Deserializes one object and set the number of parsed bytes involved.
* Returns true if it successes. Otherwise false is returned.
* @param mpac pointer to an initialized msgpack_unpacker object.
* @param result pointer to an initialized msgpack_unpacked object.
* @param p_bytes pointer to variable that will be set with the number of parsed bytes.
*/
MSGPACK_DLLEXPORT
msgpack_unpack_return msgpack_unpacker_next_with_size(msgpack_unpacker* mpac,
msgpack_unpacked* result,
size_t *p_bytes);
/**
* Initializes a msgpack_unpacked object.
* The initialized object must be destroyed by msgpack_unpacked_destroy(msgpack_unpacker*).
* Use the object with msgpack_unpacker_next(msgpack_unpacker*, msgpack_unpacked*) or
* msgpack_unpack_next(msgpack_unpacked*, const char*, size_t, size_t*).
*/
static inline void msgpack_unpacked_init(msgpack_unpacked* result);
/**
* Destroys a streaming deserializer initialized by msgpack_unpacked().
*/
static inline void msgpack_unpacked_destroy(msgpack_unpacked* result);
/**
* Releases the memory zone from msgpack_unpacked object.
* The released zone must be freed by msgpack_zone_free(msgpack_zone*).
*/
static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result);
MSGPACK_DLLEXPORT
int msgpack_unpacker_execute(msgpack_unpacker* mpac);
MSGPACK_DLLEXPORT
msgpack_object msgpack_unpacker_data(msgpack_unpacker* mpac);
MSGPACK_DLLEXPORT
msgpack_zone* msgpack_unpacker_release_zone(msgpack_unpacker* mpac);
MSGPACK_DLLEXPORT
void msgpack_unpacker_reset_zone(msgpack_unpacker* mpac);
MSGPACK_DLLEXPORT
void msgpack_unpacker_reset(msgpack_unpacker* mpac);
static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac);
/** @} */
// obsolete
MSGPACK_DLLEXPORT
msgpack_unpack_return
msgpack_unpack(const char* data, size_t len, size_t* off,
msgpack_zone* result_zone, msgpack_object* result);
static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac);
MSGPACK_DLLEXPORT
bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac);
MSGPACK_DLLEXPORT
bool msgpack_unpacker_expand_buffer(msgpack_unpacker* mpac, size_t size);
static inline bool msgpack_unpacker_reserve_buffer(msgpack_unpacker* mpac, size_t size)
{
if(mpac->free >= size) { return true; }
return msgpack_unpacker_expand_buffer(mpac, size);
}
static inline char* msgpack_unpacker_buffer(msgpack_unpacker* mpac)
{
return mpac->buffer + mpac->used;
}
static inline size_t msgpack_unpacker_buffer_capacity(const msgpack_unpacker* mpac)
{
return mpac->free;
}
static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, size_t size)
{
mpac->used += size;
mpac->free -= size;
}
static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac)
{
return mpac->parsed - mpac->off + mpac->used;
}
static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac)
{
return mpac->parsed;
}
static inline void msgpack_unpacked_init(msgpack_unpacked* result)
{
memset(result, 0, sizeof(msgpack_unpacked));
}
static inline void msgpack_unpacked_destroy(msgpack_unpacked* result)
{
if(result->zone != NULL) {
msgpack_zone_free(result->zone);
result->zone = NULL;
memset(&result->data, 0, sizeof(msgpack_object));
}
}
static inline msgpack_zone* msgpack_unpacked_release_zone(msgpack_unpacked* result)
{
if(result->zone != NULL) {
msgpack_zone* z = result->zone;
result->zone = NULL;
return z;
}
return NULL;
}
#ifdef __cplusplus
}
#endif
#endif /* msgpack/unpack.h */

View File

@ -7,19 +7,10 @@
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef MSGPACK_UNPACK_DEFINE_H
#define MSGPACK_UNPACK_DEFINE_H
#include "msgpack/sysdep.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MSGPACK_UNPACK_DEFINE_HPP
#define MSGPACK_UNPACK_DEFINE_HPP
#include "msgpack/sysdep.hpp"
#ifndef MSGPACK_EMBED_STACK_SIZE
#define MSGPACK_EMBED_STACK_SIZE 32
@ -81,9 +72,4 @@ typedef enum {
} msgpack_container_type;
#ifdef __cplusplus
}
#endif
#endif /* msgpack/unpack_define.h */
#endif /* msgpack/unpack_define.hpp */

View File

@ -1,471 +0,0 @@
/*
* MessagePack unpacking routine template
*
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
*
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
*/
#ifndef msgpack_unpack_func
#error msgpack_unpack_func template is not defined
#endif
#ifndef msgpack_unpack_callback
#error msgpack_unpack_callback template is not defined
#endif
#ifndef msgpack_unpack_struct
#error msgpack_unpack_struct template is not defined
#endif
#ifndef msgpack_unpack_struct_decl
#define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name)
#endif
#ifndef msgpack_unpack_object
#error msgpack_unpack_object type is not defined
#endif
#ifndef msgpack_unpack_user
#error msgpack_unpack_user type is not defined
#endif
#ifndef USE_CASE_RANGE
#if !defined(_MSC_VER)
#define USE_CASE_RANGE
#endif
#endif
#if defined(_KERNEL_MODE)
#undef assert
#define assert NT_ASSERT
#endif
msgpack_unpack_struct_decl(_stack) {
msgpack_unpack_object obj;
size_t count;
unsigned int ct;
msgpack_unpack_object map_key;
};
msgpack_unpack_struct_decl(_context) {
msgpack_unpack_user user;
unsigned int cs;
unsigned int trail;
unsigned int top;
/*
msgpack_unpack_struct(_stack)* stack;
unsigned int stack_size;
msgpack_unpack_struct(_stack) embed_stack[MSGPACK_EMBED_STACK_SIZE];
*/
msgpack_unpack_struct(_stack) stack[MSGPACK_EMBED_STACK_SIZE];
};
msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx)
{
ctx->cs = MSGPACK_CS_HEADER;
ctx->trail = 0;
ctx->top = 0;
/*
ctx->stack = ctx->embed_stack;
ctx->stack_size = MSGPACK_EMBED_STACK_SIZE;
*/
ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user);
}
/*
msgpack_unpack_func(void, _destroy)(msgpack_unpack_struct(_context)* ctx)
{
if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) {
free(ctx->stack);
}
}
*/
msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx)
{
return (ctx)->stack[0].obj;
}
msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
{
assert(len >= *off);
{
const unsigned char* p = (unsigned char*)data + *off;
const unsigned char* const pe = (unsigned char*)data + len;
const void* n = NULL;
unsigned int trail = ctx->trail;
unsigned int cs = ctx->cs;
unsigned int top = ctx->top;
msgpack_unpack_struct(_stack)* stack = ctx->stack;
/*
unsigned int stack_size = ctx->stack_size;
*/
msgpack_unpack_user* user = &ctx->user;
msgpack_unpack_object obj;
msgpack_unpack_struct(_stack)* c = NULL;
int ret;
#define push_simple_value(func) \
ret = msgpack_unpack_callback(func)(user, &obj); \
if(ret < 0) { goto _failed; } \
goto _push
#define push_fixed_value(func, arg) \
ret = msgpack_unpack_callback(func)(user, arg, &obj); \
if(ret < 0) { goto _failed; } \
goto _push
#define push_variable_value(func, base, pos, len) \
ret = msgpack_unpack_callback(func)(user, \
(const char*)base, (const char*)pos, len, &obj); \
if(ret < 0) { goto _failed; } \
goto _push
#define again_fixed_trail(_cs, trail_len) \
trail = trail_len; \
cs = _cs; \
goto _fixed_trail_again
#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \
trail = trail_len; \
if(trail == 0) { goto ifzero; } \
cs = _cs; \
goto _fixed_trail_again
#define start_container(func, count_, ct_) \
if(top >= MSGPACK_EMBED_STACK_SIZE) { \
ret = MSGPACK_UNPACK_NOMEM_ERROR; \
goto _failed; \
} /* FIXME */ \
ret = msgpack_unpack_callback(func)(user, count_, &stack[top].obj); \
if(ret < 0) { goto _failed; } \
if((count_) == 0) { obj = stack[top].obj; goto _push; } \
stack[top].ct = ct_; \
stack[top].count = count_; \
++top; \
goto _header_again
#define NEXT_CS(p) \
((unsigned int)*p & 0x1f)
#ifdef USE_CASE_RANGE
#define SWITCH_RANGE_BEGIN switch(*p) {
#define SWITCH_RANGE(FROM, TO) case FROM ... TO:
#define SWITCH_RANGE_DEFAULT default:
#define SWITCH_RANGE_END }
#else
#define SWITCH_RANGE_BEGIN { if(0) {
#define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) {
#define SWITCH_RANGE_DEFAULT } else {
#define SWITCH_RANGE_END } }
#endif
if(p == pe) { goto _out; }
do {
switch(cs) {
case MSGPACK_CS_HEADER:
SWITCH_RANGE_BEGIN
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
push_fixed_value(_uint8, *(uint8_t*)p);
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
push_fixed_value(_int8, *(int8_t*)p);
SWITCH_RANGE(0xc0, 0xdf) // Variable
switch(*p) {
case 0xc0: // nil
push_simple_value(_nil);
//case 0xc1: // string
// again_terminal_trail(NEXT_CS(p), p+1);
case 0xc2: // false
push_simple_value(_false);
case 0xc3: // true
push_simple_value(_true);
case 0xc4: // bin 8
case 0xc5: // bin 16
case 0xc6: // bin 32
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
case 0xc7: // ext 8
case 0xc8: // ext 16
case 0xc9: // ext 32
again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) + 1) & 0x03));
case 0xca: // float
case 0xcb: // double
case 0xcc: // unsigned int 8
case 0xcd: // unsigned int 16
case 0xce: // unsigned int 32
case 0xcf: // unsigned int 64
case 0xd0: // signed int 8
case 0xd1: // signed int 16
case 0xd2: // signed int 32
case 0xd3: // signed int 64
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
case 0xd4: // fixext 1
case 0xd5: // fixext 2
case 0xd6: // fixext 4
case 0xd7: // fixext 8
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE,
(1 << (((unsigned int)*p) & 0x03)) + 1, _ext_zero);
case 0xd8: // fixext 16
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 16+1, _ext_zero);
case 0xd9: // str 8
case 0xda: // str 16
case 0xdb: // str 32
again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) & 0x03) - 1));
case 0xdc: // array 16
case 0xdd: // array 32
case 0xde: // map 16
case 0xdf: // map 32
again_fixed_trail(NEXT_CS(p), 2u << (((unsigned int)*p) & 0x01));
default:
ret = MSGPACK_UNPACK_PARSE_ERROR;
goto _failed;
}
SWITCH_RANGE(0xa0, 0xbf) // FixStr
again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, ((unsigned int)*p & 0x1f), _str_zero);
SWITCH_RANGE(0x90, 0x9f) // FixArray
start_container(_array, ((unsigned int)*p) & 0x0f, MSGPACK_CT_ARRAY_ITEM);
SWITCH_RANGE(0x80, 0x8f) // FixMap
start_container(_map, ((unsigned int)*p) & 0x0f, MSGPACK_CT_MAP_KEY);
SWITCH_RANGE_DEFAULT
ret = MSGPACK_UNPACK_PARSE_ERROR;
goto _failed;
SWITCH_RANGE_END
// end MSGPACK_CS_HEADER
_fixed_trail_again:
++p;
// fallthrough
default:
if((size_t)(pe - p) < trail) { goto _out; }
n = p; p += trail - 1;
switch(cs) {
//case MSGPACK_CS_
//case MSGPACK_CS_
case MSGPACK_CS_FLOAT: {
union { uint32_t i; float f; } mem;
_msgpack_load32(uint32_t, n, &mem.i);
push_fixed_value(_float, mem.f); }
case MSGPACK_CS_DOUBLE: {
union { uint64_t i; double f; } mem;
_msgpack_load64(uint64_t, n, &mem.i);
#if defined(TARGET_OS_IPHONE)
// ok
#elif defined(__arm__) && !(__ARM_EABI__) // arm-oabi
// https://github.com/msgpack/msgpack-perl/pull/1
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
#endif
push_fixed_value(_double, mem.f); }
case MSGPACK_CS_UINT_8:
push_fixed_value(_uint8, *(uint8_t*)n);
case MSGPACK_CS_UINT_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
push_fixed_value(_uint16, tmp);
}
case MSGPACK_CS_UINT_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
push_fixed_value(_uint32, tmp);
}
case MSGPACK_CS_UINT_64:{
uint64_t tmp;
_msgpack_load64(uint64_t,n,&tmp);
push_fixed_value(_uint64, tmp);
}
case MSGPACK_CS_INT_8:
push_fixed_value(_int8, *(int8_t*)n);
case MSGPACK_CS_INT_16:{
int16_t tmp;
_msgpack_load16(int16_t,n,&tmp);
push_fixed_value(_int16, tmp);
}
case MSGPACK_CS_INT_32:{
int32_t tmp;
_msgpack_load32(int32_t,n,&tmp);
push_fixed_value(_int32, tmp);
}
case MSGPACK_CS_INT_64:{
int64_t tmp;
_msgpack_load64(int64_t,n,&tmp);
push_fixed_value(_int64, tmp);
}
case MSGPACK_CS_FIXEXT_1:
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 1+1, _ext_zero);
case MSGPACK_CS_FIXEXT_2:
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 2+1, _ext_zero);
case MSGPACK_CS_FIXEXT_4:
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 4+1, _ext_zero);
case MSGPACK_CS_FIXEXT_8:
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 8+1, _ext_zero);
case MSGPACK_CS_FIXEXT_16:
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, 16+1, _ext_zero);
case MSGPACK_CS_STR_8:
again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, *(uint8_t*)n, _str_zero);
case MSGPACK_CS_BIN_8:
again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, *(uint8_t*)n, _bin_zero);
case MSGPACK_CS_EXT_8:
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, (*(uint8_t*)n) + 1, _ext_zero);
case MSGPACK_CS_STR_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, tmp, _str_zero);
}
case MSGPACK_CS_BIN_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, tmp, _bin_zero);
}
case MSGPACK_CS_EXT_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, tmp + 1, _ext_zero);
}
case MSGPACK_CS_STR_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
again_fixed_trail_if_zero(MSGPACK_ACS_STR_VALUE, tmp, _str_zero);
}
case MSGPACK_CS_BIN_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
again_fixed_trail_if_zero(MSGPACK_ACS_BIN_VALUE, tmp, _bin_zero);
}
case MSGPACK_CS_EXT_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
again_fixed_trail_if_zero(MSGPACK_ACS_EXT_VALUE, tmp + 1, _ext_zero);
}
case MSGPACK_ACS_STR_VALUE:
_str_zero:
push_variable_value(_str, data, n, trail);
case MSGPACK_ACS_BIN_VALUE:
_bin_zero:
push_variable_value(_bin, data, n, trail);
case MSGPACK_ACS_EXT_VALUE:
_ext_zero:
push_variable_value(_ext, data, n, trail);
case MSGPACK_CS_ARRAY_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
start_container(_array, tmp, MSGPACK_CT_ARRAY_ITEM);
}
case MSGPACK_CS_ARRAY_32:{
/* FIXME security guard */
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
start_container(_array, tmp, MSGPACK_CT_ARRAY_ITEM);
}
case MSGPACK_CS_MAP_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
start_container(_map, tmp, MSGPACK_CT_MAP_KEY);
}
case MSGPACK_CS_MAP_32:{
/* FIXME security guard */
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
start_container(_map, tmp, MSGPACK_CT_MAP_KEY);
}
default:
ret = MSGPACK_UNPACK_PARSE_ERROR;
goto _failed;
}
}
_push:
if(top == 0) { goto _finish; }
c = &stack[top-1];
switch(c->ct) {
case MSGPACK_CT_ARRAY_ITEM:
ret = msgpack_unpack_callback(_array_item)(user, &c->obj, obj); \
if(ret < 0) { goto _failed; }
if(--c->count == 0) {
obj = c->obj;
--top;
/*printf("stack pop %d\n", top);*/
goto _push;
}
goto _header_again;
case MSGPACK_CT_MAP_KEY:
c->map_key = obj;
c->ct = MSGPACK_CT_MAP_VALUE;
goto _header_again;
case MSGPACK_CT_MAP_VALUE:
ret = msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj); \
if(ret < 0) { goto _failed; }
if(--c->count == 0) {
obj = c->obj;
--top;
/*printf("stack pop %d\n", top);*/
goto _push;
}
c->ct = MSGPACK_CT_MAP_KEY;
goto _header_again;
default:
ret = MSGPACK_UNPACK_PARSE_ERROR;
goto _failed;
}
_header_again:
cs = MSGPACK_CS_HEADER;
++p;
} while(p != pe);
goto _out;
_finish:
stack[0].obj = obj;
++p;
ret = 1;
/*printf("-- finish --\n"); */
goto _end;
_failed:
/*printf("** FAILED **\n"); */
goto _end;
_out:
ret = 0;
goto _end;
_end:
ctx->cs = cs;
ctx->trail = trail;
ctx->top = top;
*off = (size_t)(p - (const unsigned char*)data);
return ret;
}
}
#undef msgpack_unpack_func
#undef msgpack_unpack_callback
#undef msgpack_unpack_struct
#undef msgpack_unpack_object
#undef msgpack_unpack_user
#undef push_simple_value
#undef push_fixed_value
#undef push_variable_value
#undef again_fixed_trail
#undef again_fixed_trail_if_zero
#undef start_container
#undef NEXT_CS
#undef SWITCH_RANGE_BEGIN
#undef SWITCH_RANGE
#undef SWITCH_RANGE_DEFAULT
#undef SWITCH_RANGE_END

View File

@ -1,15 +0,0 @@
/*
* MessagePack for C utilities
*
* Copyright (C) 2014 FURUHASHI Sadayuki
*
* 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_UTIL_H
#define MSGPACK_UTIL_H
#define MSGPACK_UNUSED(a) (void)(a)
#endif /* MSGPACK_UTIL_H */

View File

@ -12,6 +12,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
namespace msgpack {

View File

@ -12,6 +12,7 @@
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
namespace msgpack {

View File

@ -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"
@ -21,11 +22,23 @@
#include "msgpack/adaptor/cpp11/tuple.hpp"
#endif // #if !defined (MSGPACK_USE_CPP03)
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif // defined(__GNUC__)
#include <boost/fusion/support/is_sequence.hpp>
#include <boost/fusion/sequence/intrinsic/size.hpp>
#include <boost/fusion/algorithm/iteration/for_each.hpp>
#include <boost/fusion/sequence/intrinsic/at.hpp>
#include <boost/fusion/include/mpl.hpp>
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // defined(__GNUC__)
#include <boost/mpl/size.hpp>
namespace msgpack {
@ -111,7 +124,7 @@ struct as<
template<std::size_t... Is, typename U>
static std::tuple<
typename std::remove_reference<
typename boost::fusion::result_of::at_c<T, Is>::type
typename boost::fusion::result_of::at_c<T, static_cast<int>(Is)>::type
>::type...>
to_tuple(U const& u, seq<Is...>) {
return std::make_tuple(boost::fusion::at_c<Is>(u)...);

View File

@ -10,8 +10,6 @@
#ifndef MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP
#define MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP
#if defined(MSGPACK_USE_BOOST)
#include "msgpack/v1/adaptor/boost/msgpack_variant_decl.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
@ -28,7 +26,18 @@
#include "msgpack/adaptor/vector.hpp"
#include "msgpack/adaptor/map.hpp"
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif // defined(__GNUC__)
#include <boost/variant.hpp>
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // defined(__GNUC__)
#include <boost/operators.hpp>
namespace msgpack {
@ -113,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;
@ -168,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) {
@ -243,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>
@ -439,5 +446,4 @@ struct object_with_zone<type::basic_variant<STR, BIN, EXT> > {
} // namespace msgpack
#endif // MSGPACK_USE_BOOST
#endif // MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_HPP

View File

@ -10,10 +10,9 @@
#ifndef MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP
#define MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP
#if defined(MSGPACK_USE_BOOST)
#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"
@ -58,5 +57,4 @@ typedef basic_variant<
} // namespace msgpack
#endif // MSGPACK_USE_BOOST
#endif // MSGPACK_V1_TYPE_BOOST_MSGPACK_VARIANT_DECL_HPP

View File

@ -12,8 +12,14 @@
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#if defined(__GNUC__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wconversion"
#endif // defined(__GNUC__)
// To suppress warning on Boost.1.58.0
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
#pragma GCC diagnostic push
@ -26,6 +32,10 @@
#pragma GCC diagnostic pop
#endif // defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) || defined(__clang__)
#if defined(__GNUC__)
#pragma GCC diagnostic pop
#endif // defined(__GNUC__)
namespace msgpack {
/// @cond

View File

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

View File

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

View File

@ -12,7 +12,7 @@
#include "msgpack/versioning.hpp"
#include <cstdlib>
#include "msgpack/sysdep.h"
#include "msgpack/sysdep.hpp"
namespace msgpack {

View File

@ -0,0 +1,91 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2020 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_V1_TYPE_COMPLEX_HPP
#define MSGPACK_V1_TYPE_COMPLEX_HPP
#include <complex>
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/meta.hpp"
namespace msgpack {
/// @cond
MSGPACK_API_VERSION_NAMESPACE(v1) {
/// @endcond
namespace adaptor {
#if !defined(MSGPACK_USE_CPP03)
template <typename T>
struct as<std::complex<T>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
std::complex<T> operator()(msgpack::object const& o) const {
if (o.type != msgpack::type::ARRAY)
throw msgpack::type_error();
if (o.via.array.size != 2)
throw msgpack::type_error();
return std::complex<T>(o.via.array.ptr[0].as<T>(), o.via.array.ptr[1].as<T>());
}
};
#endif // !defined(MSGPACK_USE_CPP03)
template <typename T>
struct convert<std::complex<T> > {
msgpack::object const& operator()(msgpack::object const& o, std::complex<T>& v) const {
if(o.type != msgpack::type::ARRAY)
throw msgpack::type_error();
if(o.via.array.size != 2)
throw msgpack::type_error();
T real;
T imag;
o.via.array.ptr[0].convert(real);
o.via.array.ptr[1].convert(imag);
v.real(real);
v.imag(imag);
return o;
}
};
template <typename T>
struct pack<std::complex<T> > {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, std::complex<T> const& v) const {
o.pack_array(2);
o.pack(v.real());
o.pack(v.imag());
return o;
}
};
template <typename T>
struct object_with_zone<std::complex<T> > {
void operator()(msgpack::object::with_zone& o, std::complex<T> const& v) const {
o.type = msgpack::type::ARRAY;
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*2, MSGPACK_ZONE_ALIGNOF(msgpack::object)));
o.via.array.ptr = p;
o.via.array.size = 2;
p[0] = msgpack::object(v.real(), o.zone);
p[1] = msgpack::object(v.imag(), o.zone);
}
};
} // namespace adaptor
/// @cond
} // MSGPACK_API_VERSION_NAMESPACE(v1)
/// @endcond
} // namespace msgpack
#endif // MSGPACK_V1_TYPE_COMPLEX_HPP

View File

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

View File

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

View File

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

View File

@ -13,8 +13,10 @@
#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>
namespace msgpack {
@ -25,12 +27,119 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace adaptor {
template <>
struct as<std::chrono::system_clock::time_point> {
typename std::chrono::system_clock::time_point operator()(msgpack::object const& o) const {
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 {
if(o.type != msgpack::type::EXT) { throw msgpack::type_error(); }
if(o.via.ext.type() != -1) { throw msgpack::type_error(); }
std::chrono::system_clock::time_point tp;
std::chrono::time_point<Clock, Duration> tp;
switch(o.via.ext.size) {
case 4: {
uint32_t sec;
@ -40,9 +149,9 @@ struct as<std::chrono::system_clock::time_point> {
case 8: {
uint64_t value;
_msgpack_load64(uint64_t, o.via.ext.data(), &value);
uint32_t nanosec = static_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<std::chrono::system_clock::duration>(
tp += std::chrono::duration_cast<Duration>(
std::chrono::nanoseconds(nanosec));
tp += std::chrono::seconds(sec);
} break;
@ -51,9 +160,24 @@ struct as<std::chrono::system_clock::time_point> {
_msgpack_load32(uint32_t, o.via.ext.data(), &nanosec);
int64_t sec;
_msgpack_load64(int64_t, o.via.ext.data() + 4, &sec);
tp += std::chrono::duration_cast<std::chrono::system_clock::duration>(
std::chrono::nanoseconds(nanosec));
tp += std::chrono::seconds(sec);
if (sec > 0) {
tp += std::chrono::seconds(sec);
tp += std::chrono::duration_cast<Duration>(
std::chrono::nanoseconds(nanosec));
}
else {
if (nanosec == 0) {
tp += std::chrono::seconds(sec);
}
else {
++sec;
tp += std::chrono::seconds(sec);
int64_t ns = detail::integral_cast<int64_t>(nanosec) - 1000000000L;
tp += std::chrono::duration_cast<Duration>(
std::chrono::nanoseconds(ns));
}
}
} break;
default:
throw msgpack::type_error();
@ -62,12 +186,12 @@ struct as<std::chrono::system_clock::time_point> {
}
};
template <>
struct convert<std::chrono::system_clock::time_point> {
msgpack::object const& operator()(msgpack::object const& o, std::chrono::system_clock::time_point& v) const {
template <typename Clock, typename Duration>
struct convert<std::chrono::time_point<Clock, Duration>> {
msgpack::object const& operator()(msgpack::object const& o, std::chrono::time_point<Clock, Duration>& v) const {
if(o.type != msgpack::type::EXT) { throw msgpack::type_error(); }
if(o.via.ext.type() != -1) { throw msgpack::type_error(); }
std::chrono::system_clock::time_point tp;
std::chrono::time_point<Clock, Duration> tp;
switch(o.via.ext.size) {
case 4: {
uint32_t sec;
@ -78,9 +202,9 @@ struct convert<std::chrono::system_clock::time_point> {
case 8: {
uint64_t value;
_msgpack_load64(uint64_t, o.via.ext.data(), &value);
uint32_t nanosec = static_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<std::chrono::system_clock::duration>(
tp += std::chrono::duration_cast<Duration>(
std::chrono::nanoseconds(nanosec));
tp += std::chrono::seconds(sec);
v = tp;
@ -90,9 +214,25 @@ struct convert<std::chrono::system_clock::time_point> {
_msgpack_load32(uint32_t, o.via.ext.data(), &nanosec);
int64_t sec;
_msgpack_load64(int64_t, o.via.ext.data() + 4, &sec);
tp += std::chrono::duration_cast<std::chrono::system_clock::duration>(
std::chrono::nanoseconds(nanosec));
tp += std::chrono::seconds(sec);
if (sec > 0) {
tp += std::chrono::seconds(sec);
tp += std::chrono::duration_cast<Duration>(
std::chrono::nanoseconds(nanosec));
}
else {
if (nanosec == 0) {
tp += std::chrono::seconds(sec);
}
else {
++sec;
tp += std::chrono::seconds(sec);
int64_t ns = detail::integral_cast<int64_t>(nanosec) - 1000000000L;
tp += std::chrono::duration_cast<Duration>(
std::chrono::nanoseconds(ns));
}
}
v = tp;
} break;
default:
@ -102,31 +242,31 @@ struct convert<std::chrono::system_clock::time_point> {
}
};
template <>
struct pack<std::chrono::system_clock::time_point> {
template <typename Clock, typename Duration>
struct pack<std::chrono::time_point<Clock, Duration>> {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::chrono::system_clock::time_point& v) const {
int64_t count = static_cast<int64_t>(v.time_since_epoch().count());
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, std::chrono::time_point<Clock, Duration> const& v) const {
int64_t count = detail::integral_cast<int64_t>(v.time_since_epoch().count());
int64_t nano_num =
std::chrono::system_clock::duration::period::ratio::num *
(1000000000 / std::chrono::system_clock::duration::period::ratio::den);
Duration::period::ratio::num *
(1000000000L / Duration::period::ratio::den);
int64_t nanosec = count % (1000000000 / nano_num) * nano_num;
int64_t nanosec = count % (1000000000L / nano_num) * nano_num;
int64_t sec = 0;
if (nanosec < 0) {
nanosec = 1000000000 + nanosec;
nanosec = 1000000000L + nanosec;
--sec;
}
sec += count
* std::chrono::system_clock::duration::period::ratio::num
/ std::chrono::system_clock::duration::period::ratio::den;
* Duration::period::ratio::num
/ Duration::period::ratio::den;
if ((sec >> 34) == 0) {
uint64_t data64 = (static_cast<uint64_t>(nanosec) << 34) | static_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 = static_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);
@ -143,7 +283,9 @@ struct pack<std::chrono::system_clock::time_point> {
// timestamp 96
o.pack_ext(12, -1);
char buf[12];
_msgpack_store32(&buf[0], static_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);
}
@ -151,33 +293,33 @@ struct pack<std::chrono::system_clock::time_point> {
}
};
template <>
struct object_with_zone<std::chrono::system_clock::time_point> {
void operator()(msgpack::object::with_zone& o, const std::chrono::system_clock::time_point& v) const {
int64_t count = static_cast<int64_t>(v.time_since_epoch().count());
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 = detail::integral_cast<int64_t>(v.time_since_epoch().count());
int64_t nano_num =
std::chrono::system_clock::duration::period::ratio::num *
(1000000000 / std::chrono::system_clock::duration::period::ratio::den);
Duration::period::ratio::num *
(1000000000L / Duration::period::ratio::den);
int64_t nanosec = count % (1000000000 / nano_num) * nano_num;
int64_t nanosec = count % (1000000000L / nano_num) * nano_num;
int64_t sec = 0;
if (nanosec < 0) {
nanosec = 1000000000 + nanosec;
nanosec = 1000000000L + nanosec;
--sec;
}
sec += count
* std::chrono::system_clock::duration::period::ratio::num
/ std::chrono::system_clock::duration::period::ratio::den;
* Duration::period::ratio::num
/ Duration::period::ratio::den;
if ((sec >> 34) == 0) {
uint64_t data64 = (static_cast<uint64_t>(nanosec) << 34) | static_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 = static_cast<uint32_t>(data64);
uint32_t data32 = detail::integral_cast<uint32_t>(data64);
_msgpack_store32(&p[1], data32);
o.via.ext.ptr = p;
}
@ -197,7 +339,7 @@ struct object_with_zone<std::chrono::system_clock::time_point> {
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], static_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;
}

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -0,0 +1,124 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2021 KONDO Takatoshi
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)
//
#ifndef MSGPACK_V1_TYPE_ARRAY_BYTE_HPP
#define MSGPACK_V1_TYPE_ARRAY_BYTE_HPP
#include "msgpack/cpp_version.hpp"
#if MSGPACK_CPP_VERSION >= 201703
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <array>
#include <cstring>
#include <cstddef>
namespace msgpack {
/// @cond
MSGPACK_API_VERSION_NAMESPACE(v1) {
/// @endcond
namespace adaptor {
template <std::size_t N>
struct convert<std::array<std::byte, N> > {
msgpack::object const& operator()(msgpack::object const& o, std::array<std::byte, N>& v) const {
switch (o.type) {
case msgpack::type::BIN:
if (o.via.bin.size != N)
throw msgpack::type_error();
if (N != 0) {
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
}
break;
case msgpack::type::STR:
if (o.via.bin.size != N)
throw msgpack::type_error();
if (N != 0) {
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
#endif // defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
#if defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
#pragma GCC diagnostic pop
#endif // defined(__GNUC__) && (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__)
}
break;
default:
throw msgpack::type_error();
break;
}
return o;
}
};
template <std::size_t N>
struct pack<std::array<std::byte, N> > {
template <typename Stream>
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<std::byte, N>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.pack_bin(size);
if (size != 0) {
o.pack_bin_body(reinterpret_cast<char const*>(&v.front()), size);
}
return o;
}
};
template <std::size_t N>
struct object<std::array<std::byte, N> > {
void operator()(msgpack::object& o, const std::array<std::byte, N>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN;
if (size != 0) {
o.via.bin.ptr = reinterpret_cast<char const*>(&v.front());
}
o.via.bin.size = size;
}
};
template <std::size_t N>
struct object_with_zone<std::array<std::byte, N> > {
void operator()(msgpack::object::with_zone& o, const std::array<std::byte, N>& v) const {
uint32_t size = checked_get_container_size(v.size());
o.type = msgpack::type::BIN;
o.via.bin.size = size;
if (size != 0) {
char* ptr = static_cast<char*>(o.zone.allocate_align(size, MSGPACK_ZONE_ALIGNOF(char)));
o.via.bin.ptr = ptr;
std::memcpy(ptr, &v.front(), size);
}
}
};
} // namespace adaptor
/// @cond
} // MSGPACK_API_VERSION_NAMESPACE(v1)
/// @endcond
} // namespace msgpack
#endif // MSGPACK_CPP_VERSION >= 201703
#endif // MSGPACK_V1_TYPE_ARRAY_BYTE_HPP

View File

@ -10,10 +10,13 @@
#ifndef MSGPACK_V1_TYPE_BYTE_HPP
#define MSGPACK_V1_TYPE_BYTE_HPP
#if __cplusplus >= 201703
#include "msgpack/cpp_version.hpp"
#if MSGPACK_CPP_VERSION >= 201703
#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"
@ -69,6 +72,6 @@ struct object_with_zone<std::byte> {
} // namespace msgpack
#endif // __cplusplus >= 201703
#endif // MSGPACK_CPP_VERSION >= 201703
#endif // MSGPACK_V1_TYPE_BYTE_HPP

View File

@ -10,10 +10,13 @@
#ifndef MSGPACK_V1_TYPE_CARRAY_BYTE_HPP
#define MSGPACK_V1_TYPE_CARRAY_BYTE_HPP
#if __cplusplus >= 201703
#include "msgpack/cpp_version.hpp"
#if MSGPACK_CPP_VERSION >= 201703
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <cstring>
@ -104,6 +107,6 @@ struct object_with_zone<const std::byte[N]> {
} // namespace msgpack
#endif // __cplusplus >= 201703
#endif // MSGPACK_CPP_VERSION >= 201703
#endif // MSGPACK_V1_TYPE_CARRAY_BYTE_HPP

View File

@ -10,10 +10,13 @@
#ifndef MSGPACK_V1_TYPE_OPTIONAL_HPP
#define MSGPACK_V1_TYPE_OPTIONAL_HPP
#if __cplusplus >= 201703
#include "msgpack/cpp_version.hpp"
#if MSGPACK_CPP_VERSION >= 201703
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <optional>
@ -85,6 +88,6 @@ struct object_with_zone<std::optional<T> > {
} // namespace msgpack
#endif // __cplusplus >= 201703
#endif // MSGPACK_CPP_VERSION >= 201703
#endif // MSGPACK_V1_TYPE_OPTIONAL_HPP

View File

@ -10,10 +10,13 @@
#ifndef MSGPACK_V1_TYPE_STRING_VIEW_HPP
#define MSGPACK_V1_TYPE_STRING_VIEW_HPP
#if __cplusplus >= 201703
#include "msgpack/cpp_version.hpp"
#if MSGPACK_CPP_VERSION >= 201703
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <string_view>
@ -81,6 +84,6 @@ struct object_with_zone<std::string_view> {
} // namespace msgpack
#endif // __cplusplus >= 201703
#endif // MSGPACK_CPP_VERSION >= 201703
#endif // MSGPACK_V1_TYPE_STRING_VIEW_HPP

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

@ -10,10 +10,13 @@
#ifndef MSGPACK_V1_TYPE_VECTOR_BYTE_HPP
#define MSGPACK_V1_TYPE_VECTOR_BYTE_HPP
#if __cplusplus >= 201703
#include "msgpack/cpp_version.hpp"
#if MSGPACK_CPP_VERSION >= 201703
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/adaptor_base.hpp"
#include "msgpack/object.hpp"
#include "msgpack/adaptor/check_container_size.hpp"
#include <vector>
@ -114,6 +117,6 @@ struct object_with_zone<std::vector<std::byte, Alloc> > {
} // namespace msgpack
#endif // __cplusplus >= 201703
#endif // MSGPACK_CPP_VERSION >= 201703
#endif // MSGPACK_V1_TYPE_VECTOR_BYTE_HPP

View File

@ -0,0 +1,124 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2021 KONDO Takatoshi and Daniil Kovalev
//
// 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_CPP20_SPAN_HPP
#define MSGPACK_V1_TYPE_CPP20_SPAN_HPP
#include "msgpack/cpp_version.hpp"
// Some compilers still do not set the corresponding macro to 202002
#if MSGPACK_CPP_VERSION > 201703
#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"
#include <span>
#include <cstring>
#include <cstddef>
namespace msgpack {
/// @cond
MSGPACK_API_VERSION_NAMESPACE(v1) {
/// @endcond
namespace adaptor {
#define MSGPACK_ADAPTOR_CONVERT_SPAN_BINARY(byte_t) \
template <> \
struct convert<std::span<const byte_t> > { \
msgpack::object const& operator()(msgpack::object const& o, std::span<const byte_t>& v) const { \
switch (o.type) { \
case msgpack::type::BIN: \
v = std::span(reinterpret_cast<const byte_t*>(o.via.bin.ptr), o.via.bin.size); \
break; \
default: \
throw msgpack::type_error(); \
break; \
} \
return o; \
} \
};
#define MSGPACK_ADAPTOR_PACK_SPAN_BINARY(byte_t) \
template <> \
struct pack<std::span<byte_t> > { \
template <typename Stream> \
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::span<byte_t>& v) const { \
uint32_t size = checked_get_container_size(v.size()); \
o.pack_bin(size); \
if (size != 0) { \
o.pack_bin_body(reinterpret_cast<char const*>(v.data()), size); \
} \
return o; \
} \
};
#define MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY(byte_t) \
template <> \
struct object<std::span<byte_t> > { \
void operator()(msgpack::object& o, const std::span<byte_t>& v) const { \
uint32_t size = checked_get_container_size(v.size()); \
o.type = msgpack::type::BIN; \
if (size != 0) { \
o.via.bin.ptr = reinterpret_cast<char const*>(v.data()); \
} \
o.via.bin.size = size; \
} \
};
#define MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY(byte_t) \
template <> \
struct object_with_zone<std::span<byte_t> > { \
void operator()(msgpack::object::with_zone& o, const std::span<byte_t>& v) const { \
uint32_t size = checked_get_container_size(v.size()); \
o.type = msgpack::type::BIN; \
o.via.bin.size = size; \
if (size != 0) { \
char* ptr = static_cast<char*>(o.zone.allocate_align(size, MSGPACK_ZONE_ALIGNOF(char))); \
o.via.bin.ptr = ptr; \
std::memcpy(ptr, v.data(), size); \
} \
} \
};
#define MSGPACK_ADAPTOR_SPAN_BINARY(byte_t) \
MSGPACK_ADAPTOR_CONVERT_SPAN_BINARY(byte_t) \
MSGPACK_ADAPTOR_PACK_SPAN_BINARY(byte_t) \
MSGPACK_ADAPTOR_PACK_SPAN_BINARY(const byte_t) \
MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY(byte_t) \
MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY(const byte_t) \
MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY(byte_t) \
MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY(const byte_t)
MSGPACK_ADAPTOR_SPAN_BINARY(char)
MSGPACK_ADAPTOR_SPAN_BINARY(unsigned char)
MSGPACK_ADAPTOR_SPAN_BINARY(std::byte)
#undef MSGPACK_ADAPTOR_SPAN_BINARY
#undef MSGPACK_ADAPTOR_OBJECT_WITH_ZONE_SPAN_BINARY
#undef MSGPACK_ADAPTOR_OBJECT_SPAN_BINARY
#undef MSGPACK_ADAPTOR_PACK_SPAN_BINARY
#undef MSGPACK_ADAPTOR_CONVERT_SPAN_BINARY
} // namespace adaptor
/// @cond
} // MSGPACK_API_VERSION_NAMESPACE(v1)
/// @endcond
} // namespace msgpack
#endif // MSGPACK_CPP_VERSION > 201703
#endif // MSGPACK_V1_TYPE_CPP11_ARRAY_HPP

View File

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

Some files were not shown because too many files have changed in this diff Show More