mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 22:31:33 +02:00
Compare commits
340 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
7bee573a72 | ||
![]() |
5568abb6ab | ||
![]() |
67486480ac | ||
![]() |
0e3bb789b8 | ||
![]() |
e1eabbfebf | ||
![]() |
e416b534b8 | ||
![]() |
212ef8eb2b | ||
![]() |
7bf06a5885 | ||
![]() |
1822523289 | ||
![]() |
156a4403ab | ||
![]() |
ad5da7f131 | ||
![]() |
62be3f1212 | ||
![]() |
8dbe25a51d | ||
![]() |
7cfd4bb1d8 | ||
![]() |
037a108c49 | ||
![]() |
79a127a8b6 | ||
![]() |
ace27f6238 | ||
![]() |
cc2ded6338 | ||
![]() |
13a746f6fa | ||
![]() |
b0ff2802d2 | ||
![]() |
4b0c90fc90 | ||
![]() |
4b11fb32cd | ||
![]() |
f707c6b47c | ||
![]() |
081ee0e99a | ||
![]() |
8eaa2e9e74 | ||
![]() |
ac1eb6e1d3 | ||
![]() |
343ceabe9a | ||
![]() |
eb765d21f2 | ||
![]() |
2d5c68055c | ||
![]() |
de68fbd6d0 | ||
![]() |
118cf7270c | ||
![]() |
cf1487f8ba | ||
![]() |
e4cd479bf3 | ||
![]() |
8dae63e4c1 | ||
![]() |
a3f350842c | ||
![]() |
c1e9f92d7f | ||
![]() |
582fe38e78 | ||
![]() |
6443738f66 | ||
![]() |
45eb2ad0c7 | ||
![]() |
37593400c3 | ||
![]() |
60648fc3a8 | ||
![]() |
0482e4fcd1 | ||
![]() |
82a10cba5c | ||
![]() |
0d9a21ea08 | ||
![]() |
f399ec8c30 | ||
![]() |
8ad9ce059b | ||
![]() |
a4aa14d1e2 | ||
![]() |
f7f2d4b990 | ||
![]() |
c675881f3b | ||
![]() |
f6d0cd9a4b | ||
![]() |
4ef5894856 | ||
![]() |
07ddfa1430 | ||
![]() |
252d66a4b2 | ||
![]() |
b4eba4ba09 | ||
![]() |
2266505eed | ||
![]() |
46e2398e02 | ||
![]() |
3662a17e81 | ||
![]() |
66f221d088 | ||
![]() |
9ed4e443fb | ||
![]() |
15aec0493d | ||
![]() |
d6a7bd1995 | ||
![]() |
ff86d61799 | ||
![]() |
97886c50e7 | ||
![]() |
327b0db626 | ||
![]() |
994144dac2 | ||
![]() |
023f81ae9c | ||
![]() |
83fac26762 | ||
![]() |
213ba44b65 | ||
![]() |
fa231139d7 | ||
![]() |
5cd1c6bfa1 | ||
![]() |
c4fb47c00d | ||
![]() |
70e50d9679 | ||
![]() |
978e6b9057 | ||
![]() |
571f1a27a2 | ||
![]() |
c3518c0666 | ||
![]() |
64ac09c492 | ||
![]() |
414da4e8c6 | ||
![]() |
3eadb124fc | ||
![]() |
fd9eb26688 | ||
![]() |
6c59e5195a | ||
![]() |
3bdf646cc6 | ||
![]() |
2bbf10a324 | ||
![]() |
737e6703df | ||
![]() |
7f48ddc85e | ||
![]() |
a84f444ce2 | ||
![]() |
7e597779e4 | ||
![]() |
bf8c830eef | ||
![]() |
5f52ec5030 | ||
![]() |
c71ce9eb49 | ||
![]() |
f105b4bbb0 | ||
![]() |
f64be3b2d0 | ||
![]() |
abac9fe90a | ||
![]() |
5798fa0e47 | ||
![]() |
fe4af1125d | ||
![]() |
ce96ca8bfc | ||
![]() |
57732f0c1b | ||
![]() |
7ccef5b787 | ||
![]() |
1a116fb644 | ||
![]() |
f79fd82953 | ||
![]() |
b9a80697bc | ||
![]() |
467822c97a | ||
![]() |
7ab7eaf61b | ||
![]() |
3ed6b673d4 | ||
![]() |
469040be6b | ||
![]() |
309e96087a | ||
![]() |
2d61fdf865 | ||
![]() |
6e560e345a | ||
![]() |
8b796dc788 | ||
![]() |
240b02174d | ||
![]() |
38a380684e | ||
![]() |
1a615af437 | ||
![]() |
9162610682 | ||
![]() |
c52a58b322 | ||
![]() |
ac3433f5dd | ||
![]() |
dab725624e | ||
![]() |
037b1c22dc | ||
![]() |
0de0b434b3 | ||
![]() |
7eb3d2aa59 | ||
![]() |
0827d08cd7 | ||
![]() |
3d20ec6f21 | ||
![]() |
bcdbf78542 | ||
![]() |
a4af97b32c | ||
![]() |
e00b299fe0 | ||
![]() |
d6cc5494a9 | ||
![]() |
96c688708c | ||
![]() |
79e7a9810c | ||
![]() |
a0ae0289dc | ||
![]() |
31a3d34b49 | ||
![]() |
1c54d804f5 | ||
![]() |
111efdf50f | ||
![]() |
dac8f6290d | ||
![]() |
3bfd142660 | ||
![]() |
d031162d96 | ||
![]() |
8e24d9206a | ||
![]() |
b78b49a7bd | ||
![]() |
561e9ba105 | ||
![]() |
6e84266043 | ||
![]() |
151c92d08d | ||
![]() |
1285470c21 | ||
![]() |
837c5ecfc3 | ||
![]() |
04aa309f24 | ||
![]() |
69b2ea4002 | ||
![]() |
8ddc219365 | ||
![]() |
a9cf916b82 | ||
![]() |
8455a2eb70 | ||
![]() |
5c0f1db25c | ||
![]() |
466986b519 | ||
![]() |
a6aac482dd | ||
![]() |
bb984d3445 | ||
![]() |
f8e2766d28 | ||
![]() |
2d5d12f9a6 | ||
![]() |
11a2a1b8ec | ||
![]() |
b5e66150e9 | ||
![]() |
e21e3245db | ||
![]() |
07e7ad6b7e | ||
![]() |
44b524529d | ||
![]() |
fc65bc0682 | ||
![]() |
ca12e6d39d | ||
![]() |
db8578a62b | ||
![]() |
4a292193f2 | ||
![]() |
1e7fbc0349 | ||
![]() |
479d50bd93 | ||
![]() |
982787865f | ||
![]() |
bf4a57da34 | ||
![]() |
2fcbe6116d | ||
![]() |
4c00f448aa | ||
![]() |
3ddeb08e6e | ||
![]() |
0176dd760a | ||
![]() |
d30548af3f | ||
![]() |
ab12b2b2b9 | ||
![]() |
7ce69a362f | ||
![]() |
cc08146b1c | ||
![]() |
6896cc602f | ||
![]() |
d8f366daf2 | ||
![]() |
ef649009e4 | ||
![]() |
cd03ab62f8 | ||
![]() |
44e41efa0c | ||
![]() |
ecf4b09acd | ||
![]() |
d6122b4a18 | ||
![]() |
4fcb4777f3 | ||
![]() |
03ed30ce03 | ||
![]() |
6e810df2a4 | ||
![]() |
847a7852e5 | ||
![]() |
e265beef91 | ||
![]() |
0335df55e1 | ||
![]() |
dd4043a616 | ||
![]() |
6a8412d6de | ||
![]() |
7491c1996a | ||
![]() |
0ab14b4138 | ||
![]() |
6e77c6df11 | ||
![]() |
bcc91d78e9 | ||
![]() |
32b65dba47 | ||
![]() |
aa75e6ecd3 | ||
![]() |
dc679a2572 | ||
![]() |
b6bc7f7ecb | ||
![]() |
896dead7cc | ||
![]() |
dfa277a9e0 | ||
![]() |
501260eb54 | ||
![]() |
370a9251f5 | ||
![]() |
7737f1cb77 | ||
![]() |
f72022037c | ||
![]() |
865528f778 | ||
![]() |
d54048eabe | ||
![]() |
103a6c56e4 | ||
![]() |
11f1d5fbbd | ||
![]() |
7ebdb63131 | ||
![]() |
a186725213 | ||
![]() |
8615358515 | ||
![]() |
86ad026f11 | ||
![]() |
93d0f0bd00 | ||
![]() |
a0f5392876 | ||
![]() |
5896ff3746 | ||
![]() |
d15e49cb73 | ||
![]() |
2103c12e05 | ||
![]() |
f0a12a23a1 | ||
![]() |
30b946ee85 | ||
![]() |
a388000d47 | ||
![]() |
4c888294b5 | ||
![]() |
68bf4acb4b | ||
![]() |
2c2df64427 | ||
![]() |
4d6e9d6c05 | ||
![]() |
f969f6f39c | ||
![]() |
8920c49597 | ||
![]() |
e18102d16f | ||
![]() |
ea23bf843e | ||
![]() |
e217e72c22 | ||
![]() |
0bc4b3f599 | ||
![]() |
b2f5893669 | ||
![]() |
9a1ccaf155 | ||
![]() |
0201c21b9a | ||
![]() |
dee68403df | ||
![]() |
0a99b9f933 | ||
![]() |
17e696fc0d | ||
![]() |
b5b459cfca | ||
![]() |
7822bc787d | ||
![]() |
1f5d6b9cac | ||
![]() |
ce21ab0ebf | ||
![]() |
5af6d36341 | ||
![]() |
15a0d61a64 | ||
![]() |
66014eebc0 | ||
![]() |
fd566afeb4 | ||
![]() |
e4d32b176e | ||
![]() |
b27c87c9ed | ||
![]() |
3729f334a1 | ||
![]() |
55bf279a7c | ||
![]() |
78e8cbdfb5 | ||
![]() |
dd083ca933 | ||
![]() |
23d670f3bd | ||
![]() |
6fab3594a2 | ||
![]() |
421aeb5021 | ||
![]() |
47f4ffe9f3 | ||
![]() |
09325ed846 | ||
![]() |
bfa428ab13 | ||
![]() |
ecdeec9948 | ||
![]() |
f11a811114 | ||
![]() |
c203928fae | ||
![]() |
59b111e026 | ||
![]() |
2a694f8c20 | ||
![]() |
0380215982 | ||
![]() |
0e48f65a4b | ||
![]() |
aa79fc2ff4 | ||
![]() |
cc571b8bb1 | ||
![]() |
b0df21295c | ||
![]() |
0889e6117e | ||
![]() |
212f025f00 | ||
![]() |
f6a5402194 | ||
![]() |
6a349d0b28 | ||
![]() |
dac5c60608 | ||
![]() |
bc33317b7e | ||
![]() |
754b1682a5 | ||
![]() |
cb9eed8ccc | ||
![]() |
862905742f | ||
![]() |
ba98315f65 | ||
![]() |
124a871923 | ||
![]() |
378f6afccd | ||
![]() |
1320863cb3 | ||
![]() |
a951ea90b8 | ||
![]() |
3b7a2f8f32 | ||
![]() |
038c3e3518 | ||
![]() |
c08439ff41 | ||
![]() |
59d994ea5f | ||
![]() |
ed51d23335 | ||
![]() |
2be892bfda | ||
![]() |
723d900098 | ||
![]() |
13404a7444 | ||
![]() |
a20594dfdc | ||
![]() |
bff4cadeff | ||
![]() |
6515577dc3 | ||
![]() |
beebccd323 | ||
![]() |
d70c44b723 | ||
![]() |
33d3192ca2 | ||
![]() |
0d13931844 | ||
![]() |
293c839a22 | ||
![]() |
f187ae35d9 | ||
![]() |
74013e7e7d | ||
![]() |
e2026c0507 | ||
![]() |
c375e14705 | ||
![]() |
fade0644c7 | ||
![]() |
5fedaf285b | ||
![]() |
fe82444db1 | ||
![]() |
f7692691ca | ||
![]() |
7fba3484c5 | ||
![]() |
561b6b583d | ||
![]() |
7675c15fa9 | ||
![]() |
99971abc9b | ||
![]() |
b7a1ba9ba0 | ||
![]() |
63c26cd58b | ||
![]() |
f8fc03b482 | ||
![]() |
b0b1a0e9a7 | ||
![]() |
4d2a9c23af | ||
![]() |
c41154989a | ||
![]() |
541ece13c0 | ||
![]() |
b6b2ef5e57 | ||
![]() |
4ef69da25d | ||
![]() |
9bd339baf8 | ||
![]() |
616be1aa60 | ||
![]() |
415b14335f | ||
![]() |
1fb707f93f | ||
![]() |
aa4ed82b66 | ||
![]() |
7ce8abe5d6 | ||
![]() |
27629a8dd6 | ||
![]() |
521a4f4190 | ||
![]() |
bad3801eae | ||
![]() |
72b3064a67 | ||
![]() |
7593e5ce0e | ||
![]() |
8a08548f36 | ||
![]() |
56b0ad6809 | ||
![]() |
f8561fbfd5 | ||
![]() |
e80cbd4437 | ||
![]() |
da601e4589 | ||
![]() |
36a87b6968 | ||
![]() |
e0b42939ba | ||
![]() |
7d731f83a4 | ||
![]() |
40ad7da455 | ||
![]() |
e0d1e5c722 | ||
![]() |
5b3a168b86 | ||
![]() |
11afd4820f | ||
![]() |
ec5c1194fc | ||
![]() |
7eccd1029a | ||
![]() |
c2ca709d68 |
3
.gitignore
vendored
3
.gitignore
vendored
@@ -1,5 +1,7 @@
|
||||
# Files generated by the bootstrap script.
|
||||
/INSTALL
|
||||
/AUTHORS
|
||||
/ChangeLog
|
||||
/NEWS
|
||||
/README
|
||||
/ac/
|
||||
@@ -19,6 +21,7 @@ Makefile.in
|
||||
/libtool
|
||||
/msgpack.pc
|
||||
/src/msgpack/version.h
|
||||
/src/msgpack/version.hpp
|
||||
/stamp-h1
|
||||
Makefile
|
||||
.deps
|
||||
|
34
.travis.yml
Normal file
34
.travis.yml
Normal file
@@ -0,0 +1,34 @@
|
||||
language: cpp
|
||||
cache:
|
||||
- apt
|
||||
compiler:
|
||||
- clang
|
||||
- gcc
|
||||
before_install:
|
||||
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
|
||||
- sudo add-apt-repository -y ppa:h-rayflood/llvm
|
||||
- sudo apt-get update -qq
|
||||
- sudo apt-get update
|
||||
- sudo apt-get install valgrind
|
||||
install:
|
||||
- sudo apt-get install -qq gcc-4.8-multilib g++-4.8-multilib
|
||||
- sudo apt-get install --allow-unauthenticated -qq clang-3.4
|
||||
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
|
||||
- sudo apt-get install -y lib32gcc1
|
||||
- sudo apt-get install -y libc6-i386
|
||||
- sudo apt-get install -y lib32z1-dev
|
||||
- sudo apt-get install -y lib32stdc++6
|
||||
- wget https://googletest.googlecode.com/files/gtest-1.7.0.zip
|
||||
- unzip gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && g++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && g++ -m32 src/gtest-all.cc -I. -Iinclude -c && g++ -m32 src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mkdir /usr/local/lib32 && sudo mv *.a /usr/local/lib32 && cd ..
|
||||
env:
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib"
|
||||
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib"
|
||||
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32"
|
||||
|
||||
script:
|
||||
- git clean -xdf && CMAKE_LIBRARY_PATH=${LIBPATH} ${ACTION} ${VERSION} ${ARCH}
|
@@ -1,3 +1,35 @@
|
||||
2015-3-22 version 1.0.1:
|
||||
* Fix compilation error on Mac 10.9 (#244)
|
||||
* Fix typos in documents (#240)
|
||||
* Update CHANGELOG.md for version 1.0.0 (#242)
|
||||
* Fix erb templates for the next code generation (#239)
|
||||
|
||||
2015-03-10 version 1.0.0:
|
||||
* Support msgpack v5 format (str, bin, and ext) https://github.com/msgpack/msgpack/blob/master/spec.md (#142)
|
||||
* Support std::tuple, std::forward_list, std::array, std::unordered_set, std::unordered_map on C++11. tr1 unordered containers are still supported (#53, #130, #137, #154, #169)
|
||||
* Update msgpack-c as a header-only library on C++ (#142)
|
||||
* Move include directory (#142)
|
||||
* Update the name of float format family on msgpack::object from 'dec' to 'f64' (#194)
|
||||
* Remove existing elements on associative containers when unpacking (#127)
|
||||
* Add an API versioning functionality https://github.com/msgpack/msgpack-c/wiki/cpp_versioning (#139)
|
||||
* Add C++11 enum class support (#205)
|
||||
* Map std::vector<char> and std::array<char> to BIN (#100)
|
||||
* Map '\0' teminated char* and char const* to STR (#206)
|
||||
* Add the new parameter on unpacking functions and classes to limit msgpack's bytestream size (https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker#limit-size-of-elements) (#175)
|
||||
* Add the copy or reference choosing function on unpack() and unpacker (https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker#memory-management)
|
||||
* Add the new unpack() overloads for C++11 https://github.com/msgpack/msgpack-c/wiki/cpp_unpacker (#128)
|
||||
* Add a msgpack::object::with_zone (deep) copying function (#133, #163)
|
||||
* Remove the compile-time defined limit of msgpack nest level on C++ (#218)
|
||||
* Add the new unpack() overloads that use an existing zone (#201)
|
||||
* Add the range-based for loop support on msgpack object array and map (#203)
|
||||
* Add msgpack revision getter function for 'revision' (#237)
|
||||
* Support EXT for C (#118, #129)
|
||||
* Fix unpacking buffer allocation problem when malformed data is given (#160, #185)
|
||||
* Add dll exporting function on MSVC (#162)
|
||||
* Fix msgpack::zone::allocate_no_align(). Now it allocates the memory that is not aligned as expected (#171)
|
||||
* Improve documents (https://github.com/msgpack/msgpack-c/wiki)
|
||||
* Other bug fixes and refactoring: #62, #91, #95, #97, #107, #109, #113, #117, #119, #121, #122, #123, #126, #131, #136, #138, #140, #143, #145, #146, #150, #151, #152, #156, #157, #158, #161, #165, #170, #172, #179, #180, #181, #182, #183, #192, #195, #199, #200, #207, #211, #212, #219, #222, #224, #230, #231, #232, #233, #234, #235
|
||||
|
||||
2014-07-02 version 0.5.9:
|
||||
|
||||
* Support std::tr1 unordered containers by default (#51, #63, #68, #69)
|
311
CMakeLists.txt
311
CMakeLists.txt
@@ -1,20 +1,50 @@
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.6)
|
||||
PROJECT (msgpack)
|
||||
|
||||
SET (VERSION 0.5.9)
|
||||
SET (VERSION_MAJOR 0)
|
||||
SET (VERSION_MINOR 5)
|
||||
FILE (READ ${CMAKE_CURRENT_SOURCE_DIR}/include/msgpack/version_master.h 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})
|
||||
SET (VERSION_MINOR ${CMAKE_MATCH_1})
|
||||
STRING (REGEX MATCH "#define MSGPACK_VERSION_REVISION *([0-9a-zA-Z_]*)" NULL_OUT ${contents})
|
||||
SET (VERSION_REVISION ${CMAKE_MATCH_1})
|
||||
SET (VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
|
||||
|
||||
SET (prefix ${CMAKE_INSTALL_PREFIX})
|
||||
SET (exec_prefix "\${prefix}")
|
||||
SET (libdir "\${exec_prefix}/lib")
|
||||
SET (includedir "\${prefix}/include")
|
||||
|
||||
OPTION (MSGPACK_CXX11 "Using c++11 compiler" OFF)
|
||||
OPTION (MSGPACK_32BIT "32bit compile" OFF)
|
||||
|
||||
IF (MSGPACK_CXX11)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
|
||||
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
|
||||
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++11 yet.")
|
||||
ENDIF ()
|
||||
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 ()
|
||||
ENDIF ()
|
||||
|
||||
FIND_PACKAGE (GTest)
|
||||
FIND_PACKAGE (ZLIB)
|
||||
FIND_PACKAGE (Threads)
|
||||
IF (GTEST_FOUND AND ZLIB_FOUND AND THREADS_FOUND)
|
||||
OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON)
|
||||
OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON)
|
||||
ENDIF ()
|
||||
|
||||
OPTION (MSGPACK_ENABLE_CXX "Enable C++ interface." ON)
|
||||
@@ -26,163 +56,210 @@ 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; }
|
||||
int main(int argc, char * argv[])
|
||||
{
|
||||
atomic_sub(1);
|
||||
atomic_add(1);
|
||||
atomic_sub(1);
|
||||
atomic_add(1);
|
||||
}
|
||||
" MSGPACK_ENABLE_GCC_CXX_ATOMIC)
|
||||
|
||||
IF (MSGPACK_ENABLE_CXX)
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/object.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
IF (MSGPACK_ENABLE_GCC_CXX_ATOMIC)
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/gcc_atomic.cpp
|
||||
)
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/gcc_atomic.cpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
|
||||
LIST (APPEND msgpack_SOURCES
|
||||
src/unpack.c
|
||||
src/objectc.c
|
||||
src/version.c
|
||||
src/vrefbuffer.c
|
||||
src/zone.c
|
||||
src/unpack.c
|
||||
src/objectc.c
|
||||
src/version.c
|
||||
src/vrefbuffer.c
|
||||
src/zone.c
|
||||
)
|
||||
|
||||
LIST (APPEND msgpack_HEADERS
|
||||
src/msgpack/pack_define.h
|
||||
src/msgpack/pack_template.h
|
||||
src/msgpack/unpack_define.h
|
||||
src/msgpack/unpack_template.h
|
||||
src/msgpack/sysdep.h
|
||||
src/msgpack/sbuffer.h
|
||||
src/msgpack/version.h
|
||||
src/msgpack/vrefbuffer.h
|
||||
src/msgpack/zbuffer.h
|
||||
src/msgpack/fbuffer.h
|
||||
src/msgpack/pack.h
|
||||
src/msgpack/unpack.h
|
||||
src/msgpack/object.h
|
||||
src/msgpack/zone.h
|
||||
include/msgpack/pack_define.h
|
||||
include/msgpack/pack_template.h
|
||||
include/msgpack/unpack_define.h
|
||||
include/msgpack/unpack_template.h
|
||||
include/msgpack/util.h
|
||||
include/msgpack/sysdep.h
|
||||
include/msgpack/gcc_atomic.h
|
||||
include/msgpack/sbuffer.h
|
||||
include/msgpack/version.h
|
||||
include/msgpack/vrefbuffer.h
|
||||
include/msgpack/zbuffer.h
|
||||
include/msgpack/fbuffer.h
|
||||
include/msgpack/pack.h
|
||||
include/msgpack/unpack.h
|
||||
include/msgpack/object.h
|
||||
include/msgpack/zone.h
|
||||
)
|
||||
|
||||
IF (MSGPACK_ENABLE_CXX)
|
||||
LIST (APPEND msgpack_HEADERS
|
||||
src/msgpack.hpp
|
||||
src/msgpack/sbuffer.hpp
|
||||
src/msgpack/vrefbuffer.hpp
|
||||
src/msgpack/zbuffer.hpp
|
||||
src/msgpack/fbuffer.hpp
|
||||
src/msgpack/pack.hpp
|
||||
src/msgpack/unpack.hpp
|
||||
src/msgpack/object.hpp
|
||||
src/msgpack/zone.hpp
|
||||
src/msgpack/type.hpp
|
||||
src/msgpack/type/bool.hpp
|
||||
src/msgpack/type/deque.hpp
|
||||
src/msgpack/type/float.hpp
|
||||
src/msgpack/type/fixint.hpp
|
||||
src/msgpack/type/int.hpp
|
||||
src/msgpack/type/list.hpp
|
||||
src/msgpack/type/map.hpp
|
||||
src/msgpack/type/nil.hpp
|
||||
src/msgpack/type/pair.hpp
|
||||
src/msgpack/type/raw.hpp
|
||||
src/msgpack/type/set.hpp
|
||||
src/msgpack/type/string.hpp
|
||||
src/msgpack/type/vector.hpp
|
||||
src/msgpack/type/tuple.hpp
|
||||
src/msgpack/type/define.hpp
|
||||
src/msgpack/type/tr1/unordered_map.hpp
|
||||
src/msgpack/type/tr1/unordered_set.hpp
|
||||
)
|
||||
LIST (APPEND msgpack_HEADERS
|
||||
include/msgpack.hpp
|
||||
include/msgpack_fwd.hpp
|
||||
include/msgpack/adaptor/bool.hpp
|
||||
include/msgpack/adaptor/bool_fwd.hpp
|
||||
include/msgpack/adaptor/char_ptr.hpp
|
||||
include/msgpack/adaptor/char_ptr_fwd.hpp
|
||||
include/msgpack/adaptor/check_container_size.hpp
|
||||
include/msgpack/adaptor/cpp11/array.hpp
|
||||
include/msgpack/adaptor/cpp11/array_fwd.hpp
|
||||
include/msgpack/adaptor/cpp11/array_char.hpp
|
||||
include/msgpack/adaptor/cpp11/array_char_fwd.hpp
|
||||
include/msgpack/adaptor/cpp11/forward_list.hpp
|
||||
include/msgpack/adaptor/cpp11/forward_list_fwd.hpp
|
||||
include/msgpack/adaptor/cpp11/tuple.hpp
|
||||
include/msgpack/adaptor/cpp11/tuple_fwd.hpp
|
||||
include/msgpack/adaptor/cpp11/unordered_map.hpp
|
||||
include/msgpack/adaptor/cpp11/unordered_map_fwd.hpp
|
||||
include/msgpack/adaptor/cpp11/unordered_set.hpp
|
||||
include/msgpack/adaptor/cpp11/unordered_set_fwd.hpp
|
||||
include/msgpack/adaptor/define.hpp
|
||||
include/msgpack/adaptor/deque.hpp
|
||||
include/msgpack/adaptor/deque_fwd.hpp
|
||||
include/msgpack/adaptor/detail/cpp03_define.hpp
|
||||
include/msgpack/adaptor/detail/cpp03_msgpack_tuple.hpp
|
||||
include/msgpack/adaptor/detail/cpp03_msgpack_tuple_fwd.hpp
|
||||
include/msgpack/adaptor/detail/cpp11_define.hpp
|
||||
include/msgpack/adaptor/detail/cpp11_msgpack_tuple.hpp
|
||||
include/msgpack/adaptor/detail/cpp11_msgpack_tuple_fwd.hpp
|
||||
include/msgpack/adaptor/fixint.hpp
|
||||
include/msgpack/adaptor/fixint_fwd.hpp
|
||||
include/msgpack/adaptor/float.hpp
|
||||
include/msgpack/adaptor/float_fwd.hpp
|
||||
include/msgpack/adaptor/int.hpp
|
||||
include/msgpack/adaptor/int_fwd.hpp
|
||||
include/msgpack/adaptor/list.hpp
|
||||
include/msgpack/adaptor/list_fwd.hpp
|
||||
include/msgpack/adaptor/map.hpp
|
||||
include/msgpack/adaptor/map_fwd.hpp
|
||||
include/msgpack/adaptor/msgpack_tuple.hpp
|
||||
include/msgpack/adaptor/msgpack_tuple_fwd.hpp
|
||||
include/msgpack/adaptor/nil.hpp
|
||||
include/msgpack/adaptor/nil_fwd.hpp
|
||||
include/msgpack/adaptor/pair.hpp
|
||||
include/msgpack/adaptor/pair_fwd.hpp
|
||||
include/msgpack/adaptor/raw.hpp
|
||||
include/msgpack/adaptor/raw_fwd.hpp
|
||||
include/msgpack/adaptor/set.hpp
|
||||
include/msgpack/adaptor/set_fwd.hpp
|
||||
include/msgpack/adaptor/string.hpp
|
||||
include/msgpack/adaptor/string_fwd.hpp
|
||||
include/msgpack/adaptor/tr1/unordered_map.hpp
|
||||
include/msgpack/adaptor/tr1/unordered_map_fwd.hpp
|
||||
include/msgpack/adaptor/tr1/unordered_set.hpp
|
||||
include/msgpack/adaptor/tr1/unordered_set_fwd.hpp
|
||||
include/msgpack/adaptor/vector.hpp
|
||||
include/msgpack/adaptor/vector_fwd.hpp
|
||||
include/msgpack/adaptor/vector_bool.hpp
|
||||
include/msgpack/adaptor/vector_bool_fwd.hpp
|
||||
include/msgpack/adaptor/vector_char.hpp
|
||||
include/msgpack/adaptor/vector_char_fwd.hpp
|
||||
include/msgpack/cpp_config.hpp
|
||||
include/msgpack/detail/cpp03_zone.hpp
|
||||
include/msgpack/detail/cpp11_zone.hpp
|
||||
include/msgpack/fbuffer.hpp
|
||||
include/msgpack/object.hpp
|
||||
include/msgpack/object_fwd.hpp
|
||||
include/msgpack/pack.hpp
|
||||
include/msgpack/sbuffer.hpp
|
||||
include/msgpack/type.hpp
|
||||
include/msgpack/unpack.hpp
|
||||
include/msgpack/version.hpp
|
||||
include/msgpack/versioning.hpp
|
||||
include/msgpack/vrefbuffer.hpp
|
||||
include/msgpack/zbuffer.hpp
|
||||
include/msgpack/zone.hpp
|
||||
)
|
||||
ENDIF ()
|
||||
|
||||
EXECUTE_PROCESS (
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/src/msgpack
|
||||
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/src/msgpack
|
||||
)
|
||||
|
||||
CONFIGURE_FILE (
|
||||
src/msgpack/version.h.in
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/msgpack/version.h
|
||||
)
|
||||
|
||||
CONFIGURE_FILE (
|
||||
msgpack.pc.in
|
||||
msgpack.pc
|
||||
@ONLY
|
||||
msgpack.pc.in
|
||||
msgpack.pc
|
||||
@ONLY
|
||||
)
|
||||
|
||||
INCLUDE_DIRECTORIES (
|
||||
./
|
||||
src/
|
||||
src/msgpack/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/src/msgpack/
|
||||
./
|
||||
include/
|
||||
${CMAKE_CURRENT_BINARY_DIR}/include/
|
||||
)
|
||||
|
||||
ADD_LIBRARY (msgpack SHARED
|
||||
${msgpack_SOURCES}
|
||||
${msgpack_HEADERS}
|
||||
${msgpack_SOURCES}
|
||||
${msgpack_HEADERS}
|
||||
)
|
||||
|
||||
ADD_LIBRARY (msgpack-static STATIC
|
||||
${msgpack_SOURCES}
|
||||
${msgpack_HEADERS}
|
||||
${msgpack_SOURCES}
|
||||
${msgpack_HEADERS}
|
||||
)
|
||||
|
||||
SET_TARGET_PROPERTIES (msgpack-static PROPERTIES OUTPUT_NAME "msgpack")
|
||||
SET_TARGET_PROPERTIES (msgpack PROPERTIES IMPORT_SUFFIX "_import.lib")
|
||||
SET_TARGET_PROPERTIES (msgpack PROPERTIES SOVERSION 3 VERSION 3.0.0)
|
||||
SET_TARGET_PROPERTIES (msgpack PROPERTIES SOVERSION 3 VERSION 4.0.0)
|
||||
|
||||
IF (MSGPACK_BUILD_TESTS)
|
||||
ENABLE_TESTING ()
|
||||
ADD_SUBDIRECTORY (test)
|
||||
ENABLE_TESTING ()
|
||||
SET(CTEST_MEMORYCHECK_COMMAND "/usr/bin/valgrind")
|
||||
INCLUDE(Dart)
|
||||
SET(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1")
|
||||
ADD_SUBDIRECTORY (test)
|
||||
ENDIF ()
|
||||
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
|
||||
SET_PROPERTY (TARGET msgpack APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3 -DPIC")
|
||||
SET_PROPERTY (TARGET msgpack-static APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3" )
|
||||
SET_PROPERTY (TARGET msgpack APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3 -DPIC")
|
||||
SET_PROPERTY (TARGET msgpack-static APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3" )
|
||||
ENDIF ()
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
ENDIF ()
|
||||
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
INSTALL (TARGETS msgpack msgpack-static DESTINATION lib)
|
||||
INSTALL (DIRECTORY src/msgpack DESTINATION include)
|
||||
INSTALL (FILES src/msgpack.h src/msgpack.hpp DESTINATION include)
|
||||
INSTALL (FILES msgpack.pc DESTINATION lib/pkgconfig)
|
||||
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC90" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC10")
|
||||
SET_SOURCE_FILES_PROPERTIES(${msgpack_SOURCES} PROPERTIES LANGUAGE CXX)
|
||||
ENDIF()
|
||||
|
||||
IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
|
||||
SET(CMAKE_INSTALL_LIBDIR lib)
|
||||
ENDIF ()
|
||||
|
||||
INSTALL (TARGETS msgpack msgpack-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
|
||||
INSTALL (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX})
|
||||
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/msgpack.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
|
||||
|
||||
# Doxygen
|
||||
FIND_PACKAGE (Doxygen)
|
||||
IF (DOXYGEN_FOUND)
|
||||
ADD_CUSTOM_TARGET (
|
||||
doxygen_c
|
||||
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 "PROJECT_NAME = \"MessagePack for C\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
VERBATIM
|
||||
)
|
||||
ADD_CUSTOM_TARGET (
|
||||
doxygen_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 "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
|
||||
)
|
||||
ADD_CUSTOM_TARGET (
|
||||
doxygen_c
|
||||
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 "PROJECT_NAME = \"MessagePack for C\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
VERBATIM
|
||||
)
|
||||
ADD_CUSTOM_TARGET (
|
||||
doxygen_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 "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 ()
|
||||
|
4
NOTICE
4
NOTICE
@@ -1,4 +0,0 @@
|
||||
MessagePack is developed by FURUHASHI Sadayuki, licensed under Apache License,
|
||||
Version 2.0. The original software and related information is available at
|
||||
http://msgpack.sourceforge.jp/.
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
The serialization library is production-ready.
|
||||
|
||||
Currently, no RPC implementation is not available.
|
||||
Currently, RPC implementation is not available.
|
||||
|
||||
# Install
|
||||
|
||||
|
@@ -2,7 +2,7 @@
|
||||
|
||||
The serialization library is production-ready.
|
||||
|
||||
Currently, RPC implementation is testing phase. Requires newer kernel, not running on RHEL5/CentOS5.
|
||||
Currently, RPC implementation is in testing phase. Requires newer kernel, not running on RHEL5/CentOS5.
|
||||
|
||||
# Install
|
||||
|
||||
|
266
README.md
266
README.md
@@ -1,159 +1,219 @@
|
||||
# Msgpack for C/C++
|
||||
`msgpack` for C/C++
|
||||
===================
|
||||
|
||||
Version 1.0.1 [](https://travis-ci.org/msgpack/msgpack-c)
|
||||
|
||||
It's like JSON but small and fast.
|
||||
|
||||
Overview
|
||||
--------
|
||||
|
||||
## Overview
|
||||
[MessagePack](http://msgpack.org/) is an efficient binary serialization
|
||||
format, which lets you exchange data among multiple languages like JSON,
|
||||
except that it's faster and smaller. Small integers are encoded into a
|
||||
single byte while typical short strings require only one extra byte in
|
||||
addition to the strings themselves.
|
||||
|
||||
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.
|
||||
Example
|
||||
-------
|
||||
|
||||
In C:
|
||||
|
||||
## License
|
||||
```c
|
||||
#include <msgpack.h>
|
||||
#include <stdio.h>
|
||||
|
||||
Msgpack is Copyright (C) 2008-2010 FURUHASHI Sadayuki and licensed under the Apache License, Version 2.0 (the "License"). For details see the `COPYING` file in this directory.
|
||||
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);
|
||||
|
||||
## Contributing
|
||||
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);
|
||||
|
||||
The source for msgpack-c is held at [msgpack-c](https://github.com/msgpack/msgpack-c) github.com site.
|
||||
/* 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);
|
||||
|
||||
To report an issue, use the [msgpack-c issue tracker](https://github.com/msgpack/msgpack-c/issues) at github.com.
|
||||
msgpack_object deserialized;
|
||||
msgpack_unpack(sbuf.data, sbuf.size, NULL, &mempool, &deserialized);
|
||||
|
||||
/* print the deserialized object. */
|
||||
msgpack_object_print(stdout, deserialized);
|
||||
puts("");
|
||||
|
||||
## Using Msgpack
|
||||
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>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
msgpack::type::tuple<int, bool, std::string> src(1, true, "example");
|
||||
|
||||
// serialize the object into the buffer.
|
||||
// any classes that implements write(const char*,size_t) can be a buffer.
|
||||
std::stringstream buffer;
|
||||
msgpack::pack(buffer, src);
|
||||
|
||||
// send the buffer ...
|
||||
buffer.seekg(0);
|
||||
|
||||
// deserialize the buffer into msgpack::object instance.
|
||||
std::string str(buffer.str());
|
||||
|
||||
msgpack::unpacked result;
|
||||
|
||||
msgpack::unpack(result, str.data(), str.size());
|
||||
|
||||
// deserialized object is valid during the msgpack::unpacked instance alive.
|
||||
msgpack::object deserialized = result.get();
|
||||
|
||||
// msgpack::object supports ostream.
|
||||
std::cout << deserialized << std::endl;
|
||||
|
||||
// convert msgpack::object instance into the original type.
|
||||
// if the type is mismatched, it throws msgpack::type_error exception.
|
||||
msgpack::type::tuple<int, bool, std::string> dst;
|
||||
deserialized.convert(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
See [`QUICKSTART-CPP.md`](./QUICKSTART-CPP.md) for more details.
|
||||
|
||||
Usage
|
||||
-----
|
||||
|
||||
### C++ Header Only Library
|
||||
|
||||
When you use msgpack on C++03 and C++11, you can just add
|
||||
msgpack-c/include to your include path:
|
||||
|
||||
g++ -I msgpack-c/include your_source_file.cpp
|
||||
|
||||
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.
|
||||
|
||||
### Building and Installing
|
||||
|
||||
#### Install from git repository
|
||||
|
||||
##### Using autotools
|
||||
You will need gcc (4.1.0 or higher), autotools.
|
||||
|
||||
```
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
You will need:
|
||||
|
||||
- `gcc >= 4.1.0` or `clang >= 3.3.0`
|
||||
- `autoconf >= 2.60`
|
||||
- `automake >= 1.10`
|
||||
- `libtool >= 2.2.4`
|
||||
|
||||
The build steps below are for C and C++03. If compiling for C++11,
|
||||
add `-std=c++11` to the environmental variable `CXXFLAGS` with
|
||||
`export CXXFLAGS="$CXXFLAGS -std=c++11"` prior to following the
|
||||
directions below.
|
||||
|
||||
```bash
|
||||
$ git clone https://github.com/msgpack/msgpack-c
|
||||
$ cd msgpack-c
|
||||
$ ./bootstrap
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
|
||||
You can install the resulting library like this:
|
||||
|
||||
```bash
|
||||
$ sudo make install
|
||||
```
|
||||
##### Using cmake
|
||||
You will need gcc (4.1.0 or higher), cmake.
|
||||
|
||||
```
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
$ cmake .
|
||||
$ make
|
||||
```
|
||||
###### Using the Terminal (CLI)
|
||||
|
||||
#### Install from package
|
||||
You will need:
|
||||
|
||||
##### UNIX-like platform with ./configure
|
||||
- `gcc >= 4.1.0`
|
||||
- `cmake >= 2.8.0`
|
||||
|
||||
On typical UNIX-like platforms, download source package from [Releases](https://github.com/msgpack/msgpack-c/releases) and run `./configure && make && make install`. Example:
|
||||
C and C++03:
|
||||
|
||||
```
|
||||
$ wget https://github.com/msgpack/msgpack-c/releases/download/cpp-0.5.9/msgpack-0.5.9.tar.gz
|
||||
$ tar zxvf msgpack-0.5.9.tar.gz
|
||||
$ cd msgpack-0.5.9
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
```
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
$ cmake .
|
||||
$ make
|
||||
$ sudo make install
|
||||
|
||||
##### FreeBSD with Ports Collection
|
||||
If you want to setup C++11 version of msgpack instead,
|
||||
execute the following commands:
|
||||
|
||||
On FreeBSD, you can use Ports Collection. Install [net/msgpack](http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/msgpack/) package.
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
$ cmake -DMSGPACK_CXX11=ON .
|
||||
$ sudo make install
|
||||
|
||||
##### Gentoo Linux with Portage
|
||||
|
||||
On Gentoo Linux, you can use emerge. Install [dev-libs/msgpack](http://gentoo-portage.com/dev-libs/msgpack) package.
|
||||
|
||||
##### Mac OS X with MacPorts
|
||||
|
||||
On Mac OS X, 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.
|
||||
|
||||
```
|
||||
$ sudo brew install msgpack
|
||||
```
|
||||
|
||||
|
||||
##### Windows
|
||||
##### GUI on Windows
|
||||
|
||||
Clone msgpack-c git repository.
|
||||
|
||||
```
|
||||
$ 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/
|
||||
|
||||
Launch cmake GUI client. http://www.cmake.org/cmake/resources/software.html
|
||||
1. Launch [cmake GUI client](http://www.cmake.org/cmake/resources/software.html).
|
||||
|
||||
Set 'Where is the source code:' text box and 'Where to build the binaries:' text box.
|
||||
2. Set 'Where is the source code:' text box and 'Where to build
|
||||
the binaries:' text box.
|
||||
|
||||
Click 'Configure' button.
|
||||
3. Click 'Configure' button.
|
||||
|
||||
Choose your Visual Studio version.
|
||||
4. Choose your Visual Studio version.
|
||||
|
||||
Click 'Generate' button.
|
||||
5. Click 'Generate' button.
|
||||
|
||||
Open the created msgpack.sln on Visual Studio.
|
||||
6. Open the created msgpack.sln on Visual Studio.
|
||||
|
||||
Build all.
|
||||
7. Build all.
|
||||
|
||||
### Linking with an Application
|
||||
### Documentation
|
||||
|
||||
Include `msgpack.hpp` (or `msgpack.h` for C) in your application and link with libmsgpack. Here is a typical gcc link command:
|
||||
You can get addtional information on the
|
||||
[wiki](https://github.com/msgpack/msgpack-c/wiki/cpp_overview).
|
||||
|
||||
g++ myapp.cpp -lmsgpack -o myapp
|
||||
Contributing
|
||||
------------
|
||||
|
||||
`msgpack-c` is developed on GitHub at [msgpack/msgpack-c](https://github.com/msgpack/msgpack-c).
|
||||
To report an issue or send a pull request, use the
|
||||
[issue tracker](https://github.com/msgpack/msgpack-c/issues).
|
||||
|
||||
### Code Example
|
||||
```CPP
|
||||
#include <msgpack.hpp>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
Here's the list of [great contributors](https://github.com/msgpack/msgpack-c/graphs/contributors).
|
||||
|
||||
int main() {
|
||||
// This is target object.
|
||||
std::vector<std::string> target;
|
||||
target.push_back("Hello,");
|
||||
target.push_back("World!");
|
||||
License
|
||||
-------
|
||||
|
||||
// Serialize it.
|
||||
msgpack::sbuffer sbuf; // simple buffer
|
||||
msgpack::pack(&sbuf, target);
|
||||
|
||||
// Deserialize the serialized data.
|
||||
msgpack::unpacked msg; // includes memory pool and deserialized object
|
||||
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
|
||||
msgpack::object obj = msg.get();
|
||||
|
||||
// Print the deserialized object to stdout.
|
||||
std::cout << obj << std::endl; // ["Hello," "World!"]
|
||||
|
||||
// Convert the deserialized object to staticaly typed object.
|
||||
std::vector<std::string> result;
|
||||
obj.convert(&result);
|
||||
|
||||
// If the type is mismatched, it throws msgpack::type_error.
|
||||
obj.as<int>(); // type is mismatched, msgpack::type_error is thrown
|
||||
}
|
||||
```
|
||||
### Quickstart Guides
|
||||
|
||||
For more detailed examples see [QuickStart for C](QUICKSTART-C.md) and [QuickStart for C++](QUICKSTART-CPP.md).
|
||||
`msgpack-c` is licensed under the Apache License Version 2.0. See
|
||||
the [`LICENSE`](./LICENSE) file for details.
|
||||
|
@@ -36,6 +36,7 @@ test -f AUTHORS || touch AUTHORS
|
||||
test -f COPYING || touch COPYING
|
||||
test -f ChangeLog || touch ChangeLog
|
||||
test -f NEWS || touch NEWS
|
||||
test -f NOTICE || touch NOTICE
|
||||
test -f README || cp -f README.md README
|
||||
|
||||
ACLOCAL="aclocal"
|
||||
|
57
ci/build_autotools.sh
Executable file
57
ci/build_autotools.sh
Executable file
@@ -0,0 +1,57 @@
|
||||
#!/bin/sh
|
||||
|
||||
./bootstrap
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
if [ $1 = "cpp11" ]
|
||||
then
|
||||
if [ $2 = "32" ]
|
||||
then
|
||||
./configure CFLAGS="-m32" CXXFLAGS="-std=c++11 -m32"
|
||||
else
|
||||
./configure CXXFLAGS="-std=c++11"
|
||||
fi
|
||||
else
|
||||
if [ $2 = "32" ]
|
||||
then
|
||||
./configure CFLAGS="-m32" CXXFLAGS="-m32"
|
||||
else
|
||||
./configure
|
||||
fi
|
||||
fi
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
make
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
make check
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
make install DESTDIR=`pwd`/install
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
exit 0
|
83
ci/build_cmake.sh
Executable file
83
ci/build_cmake.sh
Executable file
@@ -0,0 +1,83 @@
|
||||
#!/bin/bash
|
||||
|
||||
mkdir build
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
cd build
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
if [ $1 = "cpp11" ]
|
||||
then
|
||||
if [ $2 = "32" ]
|
||||
then
|
||||
cmake -DMSGPACK_CXX11=ON -DMSGPACK_32BIT=ON ..
|
||||
else
|
||||
cmake -DMSGPACK_CXX11=ON ..
|
||||
fi
|
||||
else
|
||||
if [ $2 = "32" ]
|
||||
then
|
||||
cmake -DMSGPACK_32BIT=ON ..
|
||||
else
|
||||
cmake ..
|
||||
fi
|
||||
fi
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
make
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
make test
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
make install DESTDIR=`pwd`/install
|
||||
|
||||
ret=$?
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
|
||||
if [ $2 != "32" ]
|
||||
then
|
||||
ctest -T memcheck | tee memcheck.log
|
||||
|
||||
ret=${PIPESTATUS[0]}
|
||||
if [ $ret -ne 0 ]
|
||||
then
|
||||
exit $ret
|
||||
fi
|
||||
cat memcheck.log | grep "Memory Leak" > /dev/null
|
||||
ret=$?
|
||||
if [ $ret -eq 0 ]
|
||||
then
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
14
configure.in
14
configure.in
@@ -1,8 +1,7 @@
|
||||
AC_INIT(src/object.cpp)
|
||||
AC_INIT(msgpack, m4_esyscmd([cat include/msgpack/version_master.h | tr -d "\n" | sed -e 's/#define MSGPACK_VERSION_MAJOR[[:space:]]*\([[:alnum:]]*\)/\1./g' -e 's/#define MSGPACK_VERSION_MINOR[[:space:]]*\([[:alnum:]]*\)/\1./g' -e 's/#define MSGPACK_VERSION_REVISION[[:space:]]*\([[:alnum:]]*\)/\1/g' | tr -d "\n"]))
|
||||
AC_CONFIG_AUX_DIR(ac)
|
||||
AM_INIT_AUTOMAKE(msgpack, 0.5.9)
|
||||
AM_INIT_AUTOMAKE
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
||||
AC_SUBST(CFLAGS)
|
||||
CFLAGS="-O3 -Wall $CFLAGS"
|
||||
|
||||
@@ -85,16 +84,15 @@ fi
|
||||
|
||||
AM_CONDITIONAL(ENABLE_GCC_CXX_ATOMIC, test "$enable_gcc_cxx_atomic" = "yes")
|
||||
|
||||
|
||||
major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
|
||||
minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
|
||||
major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).\([[0-9]]*\).*/\1/'`
|
||||
minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).\([[0-9]]*\).*/\2/'`
|
||||
revision=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).\([[0-9]]*\).*/\3/'`
|
||||
AC_SUBST(VERSION_MAJOR, $major)
|
||||
AC_SUBST(VERSION_MINOR, $minor)
|
||||
AC_SUBST(VERSION_REVISION, $revision)
|
||||
|
||||
|
||||
AC_OUTPUT([Makefile
|
||||
msgpack.pc
|
||||
src/Makefile
|
||||
src/msgpack/version.h
|
||||
test/Makefile])
|
||||
|
||||
|
158
erb/cpp03_define.hpp.erb
Normal file
158
erb/cpp03_define.hpp.erb
Normal file
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP03_DEFINE_HPP
|
||||
#define MSGPACK_CPP03_DEFINE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple_fwd.hpp"
|
||||
#include "msgpack/adaptor/int_fwd.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#define MSGPACK_DEFINE(...) \
|
||||
template <typename Packer> \
|
||||
void msgpack_pack(Packer& pk) const \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
|
||||
} \
|
||||
void msgpack_unpack(msgpack::object const& o) \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
|
||||
}\
|
||||
template <typename MSGPACK_OBJECT> \
|
||||
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
|
||||
}
|
||||
|
||||
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||
#define MSGPACK_ADD_ENUM(enum) \
|
||||
namespace msgpack { \
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) { \
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, enum& v) \
|
||||
{ \
|
||||
int tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
inline void operator<< (msgpack::object& o, const enum& v) \
|
||||
{ \
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
inline void operator<< (msgpack::object::with_zone& o, const enum& v) \
|
||||
{ \
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
namespace detail { \
|
||||
template <typename Stream> \
|
||||
struct packer_serializer<Stream, enum> { \
|
||||
static msgpack::packer<Stream>& pack(msgpack::packer<Stream>& o, const enum& v) { \
|
||||
return o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace msgpack {
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
namespace type {
|
||||
|
||||
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct define;
|
||||
|
||||
|
||||
template <>
|
||||
struct define<> {
|
||||
typedef define<> value_type;
|
||||
typedef tuple<> tuple_type;
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
pk.pack_array(0);
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||
{
|
||||
o->type = msgpack::type::ARRAY;
|
||||
o->via.array.ptr = nullptr;
|
||||
o->via.array.size = 0;
|
||||
}
|
||||
};
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
typedef define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
|
||||
typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> tuple_type;
|
||||
define(A0& _a0<%1.upto(i) {|j|%>, A<%=j%>& _a<%=j%><%}%>) :
|
||||
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
pk.pack_array(<%=i+1%>);
|
||||
<%0.upto(i) {|j|%>
|
||||
pk.pack(a<%=j%>);<%}%>
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
const size_t size = o.via.array.size;
|
||||
if(size > 0) {
|
||||
msgpack::object *ptr = o.via.array.ptr;
|
||||
switch(size) {
|
||||
default:<%(i).downto(0) {|j|%>
|
||||
case <%=j+1%>: ptr[<%=j%>].convert(a<%=j%>);<%}%>
|
||||
}
|
||||
}
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
|
||||
{
|
||||
o->type = msgpack::type::ARRAY;
|
||||
o->via.array.ptr = static_cast<msgpack::object*>(z.allocate_align(sizeof(msgpack::object)*<%=i+1%>));
|
||||
o->via.array.size = <%=i+1%>;
|
||||
<%0.upto(i) {|j|%>
|
||||
o->via.array.ptr[<%=j%>] = msgpack::object(a<%=j%>, z);<%}%>
|
||||
}
|
||||
<%0.upto(i) {|j|%>
|
||||
A<%=j%>& a<%=j%>;<%}%>
|
||||
};
|
||||
<%}%>
|
||||
|
||||
inline define<> make_define()
|
||||
{
|
||||
return define<>();
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>)
|
||||
{
|
||||
return define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
} // namespace type
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_CPP03_DEFINE_HPP
|
216
erb/cpp03_msgpack_tuple.hpp.erb
Normal file
216
erb/cpp03_msgpack_tuple.hpp.erb
Normal file
@@ -0,0 +1,216 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP03_MSGPACK_TUPLE_HPP
|
||||
#define MSGPACK_CPP03_MSGPACK_TUPLE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
// FIXME operator==
|
||||
// FIXME operator!=
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
|
||||
template <typename A0<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%><%}%>>
|
||||
struct tuple;
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct tuple_element;
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct const_tuple_element;
|
||||
|
||||
template <typename T>
|
||||
struct tuple_type {
|
||||
typedef T type;
|
||||
typedef T value_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef const T& transparent_reference;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct tuple_type<T&> {
|
||||
typedef T type;
|
||||
typedef T& value_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef T& transparent_reference;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct tuple_type<const T&> {
|
||||
typedef T type;
|
||||
typedef T& value_type;
|
||||
typedef T& reference;
|
||||
typedef const T& const_reference;
|
||||
typedef const T& transparent_reference;
|
||||
};
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
<%0.upto(i) {|j|%>
|
||||
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
|
||||
struct tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> {
|
||||
tuple_element(tuple<A0<%1.upto(i) {|k|%>, A<%=k%> <%}%>>& x) : m_x(x.a<%=j%>) {}
|
||||
typename tuple_type<A<%=j%>>::reference get() { return m_x; }
|
||||
typename tuple_type<A<%=j%>>::const_reference get() const { return m_x; }
|
||||
private:
|
||||
typename tuple_type<A<%=j%>>::reference m_x;
|
||||
};
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
<%0.upto(i) {|j|%>
|
||||
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
|
||||
struct const_tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> {
|
||||
const_tuple_element(const tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>& x) : m_x(x.a<%=j%>) {}
|
||||
typename tuple_type<A<%=j%>>::const_reference get() const { return m_x; }
|
||||
private:
|
||||
typename tuple_type<A<%=j%>>::const_reference m_x;
|
||||
};
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
template <>
|
||||
struct tuple<> {
|
||||
tuple() {}
|
||||
tuple(msgpack::object const& o) { o.convert(*this); }
|
||||
typedef tuple<> value_type;
|
||||
};
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
|
||||
tuple() {}
|
||||
tuple(typename tuple_type<A0>::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference _a<%=j%><%}%>) :
|
||||
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
||||
tuple(msgpack::object const& o) { o.convert(*this); }
|
||||
template <int N> typename tuple_element<value_type, N>::reference get()
|
||||
{ return tuple_element<value_type, N>(*this).get(); }
|
||||
template <int N> typename const_tuple_element<value_type, N>::const_reference get() const
|
||||
{ return const_tuple_element<value_type, N>(*this).get(); }
|
||||
<%0.upto(i) {|j|%>
|
||||
A<%=j%> a<%=j%>;<%}%>
|
||||
};
|
||||
|
||||
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline typename type::tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& t)
|
||||
{ return t.template get<N>(); }
|
||||
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline typename type::const_tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::const_reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> const& t)
|
||||
{ return t.template get<N>(); }
|
||||
<%}%>
|
||||
|
||||
inline tuple<> make_tuple()
|
||||
{
|
||||
return tuple<>();
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference a<%=j%><%}%>)
|
||||
{
|
||||
return tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
|
||||
}
|
||||
<%}%>
|
||||
|
||||
} // namespace type
|
||||
|
||||
inline msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<>&) {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
return o;
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < <%=i+1%>) { throw msgpack::type_error(); }
|
||||
<%0.upto(i) {|j|%>
|
||||
o.via.array.ptr[<%=j%>].convert<typename type::tuple_type<A<%=j%>>::type>(v.template get<<%=j%>>());<%}%>
|
||||
return o;
|
||||
}
|
||||
<%}%>
|
||||
|
||||
template <typename Stream>
|
||||
inline const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<>&) {
|
||||
o.pack_array(0);
|
||||
return o;
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename Stream, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||
o.pack_array(<%=i+1%>);
|
||||
<%0.upto(i) {|j|%>
|
||||
o.pack(v.template get<<%=j%>>());<%}%>
|
||||
return o;
|
||||
}
|
||||
<%}%>
|
||||
|
||||
inline void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
const type::tuple<>&) {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*<%=i+1%>));
|
||||
o.via.array.size = <%=i+1%>;
|
||||
<%0.upto(i) {|j|%>
|
||||
o.via.array.ptr[<%=j%>] = msgpack::object(v.template get<<%=j%>>(), o.zone);<%}%>
|
||||
}
|
||||
<%}%>
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
//inline std::ostream& operator<< (std::ostream& o, const msgpack::type::tuple<>& v) {
|
||||
// return o << "[]";
|
||||
//}
|
||||
//<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
//template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
//inline std::ostream& operator<< (std::ostream& o,
|
||||
// const msgpack::type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||
// return o << "["
|
||||
// <%0.upto(i) {|j|%>
|
||||
// <<<%if j != 0 then%> ", " <<<%end%> v.template get<<%=j%>>()<%}%>
|
||||
// << "]";
|
||||
//}
|
||||
//<%}%>
|
||||
|
||||
#endif // MSGPACK_CPP03_MSGPACK_TUPLE_HPP
|
125
erb/cpp03_msgpack_tuple_fwd.hpp.erb
Normal file
125
erb/cpp03_msgpack_tuple_fwd.hpp.erb
Normal file
@@ -0,0 +1,125 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP03_MSGPACK_TUPLE_FWD_HPP
|
||||
#define MSGPACK_CPP03_MSGPACK_TUPLE_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
// FIXME operator==
|
||||
// FIXME operator!=
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct tuple;
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct tuple_element;
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct const_tuple_element;
|
||||
|
||||
template <typename T>
|
||||
struct tuple_type;
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
<%0.upto(i) {|j|%>
|
||||
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
|
||||
struct tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>>;
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
<%0.upto(i) {|j|%>
|
||||
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
|
||||
struct const_tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>>;
|
||||
<%}%>
|
||||
<%}%>
|
||||
|
||||
template <>
|
||||
struct tuple<>;
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>;
|
||||
|
||||
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
typename type::tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& t);
|
||||
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
typename type::const_tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::const_reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> const& t);
|
||||
<%}%>
|
||||
|
||||
tuple<> make_tuple();
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference a<%=j%><%}%>);
|
||||
<%}%>
|
||||
|
||||
} // namespace type
|
||||
|
||||
msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<>&);
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v);
|
||||
<%}%>
|
||||
|
||||
template <typename Stream>
|
||||
const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<>&);
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename Stream, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v);
|
||||
<%}%>
|
||||
|
||||
void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
const type::tuple<>&);
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v);
|
||||
<%}%>
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
//std::ostream& operator<< (std::ostream& o, const msgpack::type::tuple<>& v);
|
||||
//<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
//template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
//std::ostream& operator<< (std::ostream& o,
|
||||
// const msgpack::type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v);
|
||||
//<%}%>
|
||||
|
||||
#endif // MSGPACK_CPP03_MSGPACK_TUPLE_FWD_HPP
|
332
erb/cpp03_zone.hpp.erb
Normal file
332
erb/cpp03_zone.hpp.erb
Normal file
@@ -0,0 +1,332 @@
|
||||
//
|
||||
// MessagePack for C++ memory pool
|
||||
//
|
||||
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP03_ZONE_HPP
|
||||
#define MSGPACK_CPP03_ZONE_HPP
|
||||
|
||||
#include <cstdlib>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
|
||||
#ifndef MSGPACK_ZONE_CHUNK_SIZE
|
||||
#define MSGPACK_ZONE_CHUNK_SIZE 8192
|
||||
#endif
|
||||
|
||||
#ifndef MSGPACK_ZONE_ALIGN
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(void*)
|
||||
#endif
|
||||
|
||||
<% GENERATION_LIMIT = 15 %>
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
class zone {
|
||||
struct finalizer {
|
||||
finalizer(void (*func)(void*), void* data):m_func(func), m_data(data) {}
|
||||
void operator()() { m_func(m_data); }
|
||||
void (*m_func)(void*);
|
||||
void* m_data;
|
||||
};
|
||||
struct finalizer_array {
|
||||
finalizer_array():m_tail(nullptr), m_end(nullptr), m_array(nullptr) {}
|
||||
void call() {
|
||||
finalizer* fin = m_tail;
|
||||
for(; fin != m_array; --fin) (*(fin-1))();
|
||||
}
|
||||
~finalizer_array() {
|
||||
call();
|
||||
::free(m_array);
|
||||
}
|
||||
void clear() {
|
||||
call();
|
||||
m_tail = m_array;
|
||||
}
|
||||
void push(void (*func)(void* data), void* data)
|
||||
{
|
||||
finalizer* fin = m_tail;
|
||||
|
||||
if(fin == m_end) {
|
||||
push_expand(func, data);
|
||||
return;
|
||||
}
|
||||
|
||||
fin->m_func = func;
|
||||
fin->m_data = data;
|
||||
|
||||
++m_tail;
|
||||
}
|
||||
void push_expand(void (*func)(void*), void* data) {
|
||||
const size_t nused = m_end - m_array;
|
||||
size_t nnext;
|
||||
if(nused == 0) {
|
||||
nnext = (sizeof(finalizer) < 72/2) ?
|
||||
72 / sizeof(finalizer) : 8;
|
||||
} else {
|
||||
nnext = nused * 2;
|
||||
}
|
||||
finalizer* tmp =
|
||||
static_cast<finalizer*>(::realloc(m_array, sizeof(finalizer) * nnext));
|
||||
if(!tmp) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
m_array = tmp;
|
||||
m_end = tmp + nnext;
|
||||
m_tail = tmp + nused;
|
||||
new (m_tail) finalizer(func, data);
|
||||
|
||||
++m_tail;
|
||||
}
|
||||
finalizer* m_tail;
|
||||
finalizer* m_end;
|
||||
finalizer* m_array;
|
||||
};
|
||||
struct chunk {
|
||||
chunk* m_next;
|
||||
};
|
||||
struct chunk_list {
|
||||
chunk_list(size_t chunk_size)
|
||||
{
|
||||
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
|
||||
if(!c) {
|
||||
throw std::bad_alloc();
|
||||
}
|
||||
|
||||
m_head = c;
|
||||
m_free = chunk_size;
|
||||
m_ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
|
||||
c->m_next = nullptr;
|
||||
}
|
||||
~chunk_list()
|
||||
{
|
||||
chunk* c = m_head;
|
||||
while(c) {
|
||||
chunk* n = c->m_next;
|
||||
::free(c);
|
||||
c = n;
|
||||
}
|
||||
}
|
||||
void clear(size_t chunk_size)
|
||||
{
|
||||
chunk* c = m_head;
|
||||
while(true) {
|
||||
chunk* n = c->m_next;
|
||||
if(n) {
|
||||
::free(c);
|
||||
c = n;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
m_head->m_next = nullptr;
|
||||
m_free = chunk_size;
|
||||
m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
|
||||
}
|
||||
size_t m_free;
|
||||
char* m_ptr;
|
||||
chunk* m_head;
|
||||
};
|
||||
size_t m_chunk_size;
|
||||
chunk_list m_chunk_list;
|
||||
finalizer_array m_finalizer_array;
|
||||
|
||||
public:
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
|
||||
|
||||
public:
|
||||
void* allocate_align(size_t size, size_t align = MSGPACK_ZONE_ALIGN);
|
||||
void* allocate_no_align(size_t size);
|
||||
|
||||
void push_finalizer(void (*func)(void*), void* data);
|
||||
|
||||
template <typename T>
|
||||
void push_finalizer(msgpack::unique_ptr<T> obj);
|
||||
|
||||
void clear();
|
||||
|
||||
void swap(zone& o);
|
||||
static void* operator new(std::size_t size)
|
||||
{
|
||||
void* p = ::malloc(size);
|
||||
if (!p) throw std::bad_alloc();
|
||||
return p;
|
||||
}
|
||||
static void operator delete(void *p) /* throw() */
|
||||
{
|
||||
::free(p);
|
||||
}
|
||||
static void* operator new(std::size_t size, void* place) /* throw() */
|
||||
{
|
||||
return ::operator new(size, place);
|
||||
}
|
||||
static void operator delete(void* p, void* place) /* throw() */
|
||||
{
|
||||
::operator delete(p, place);
|
||||
}
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename T<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
T* allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>);
|
||||
<%}%>
|
||||
|
||||
private:
|
||||
void undo_allocate(size_t size);
|
||||
|
||||
template <typename T>
|
||||
static void object_destruct(void* obj);
|
||||
|
||||
template <typename T>
|
||||
static void object_delete(void* obj);
|
||||
|
||||
void* allocate_expand(size_t size);
|
||||
private:
|
||||
zone(const zone&);
|
||||
zone& operator=(const zone&);
|
||||
};
|
||||
|
||||
inline zone::zone(size_t chunk_size) /* throw() */ :m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
|
||||
{
|
||||
}
|
||||
|
||||
inline void* zone::allocate_align(size_t size, size_t align)
|
||||
{
|
||||
char* aligned =
|
||||
reinterpret_cast<char*>(
|
||||
reinterpret_cast<size_t>(
|
||||
(m_chunk_list.m_ptr + (align - 1))) / align * align);
|
||||
size_t adjusted_size = size + (aligned - m_chunk_list.m_ptr);
|
||||
if(m_chunk_list.m_free >= adjusted_size) {
|
||||
m_chunk_list.m_free -= adjusted_size;
|
||||
m_chunk_list.m_ptr += adjusted_size;
|
||||
return aligned;
|
||||
}
|
||||
return reinterpret_cast<char*>(
|
||||
reinterpret_cast<size_t>(
|
||||
allocate_expand(size + (align - 1))) / align * align);
|
||||
}
|
||||
|
||||
inline void* zone::allocate_no_align(size_t size)
|
||||
{
|
||||
if(m_chunk_list.m_free < size) {
|
||||
return allocate_expand(size);
|
||||
}
|
||||
|
||||
char* ptr = m_chunk_list.m_ptr;
|
||||
m_chunk_list.m_free -= size;
|
||||
m_chunk_list.m_ptr += size;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void* zone::allocate_expand(size_t size)
|
||||
{
|
||||
chunk_list* const cl = &m_chunk_list;
|
||||
|
||||
size_t sz = m_chunk_size;
|
||||
|
||||
while(sz < size) {
|
||||
size_t tmp_sz = sz * 2;
|
||||
if (tmp_sz <= sz) {
|
||||
sz = size;
|
||||
break;
|
||||
}
|
||||
sz = tmp_sz;
|
||||
}
|
||||
|
||||
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
|
||||
if (!c) throw std::bad_alloc();
|
||||
|
||||
char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
|
||||
|
||||
c->m_next = cl->m_head;
|
||||
cl->m_head = c;
|
||||
cl->m_free = sz - size;
|
||||
cl->m_ptr = ptr + size;
|
||||
|
||||
return ptr;
|
||||
}
|
||||
|
||||
inline void zone::push_finalizer(void (*func)(void*), void* data)
|
||||
{
|
||||
m_finalizer_array.push(func, data);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
|
||||
{
|
||||
m_finalizer_array.push(&zone::object_delete<T>, obj.release());
|
||||
}
|
||||
|
||||
inline void zone::clear()
|
||||
{
|
||||
m_finalizer_array.clear();
|
||||
m_chunk_list.clear(m_chunk_size);
|
||||
}
|
||||
|
||||
inline void zone::swap(zone& o)
|
||||
{
|
||||
using std::swap;
|
||||
swap(m_chunk_size, o.m_chunk_size);
|
||||
swap(m_chunk_list, o.m_chunk_list);
|
||||
swap(m_finalizer_array, o.m_finalizer_array);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void zone::object_destruct(void* obj)
|
||||
{
|
||||
static_cast<T*>(obj)->~T();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
void zone::object_delete(void* obj)
|
||||
{
|
||||
delete static_cast<T*>(obj);
|
||||
}
|
||||
|
||||
inline void zone::undo_allocate(size_t size)
|
||||
{
|
||||
m_chunk_list.m_ptr -= size;
|
||||
m_chunk_list.m_free += size;
|
||||
}
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename T<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
T* zone::allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>)
|
||||
{
|
||||
void* x = allocate_align(sizeof(T));
|
||||
try {
|
||||
m_finalizer_array.push(&zone::object_destruct<T>, x);
|
||||
} catch (...) {
|
||||
undo_allocate(sizeof(T));
|
||||
throw;
|
||||
}
|
||||
try {
|
||||
return new (x) T(<%=(1..i).map{|j|"a#{j}"}.join(', ')%>);
|
||||
} catch (...) {
|
||||
--m_finalizer_array.m_tail;
|
||||
undo_allocate(sizeof(T));
|
||||
throw;
|
||||
}
|
||||
}
|
||||
<%}%>
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP03_ZONE_HPP
|
119
example/c/lib_buffer_unpack.c
Normal file
119
example/c/lib_buffer_unpack.c
Normal file
@@ -0,0 +1,119 @@
|
||||
#include <msgpack.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
typedef struct receiver {
|
||||
msgpack_sbuffer sbuf;
|
||||
size_t rest;
|
||||
} receiver;
|
||||
|
||||
receiver r;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#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;
|
||||
char* buf;
|
||||
size_t recv_len;
|
||||
|
||||
msgpack_unpacked_init(&result);
|
||||
if (msgpack_unpacker_buffer_capacity(unp) < EACH_RECV_SIZE) {
|
||||
bool expanded = msgpack_unpacker_reserve_buffer(unp, 100);
|
||||
assert(expanded);
|
||||
}
|
||||
buf = msgpack_unpacker_buffer(unp);
|
||||
|
||||
recv_len = receiver_recv(r, buf, EACH_RECV_SIZE);
|
||||
msgpack_unpacker_buffer_consumed(unp, recv_len);
|
||||
|
||||
|
||||
int recv_count = 0;
|
||||
while (recv_len > 0) {
|
||||
int i = 0;
|
||||
printf("receive count: %d %zd bytes received.:\n", recv_count++, recv_len);
|
||||
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;
|
||||
}
|
||||
if (msgpack_unpacker_buffer_capacity(unp) < EACH_RECV_SIZE) {
|
||||
bool expanded = msgpack_unpacker_reserve_buffer(unp, 100);
|
||||
assert(expanded);
|
||||
}
|
||||
buf = msgpack_unpacker_buffer(unp);
|
||||
recv_len = receiver_recv(r, buf, 4);
|
||||
msgpack_unpacker_buffer_consumed(unp, recv_len);
|
||||
}
|
||||
msgpack_unpacked_destroy(&result);
|
||||
}
|
||||
|
||||
int main(void) {
|
||||
receiver r;
|
||||
receiver_init(&r);
|
||||
|
||||
unpack(&r);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Output */
|
||||
|
||||
/*
|
||||
Object no 1:
|
||||
[1, true, "example"]
|
||||
Object no 2:
|
||||
"second"
|
||||
Object no 3:
|
||||
[42, false]
|
||||
*/
|
37
example/c/simple.c
Normal file
37
example/c/simple.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#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;
|
||||
}
|
||||
|
36
example/c/speed_test_uint32_array.c
Normal file
36
example/c/speed_test_uint32_array.c
Normal file
@@ -0,0 +1,36 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint32(pk, 1);
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
}
|
||||
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
return 0;
|
||||
}
|
37
example/c/speed_test_uint64_array.c
Normal file
37
example/c/speed_test_uint64_array.c
Normal file
@@ -0,0 +1,37 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
uint64_t test_u64 = 0xFFF0000000000001LL;
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint64(pk, test_u64);
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
}
|
||||
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
return 0;
|
||||
}
|
75
example/c/user_buffer_unpack.c
Normal file
75
example/c/user_buffer_unpack.c
Normal file
@@ -0,0 +1,75 @@
|
||||
#include <msgpack.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
|
||||
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;
|
||||
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");
|
||||
/* 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]
|
||||
*/
|
83
example/cpp03/class_intrusive.cpp
Normal file
83
example/cpp03/class_intrusive.cpp
Normal file
@@ -0,0 +1,83 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
// msgpack.hpp is also ok
|
||||
#include <msgpack_fwd.hpp>
|
||||
|
||||
|
||||
class my_class {
|
||||
public:
|
||||
my_class() {} // When you want to convert from msgpack::object to my_class,
|
||||
// my_class should be default constractible.
|
||||
my_class(std::string const& name, int age):name_(name), age_(age) {}
|
||||
|
||||
friend bool operator==(my_class const& lhs, my_class const& rhs) {
|
||||
return lhs.name_ == rhs.name_ && lhs.age_ == rhs.age_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
int age_;
|
||||
|
||||
public:
|
||||
MSGPACK_DEFINE(name_, age_);
|
||||
};
|
||||
|
||||
void print(std::string const& buf) {
|
||||
for (std::string::const_iterator it = buf.begin(), end = buf.end();
|
||||
it != end;
|
||||
++it) {
|
||||
std::cout
|
||||
<< std::setw(2)
|
||||
<< std::hex
|
||||
<< std::setfill('0')
|
||||
<< (static_cast<int>(*it) & 0xff)
|
||||
<< ' ';
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
}
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
int main() {
|
||||
{ // pack, unpack
|
||||
my_class my("John Smith", 42);
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, my);
|
||||
|
||||
print(ss.str());
|
||||
|
||||
msgpack::unpacked unp;
|
||||
msgpack::unpack(unp, ss.str().data(), ss.str().size());
|
||||
msgpack::object obj = unp.get();
|
||||
std::cout << obj << std::endl;
|
||||
assert(obj.as<my_class>() == my);
|
||||
}
|
||||
{ // create object with zone
|
||||
my_class my("John Smith", 42);
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(my, z);
|
||||
std::cout << obj << std::endl;
|
||||
assert(obj.as<my_class>() == my);
|
||||
}
|
||||
}
|
139
example/cpp03/class_non_intrusive.cpp
Normal file
139
example/cpp03/class_non_intrusive.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
// msgpack.hpp should be included at after user declarations
|
||||
#include <msgpack_fwd.hpp>
|
||||
|
||||
|
||||
// declarations
|
||||
class my_class;
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||
|
||||
object const& operator>> (msgpack::object const& o, my_class& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (msgpack::packer<Stream>& o, my_class const& v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, my_class const& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
} // namespace msgpack
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
class my_class {
|
||||
public:
|
||||
my_class() {} // When you want to convert from msgpack::object to my_class,
|
||||
// my_class should be default constractible.
|
||||
my_class(std::string const& name, int age):name_(name), age_(age) {}
|
||||
|
||||
// my_class should provide getters for the data members you want to pack.
|
||||
std::string const& get_name() const { return name_; }
|
||||
int get_age() const { return age_; }
|
||||
|
||||
friend bool operator==(my_class const& lhs, my_class const& rhs) {
|
||||
return lhs.name_ == rhs.name_ && lhs.age_ == rhs.age_;
|
||||
}
|
||||
|
||||
private:
|
||||
std::string name_;
|
||||
int age_;
|
||||
};
|
||||
|
||||
|
||||
// definitions
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||
|
||||
inline object const& operator>> (msgpack::object const& o, my_class& v) {
|
||||
if (o.type != msgpack::type::ARRAY) throw msgpack::type_error();
|
||||
if (o.via.array.size != 2) throw msgpack::type_error();
|
||||
v = my_class(
|
||||
o.via.array.ptr[0].as<std::string>(),
|
||||
o.via.array.ptr[1].as<int>());
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (msgpack::packer<Stream>& o, my_class const& v) {
|
||||
// packing member variables as an array.
|
||||
o.pack_array(2);
|
||||
o.pack(v.get_name());
|
||||
o.pack(v.get_age());
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, my_class const& v) {
|
||||
o.type = type::ARRAY;
|
||||
o.via.array.size = 2;
|
||||
o.via.array.ptr = static_cast<object*>(o.zone.allocate_align(sizeof(object) * o.via.array.size));
|
||||
o.via.array.ptr[0] = msgpack::object(v.get_name(), o.zone);
|
||||
o.via.array.ptr[1] = msgpack::object(v.get_age(), o.zone);
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
void print(std::string const& buf) {
|
||||
for (std::string::const_iterator it = buf.begin(), end = buf.end();
|
||||
it != end;
|
||||
++it) {
|
||||
std::cout
|
||||
<< std::setw(2)
|
||||
<< std::hex
|
||||
<< std::setfill('0')
|
||||
<< (static_cast<int>(*it) & 0xff)
|
||||
<< ' ';
|
||||
}
|
||||
std::cout << std::dec << std::endl;
|
||||
}
|
||||
|
||||
int main() {
|
||||
{ // pack, unpack
|
||||
my_class my("John Smith", 42);
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, my);
|
||||
|
||||
print(ss.str());
|
||||
|
||||
msgpack::unpacked unp;
|
||||
msgpack::unpack(unp, ss.str().data(), ss.str().size());
|
||||
msgpack::object obj = unp.get();
|
||||
std::cout << obj << std::endl;
|
||||
assert(obj.as<my_class>() == my);
|
||||
}
|
||||
{ // create object with zone
|
||||
my_class my("John Smith", 42);
|
||||
msgpack::zone z;
|
||||
msgpack::object obj(my, z);
|
||||
std::cout << obj << std::endl;
|
||||
assert(obj.as<my_class>() == my);
|
||||
}
|
||||
}
|
75
example/cpp03/custom.cpp
Normal file
75
example/cpp03/custom.cpp
Normal file
@@ -0,0 +1,75 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <msgpack.hpp>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class old_class {
|
||||
public:
|
||||
old_class() : value("default") { }
|
||||
|
||||
std::string value;
|
||||
|
||||
MSGPACK_DEFINE(value);
|
||||
};
|
||||
|
||||
class new_class {
|
||||
public:
|
||||
new_class() : value("default"), flag(-1) { }
|
||||
|
||||
std::string value;
|
||||
int flag;
|
||||
|
||||
MSGPACK_DEFINE(value, flag);
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
{
|
||||
old_class oc;
|
||||
new_class nc;
|
||||
|
||||
std::stringstream sbuf;
|
||||
msgpack::pack(sbuf, oc);
|
||||
|
||||
msgpack::unpacked result;
|
||||
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size());
|
||||
msgpack::object obj = result.get();
|
||||
|
||||
obj.convert(&nc);
|
||||
|
||||
std::cout << obj << " value=" << nc.value << " flag=" << nc.flag << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
new_class nc;
|
||||
old_class oc;
|
||||
|
||||
std::stringstream sbuf;
|
||||
msgpack::pack(sbuf, nc);
|
||||
|
||||
msgpack::unpacked result;
|
||||
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size());
|
||||
msgpack::object obj = result.get();
|
||||
|
||||
obj.convert(&oc);
|
||||
|
||||
std::cout << obj << " value=" << oc.value << std::endl;
|
||||
}
|
||||
}
|
68
example/cpp03/enum.cpp
Normal file
68
example/cpp03/enum.cpp
Normal file
@@ -0,0 +1,68 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <msgpack_fwd.hpp>
|
||||
#include <sstream>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
enum my_enum {
|
||||
elem1,
|
||||
elem2,
|
||||
elem3
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(my_enum);
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
{ // pack, unpack
|
||||
std::stringstream sbuf;
|
||||
msgpack::pack(sbuf, elem1);
|
||||
msgpack::pack(sbuf, elem2);
|
||||
my_enum e3 = elem3;
|
||||
msgpack::pack(sbuf, e3);
|
||||
|
||||
msgpack::unpacked result;
|
||||
std::size_t off = 0;
|
||||
|
||||
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size(), off);
|
||||
std::cout << result.get().as<my_enum>() << std::endl;
|
||||
assert(result.get().as<my_enum>() == elem1);
|
||||
|
||||
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size(), off);
|
||||
std::cout << result.get().as<my_enum>() << std::endl;
|
||||
assert(result.get().as<my_enum>() == elem2);
|
||||
|
||||
msgpack::unpack(result, sbuf.str().data(), sbuf.str().size(), off);
|
||||
std::cout << result.get().as<my_enum>() << std::endl;
|
||||
assert(result.get().as<my_enum>() == elem3);
|
||||
}
|
||||
{ // create object without zone
|
||||
msgpack::object obj(elem2);
|
||||
std::cout << obj.as<my_enum>() << std::endl;
|
||||
assert(obj.as<my_enum>() == elem2);
|
||||
}
|
||||
{ // create object with zone
|
||||
msgpack::zone z;
|
||||
msgpack::object objz(elem3, z);
|
||||
std::cout << objz.as<my_enum>() << std::endl;
|
||||
assert(objz.as<my_enum>() == elem3);
|
||||
}
|
||||
}
|
103
example/cpp03/protocol.cpp
Normal file
103
example/cpp03/protocol.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace myprotocol {
|
||||
using namespace msgpack::type;
|
||||
using msgpack::define;
|
||||
|
||||
struct Get : define< tuple<uint32_t, std::string> > {
|
||||
Get() { }
|
||||
Get(uint32_t f, const std::string& k) :
|
||||
define_type(msgpack_type(f, k)) { }
|
||||
uint32_t& flags() { return msgpack::type::get<0>(*this); }
|
||||
std::string& key() { return msgpack::type::get<1>(*this); }
|
||||
};
|
||||
|
||||
struct Put : define< tuple<uint32_t, std::string, raw_ref> > {
|
||||
Put() { }
|
||||
Put(uint32_t f, const std::string& k, const char* valref, uint32_t vallen) :
|
||||
define_type(msgpack_type( f, k, raw_ref(valref,vallen) )) { }
|
||||
uint32_t& flags() { return msgpack::type::get<0>(*this); }
|
||||
std::string& key() { return msgpack::type::get<1>(*this); }
|
||||
raw_ref& value() { return msgpack::type::get<2>(*this); }
|
||||
};
|
||||
|
||||
struct MultiGet : define< std::vector<Get> > {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// send Get request
|
||||
std::stringstream stream;
|
||||
{
|
||||
myprotocol::Get req;
|
||||
req.flags() = 0;
|
||||
req.key() = "key0";
|
||||
msgpack::pack(stream, req);
|
||||
}
|
||||
|
||||
stream.seekg(0);
|
||||
|
||||
// receive Get request
|
||||
{
|
||||
std::string buffer(stream.str());
|
||||
|
||||
msgpack::unpacked result;
|
||||
msgpack::unpack(result, buffer.data(), buffer.size());
|
||||
msgpack::object o = result.get();
|
||||
|
||||
myprotocol::Get req;
|
||||
o.convert(req);
|
||||
std::cout << "received: " << o << std::endl;
|
||||
}
|
||||
|
||||
|
||||
stream.str("");
|
||||
|
||||
|
||||
// send MultiGet request
|
||||
{
|
||||
myprotocol::MultiGet req;
|
||||
req.push_back( myprotocol::Get(1, "key1") );
|
||||
req.push_back( myprotocol::Get(2, "key2") );
|
||||
req.push_back( myprotocol::Get(3, "key3") );
|
||||
msgpack::pack(stream, req);
|
||||
}
|
||||
|
||||
stream.seekg(0);
|
||||
|
||||
// receive MultiGet request
|
||||
{
|
||||
std::string buffer(stream.str());
|
||||
|
||||
msgpack::unpacked result;
|
||||
msgpack::unpack(result, buffer.data(), buffer.size());
|
||||
msgpack::object o = result.get();
|
||||
|
||||
|
||||
myprotocol::MultiGet req;
|
||||
o.convert(req);
|
||||
std::cout << "received: " << o << std::endl;
|
||||
}
|
||||
}
|
47
example/cpp03/reuse_zone.cpp
Normal file
47
example/cpp03/reuse_zone.cpp
Normal file
@@ -0,0 +1,47 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
|
||||
int main() {
|
||||
std::vector<int> v;
|
||||
v.push_back(1);
|
||||
v.push_back(42);
|
||||
std::string s("ABC");
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, v);
|
||||
msgpack::pack(ss, s);
|
||||
|
||||
msgpack::zone z;
|
||||
std::size_t offset = 0;
|
||||
|
||||
// msgpack array is constructed on z.
|
||||
msgpack::object obj = msgpack::unpack(z, ss.str().data(), ss.str().size(), offset);
|
||||
assert(obj.as<std::vector<int> >() == v);
|
||||
|
||||
// msgpack str is constructed on z.
|
||||
assert(msgpack::unpack(z, ss.str().data(), ss.str().size(), offset).as<std::string>() == s);
|
||||
}
|
54
example/cpp03/simple.cpp
Normal file
54
example/cpp03/simple.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
msgpack::type::tuple<int, bool, std::string> src(1, true, "example");
|
||||
|
||||
// serialize the object into the buffer.
|
||||
// any classes that implements write(const char*,size_t) can be a buffer.
|
||||
std::stringstream buffer;
|
||||
msgpack::pack(buffer, src);
|
||||
|
||||
// send the buffer ...
|
||||
buffer.seekg(0);
|
||||
|
||||
// deserialize the buffer into msgpack::object instance.
|
||||
std::string str(buffer.str());
|
||||
|
||||
msgpack::unpacked result;
|
||||
|
||||
msgpack::unpack(result, str.data(), str.size());
|
||||
|
||||
// deserialized object is valid during the msgpack::unpacked instance alive.
|
||||
msgpack::object deserialized = result.get();
|
||||
|
||||
// msgpack::object supports ostream.
|
||||
std::cout << deserialized << std::endl;
|
||||
|
||||
// convert msgpack::object instance into the original type.
|
||||
// if the type is mismatched, it throws msgpack::type_error exception.
|
||||
msgpack::type::tuple<int, bool, std::string> dst;
|
||||
deserialized.convert(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
71
example/cpp03/speed_test.cpp
Normal file
71
example/cpp03/speed_test.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2013-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
// g++ -std=c++11 -O3 -g -Ipath_to_msgpack_src -Ipath_to_boost speed_test.cc -Lpath_to_boost_lib -lboost_timer -lboost_system
|
||||
// export LD_LIBRARY_PATH=path_to_boost_lib
|
||||
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <map>
|
||||
#include <boost/timer/timer.hpp>
|
||||
|
||||
void test_map_pack_unpack() {
|
||||
std::cout << "[TEST][map_pack_unpack]" << std::endl;
|
||||
// setup
|
||||
std::cout << "Setting up map data..." << std::endl;
|
||||
std::map<int, int> m1;
|
||||
int const num = 30000000L;
|
||||
for (int i = 0; i < num; ++i) m1[i] = i;
|
||||
std::cout << "Start packing..." << std::endl;
|
||||
std::stringstream buffer;
|
||||
{
|
||||
boost::timer::cpu_timer timer;
|
||||
msgpack::pack(buffer, m1);
|
||||
std::string result = timer.format();
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
std::cout << "Pack finished..." << std::endl;
|
||||
|
||||
buffer.seekg(0);
|
||||
std::string str(buffer.str());
|
||||
|
||||
msgpack::unpacked unpacked;
|
||||
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
|
||||
{
|
||||
boost::timer::cpu_timer timer;
|
||||
msgpack::unpack(unpacked, str.data(), str.size());
|
||||
std::string result = timer.format();
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
std::cout << "Unpack finished..." << std::endl;
|
||||
std::map<int, int> m2;
|
||||
std::cout << "Start converting..." << std::endl;
|
||||
{
|
||||
boost::timer::cpu_timer timer;
|
||||
unpacked.get().convert(&m2);
|
||||
std::string result = timer.format();
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
std::cout << "Convert finished..." << std::endl;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_map_pack_unpack();
|
||||
}
|
94
example/cpp03/speed_test_nested_array.cpp
Normal file
94
example/cpp03/speed_test_nested_array.cpp
Normal file
@@ -0,0 +1,94 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2013-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
// g++ -std=c++11 -O3 -g -Ipath_to_msgpack_src -Ipath_to_boost speed_test.cc -Lpath_to_boost_lib -lboost_timer -lboost_system
|
||||
// export LD_LIBRARY_PATH=path_to_boost_lib
|
||||
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <vector>
|
||||
#include <boost/timer/timer.hpp>
|
||||
|
||||
template <typename T, std::size_t level>
|
||||
struct vecvec {
|
||||
typedef std::vector<typename vecvec<T, level - 1>::type> type;
|
||||
static void fill(type& v, std::size_t num_of_elems, T const& val) {
|
||||
for (int elem = 0; elem < num_of_elems; ++elem) {
|
||||
typename vecvec<T, level - 1>::type child;
|
||||
vecvec<T, level - 1>::fill(child, num_of_elems, val);
|
||||
v.push_back(child);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct vecvec<T, 0> {
|
||||
typedef std::vector<T> type;
|
||||
static void fill(type& v, std::size_t num_of_elems, T const& val) {
|
||||
for (int elem = 0; elem < num_of_elems; ++elem) {
|
||||
v.push_back(val);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void test_array_of_array() {
|
||||
std::cout << "[TEST][array_of_array]" << std::endl;
|
||||
// setup
|
||||
int const depth = 16;
|
||||
std::cout << "Setting up array data..." << std::endl;
|
||||
typename vecvec<int, depth>::type v1;
|
||||
vecvec<int, depth>::fill(v1, 3, 42);
|
||||
|
||||
std::cout << "Start packing..." << std::endl;
|
||||
std::stringstream buffer;
|
||||
{
|
||||
boost::timer::cpu_timer timer;
|
||||
msgpack::pack(buffer, v1);
|
||||
std::string result = timer.format();
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
std::cout << "Pack finished..." << std::endl;
|
||||
|
||||
buffer.seekg(0);
|
||||
std::string str(buffer.str());
|
||||
|
||||
msgpack::unpacked unpacked;
|
||||
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
|
||||
{
|
||||
boost::timer::cpu_timer timer;
|
||||
msgpack::unpack(unpacked, str.data(), str.size());
|
||||
std::string result = timer.format();
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
std::cout << "Unpack finished..." << std::endl;
|
||||
typename vecvec<int, depth>::type v2;
|
||||
std::cout << "Start converting..." << std::endl;
|
||||
{
|
||||
boost::timer::cpu_timer timer;
|
||||
unpacked.get().convert(&v2);
|
||||
std::string result = timer.format();
|
||||
std::cout << result << std::endl;
|
||||
}
|
||||
std::cout << "Convert finished..." << std::endl;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
test_array_of_array();
|
||||
}
|
150
example/cpp03/stream.cpp
Normal file
150
example/cpp03/stream.cpp
Normal file
@@ -0,0 +1,150 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <msgpack.hpp>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
class Server {
|
||||
public:
|
||||
Server(int sock) : m_sock(sock) { }
|
||||
|
||||
~Server() { }
|
||||
|
||||
typedef msgpack::unique_ptr<msgpack::zone> unique_zone;
|
||||
|
||||
void socket_readable()
|
||||
{
|
||||
m_pac.reserve_buffer(1024);
|
||||
|
||||
ssize_t count =
|
||||
read(m_sock, m_pac.buffer(), m_pac.buffer_capacity());
|
||||
|
||||
if(count <= 0) {
|
||||
if(count == 0) {
|
||||
throw std::runtime_error("connection closed");
|
||||
}
|
||||
if(errno == EAGAIN || errno == EINTR) {
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
|
||||
m_pac.buffer_consumed(count);
|
||||
|
||||
msgpack::unpacked result;
|
||||
while (m_pac.next(&result)) {
|
||||
msgpack::object msg = result.get();
|
||||
unique_zone& life = result.zone();
|
||||
process_message(msg, life);
|
||||
}
|
||||
|
||||
if(m_pac.message_size() > 10*1024*1024) {
|
||||
throw std::runtime_error("message is too large");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void process_message(msgpack::object msg, unique_zone&)
|
||||
{
|
||||
std::cout << "message reached: " << msg << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_sock;
|
||||
msgpack::unpacker m_pac;
|
||||
};
|
||||
|
||||
|
||||
static void* run_server(void* arg)
|
||||
{
|
||||
try {
|
||||
Server* srv = reinterpret_cast<Server*>(arg);
|
||||
|
||||
while(true) {
|
||||
srv->socket_readable();
|
||||
}
|
||||
return NULL;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "error while processing client packet: "
|
||||
<< e.what() << std::endl;
|
||||
return NULL;
|
||||
|
||||
} catch (...) {
|
||||
std::cerr << "error while processing client packet: "
|
||||
<< "unknown error" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
|
||||
struct fwriter {
|
||||
fwriter(int fd) : m_fp( fdopen(fd, "w") ) { }
|
||||
|
||||
void write(const char* buf, size_t buflen)
|
||||
{
|
||||
size_t count = fwrite(buf, buflen, 1, m_fp);
|
||||
if(count < 1) {
|
||||
std::cout << buflen << std::endl;
|
||||
std::cout << count << std::endl;
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void flush() { fflush(m_fp); }
|
||||
|
||||
void close() { fclose(m_fp); }
|
||||
|
||||
private:
|
||||
FILE* m_fp;
|
||||
};
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int pair[2];
|
||||
pipe(pair);
|
||||
|
||||
// run server thread
|
||||
Server srv(pair[0]);
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL,
|
||||
run_server, reinterpret_cast<void*>(&srv));
|
||||
|
||||
// client thread:
|
||||
fwriter writer(pair[1]);
|
||||
msgpack::packer<fwriter> pk(writer);
|
||||
|
||||
typedef msgpack::type::tuple<std::string, std::string, std::string> put_t;
|
||||
typedef msgpack::type::tuple<std::string, std::string> get_t;
|
||||
|
||||
put_t req1("put", "apple", "red");
|
||||
put_t req2("put", "lemon", "yellow");
|
||||
get_t req3("get", "apple");
|
||||
pk.pack(req1);
|
||||
pk.pack(req2);
|
||||
pk.pack(req3);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
pthread_join(thread, NULL);
|
||||
}
|
108
example/cpp11/container.cpp
Normal file
108
example/cpp11/container.cpp
Normal file
@@ -0,0 +1,108 @@
|
||||
// MessagePack for C++ example
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
#include <cassert>
|
||||
|
||||
#include <array>
|
||||
#include <tuple>
|
||||
#include <unordered_map>
|
||||
#include <unordered_set>
|
||||
#include <forward_list>
|
||||
#include <string>
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
void array() {
|
||||
std::array<int, 5> a { 1, 2, 3, 4, 5 };
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, a);
|
||||
|
||||
msgpack::unpacked und = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
msgpack::object obj = und.get();
|
||||
std::array<int, 5> const& new_a = obj.as<std::array<int, 5>>();
|
||||
|
||||
assert(new_a == a);
|
||||
}
|
||||
|
||||
void tuple() {
|
||||
std::tuple<bool, std::string, int> t(true, "ABC", 42);
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, t);
|
||||
|
||||
auto und = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
auto obj = und.get();
|
||||
assert(obj.as<decltype(t)>() == t);
|
||||
}
|
||||
|
||||
void unordered_map() {
|
||||
std::unordered_map<std::string, int> m { {"ABC", 1}, {"DEF", 3} };
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, m);
|
||||
|
||||
auto und = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
assert(und.get().as<decltype(m)>() == m);
|
||||
}
|
||||
|
||||
void unordered_set() {
|
||||
std::unordered_set<std::string> s { "ABC", "DEF" };
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, s);
|
||||
|
||||
assert(msgpack::unpack(ss.str().data(), ss.str().size()).get().as<decltype(s)>() == s);
|
||||
}
|
||||
|
||||
void forward_list() {
|
||||
using type = std::forward_list<std::string>;
|
||||
type f { "ABC", "DEF" };
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, f);
|
||||
|
||||
assert(msgpack::unpack(ss.str().data(), ss.str().size()).get().as<type>() == f);
|
||||
}
|
||||
|
||||
void combi() {
|
||||
std::array<int, 5> a { 1, 2, 3, 4, 5 };
|
||||
std::tuple<bool, std::string, int> t {true, "ABC", 42};
|
||||
std::unordered_map<std::string, int> m { {"ABC", 1}, {"DEF", 3} };
|
||||
std::unordered_set<std::string> s { "ABC", "DEF" };
|
||||
std::forward_list<std::string> f { "ABC", "DEF" };
|
||||
|
||||
std::stringstream ss;
|
||||
msgpack::pack(ss, a);
|
||||
msgpack::pack(ss, t);
|
||||
msgpack::pack(ss, m);
|
||||
msgpack::pack(ss, s);
|
||||
msgpack::pack(ss, f);
|
||||
|
||||
std::size_t offset = 0;
|
||||
assert(msgpack::unpack(ss.str().data(), ss.str().size(), offset).get().as<decltype(a)>() == a);
|
||||
assert(msgpack::unpack(ss.str().data(), ss.str().size(), offset).get().as<decltype(t)>() == t);
|
||||
assert(msgpack::unpack(ss.str().data(), ss.str().size(), offset).get().as<decltype(m)>() == m);
|
||||
assert(msgpack::unpack(ss.str().data(), ss.str().size(), offset).get().as<decltype(s)>() == s);
|
||||
assert(msgpack::unpack(ss.str().data(), ss.str().size(), offset).get().as<decltype(f)>() == f);
|
||||
}
|
||||
|
||||
int main() {
|
||||
array();
|
||||
tuple();
|
||||
unordered_map();
|
||||
unordered_set();
|
||||
forward_list();
|
||||
combi();
|
||||
}
|
@@ -1,58 +0,0 @@
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
|
||||
class old_class {
|
||||
public:
|
||||
old_class() : value("default") { }
|
||||
|
||||
std::string value;
|
||||
|
||||
MSGPACK_DEFINE(value);
|
||||
};
|
||||
|
||||
class new_class {
|
||||
public:
|
||||
new_class() : value("default"), flag(-1) { }
|
||||
|
||||
std::string value;
|
||||
int flag;
|
||||
|
||||
MSGPACK_DEFINE(value, flag);
|
||||
};
|
||||
|
||||
int main(void)
|
||||
{
|
||||
{
|
||||
old_class oc;
|
||||
new_class nc;
|
||||
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, oc);
|
||||
|
||||
msgpack::zone zone;
|
||||
msgpack::object obj;
|
||||
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
|
||||
|
||||
obj.convert(&nc);
|
||||
|
||||
std::cout << obj << " value=" << nc.value << " flag=" << nc.flag << std::endl;
|
||||
}
|
||||
|
||||
{
|
||||
new_class nc;
|
||||
old_class oc;
|
||||
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, nc);
|
||||
|
||||
msgpack::zone zone;
|
||||
msgpack::object obj;
|
||||
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
|
||||
|
||||
obj.convert(&oc);
|
||||
|
||||
std::cout << obj << " value=" << oc.value << std::endl;
|
||||
}
|
||||
}
|
||||
|
@@ -1,86 +0,0 @@
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
namespace myprotocol {
|
||||
using namespace msgpack::type;
|
||||
using msgpack::define;
|
||||
|
||||
struct Get : define< tuple<uint32_t, std::string> > {
|
||||
Get() { }
|
||||
Get(uint32_t f, const std::string& k) :
|
||||
define_type(msgpack_type(f, k)) { }
|
||||
uint32_t& flags() { return get<0>(); }
|
||||
std::string& key() { return get<1>(); }
|
||||
};
|
||||
|
||||
struct Put : define< tuple<uint32_t, std::string, raw_ref> > {
|
||||
Put() { }
|
||||
Put(uint32_t f, const std::string& k, const char* valref, uint32_t vallen) :
|
||||
define_type(msgpack_type( f, k, raw_ref(valref,vallen) )) { }
|
||||
uint32_t& flags() { return get<0>(); }
|
||||
std::string& key() { return get<1>(); }
|
||||
raw_ref& value() { return get<2>(); }
|
||||
};
|
||||
|
||||
struct MultiGet : define< std::vector<Get> > {
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// send Get request
|
||||
std::stringstream stream;
|
||||
{
|
||||
myprotocol::Get req;
|
||||
req.flags() = 0;
|
||||
req.key() = "key0";
|
||||
msgpack::pack(stream, req);
|
||||
}
|
||||
|
||||
stream.seekg(0);
|
||||
|
||||
// receive Get request
|
||||
{
|
||||
std::string buffer(stream.str());
|
||||
|
||||
msgpack::zone mempool;
|
||||
msgpack::object o =
|
||||
msgpack::unpack(buffer.data(), buffer.size(), mempool);
|
||||
|
||||
myprotocol::Get req;
|
||||
msgpack::convert(req, o);
|
||||
std::cout << "received: " << o << std::endl;
|
||||
}
|
||||
|
||||
|
||||
stream.str("");
|
||||
|
||||
|
||||
// send MultiGet request
|
||||
{
|
||||
myprotocol::MultiGet req;
|
||||
req.push_back( myprotocol::Get(1, "key1") );
|
||||
req.push_back( myprotocol::Get(2, "key2") );
|
||||
req.push_back( myprotocol::Get(3, "key3") );
|
||||
msgpack::pack(stream, req);
|
||||
}
|
||||
|
||||
stream.seekg(0);
|
||||
|
||||
// receive MultiGet request
|
||||
{
|
||||
std::string buffer(stream.str());
|
||||
|
||||
msgpack::zone mempool;
|
||||
msgpack::object o =
|
||||
msgpack::unpack(buffer.data(), buffer.size(), mempool);
|
||||
|
||||
myprotocol::MultiGet req;
|
||||
msgpack::convert(req, o);
|
||||
std::cout << "received: " << o << std::endl;
|
||||
}
|
||||
}
|
||||
|
@@ -1,37 +0,0 @@
|
||||
#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_raw(&pk, 7);
|
||||
msgpack_pack_raw_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;
|
||||
}
|
||||
|
@@ -1,37 +0,0 @@
|
||||
#include <msgpack.hpp>
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
msgpack::type::tuple<int, bool, std::string> src(1, true, "example");
|
||||
|
||||
// serialize the object into the buffer.
|
||||
// any classes that implements write(const char*,size_t) can be a buffer.
|
||||
std::stringstream buffer;
|
||||
msgpack::pack(buffer, src);
|
||||
|
||||
// send the buffer ...
|
||||
buffer.seekg(0);
|
||||
|
||||
// deserialize the buffer into msgpack::object instance.
|
||||
std::string str(buffer.str());
|
||||
|
||||
// deserialized object is valid during the msgpack::zone instance alive.
|
||||
msgpack::zone mempool;
|
||||
|
||||
msgpack::object deserialized;
|
||||
msgpack::unpack(str.data(), str.size(), NULL, &mempool, &deserialized);
|
||||
|
||||
// msgpack::object supports ostream.
|
||||
std::cout << deserialized << std::endl;
|
||||
|
||||
// convert msgpack::object instance into the original type.
|
||||
// if the type is mismatched, it throws msgpack::type_error exception.
|
||||
msgpack::type::tuple<int, bool, std::string> dst;
|
||||
deserialized.convert(&dst);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,36 +0,0 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint32(pk, 1);
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
}
|
||||
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
return 0;
|
||||
}
|
@@ -1,37 +0,0 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
uint64_t test_u64 = 0xFFF0000000000001LL;
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
int idx = 0;
|
||||
for (; idx < size; ++idx)
|
||||
msgpack_pack_uint64(pk, test_u64);
|
||||
}
|
||||
msgpack_packer_free(pk);
|
||||
|
||||
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
msgpack_unpacked_init(&msg);
|
||||
|
||||
while (msgpack_unpack_next(&msg, buf.data, buf.size, &upk_pos)) {
|
||||
}
|
||||
|
||||
msgpack_sbuffer_destroy(&buf);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int i = 0;
|
||||
for (; i < 10; ++i) test();
|
||||
return 0;
|
||||
}
|
@@ -1,133 +0,0 @@
|
||||
#include <msgpack.hpp>
|
||||
#include <iostream>
|
||||
#include <stdexcept>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <errno.h>
|
||||
#include <pthread.h>
|
||||
|
||||
class Server {
|
||||
public:
|
||||
Server(int sock) : m_sock(sock) { }
|
||||
|
||||
~Server() { }
|
||||
|
||||
typedef std::auto_ptr<msgpack::zone> auto_zone;
|
||||
|
||||
void socket_readable()
|
||||
{
|
||||
m_pac.reserve_buffer(1024);
|
||||
|
||||
ssize_t count =
|
||||
read(m_sock, m_pac.buffer(), m_pac.buffer_capacity());
|
||||
|
||||
if(count <= 0) {
|
||||
if(count == 0) {
|
||||
throw std::runtime_error("connection closed");
|
||||
}
|
||||
if(errno == EAGAIN || errno == EINTR) {
|
||||
return;
|
||||
}
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
|
||||
m_pac.buffer_consumed(count);
|
||||
|
||||
msgpack::unpacked result;
|
||||
while (m_pac.next(&result)) {
|
||||
msgpack::object msg = result.get();
|
||||
auto_zone& life = result.zone();
|
||||
process_message(msg, life);
|
||||
}
|
||||
|
||||
if(m_pac.message_size() > 10*1024*1024) {
|
||||
throw std::runtime_error("message is too large");
|
||||
}
|
||||
}
|
||||
|
||||
private:
|
||||
void process_message(msgpack::object msg, auto_zone& life)
|
||||
{
|
||||
std::cout << "message reached: " << msg << std::endl;
|
||||
}
|
||||
|
||||
private:
|
||||
int m_sock;
|
||||
msgpack::unpacker m_pac;
|
||||
};
|
||||
|
||||
|
||||
static void* run_server(void* arg)
|
||||
try {
|
||||
Server* srv = reinterpret_cast<Server*>(arg);
|
||||
|
||||
while(true) {
|
||||
srv->socket_readable();
|
||||
}
|
||||
return NULL;
|
||||
|
||||
} catch (std::exception& e) {
|
||||
std::cerr << "error while processing client packet: "
|
||||
<< e.what() << std::endl;
|
||||
return NULL;
|
||||
|
||||
} catch (...) {
|
||||
std::cerr << "error while processing client packet: "
|
||||
<< "unknown error" << std::endl;
|
||||
return NULL;
|
||||
}
|
||||
|
||||
|
||||
struct fwriter {
|
||||
fwriter(int fd) : m_fp( fdopen(fd, "w") ) { }
|
||||
|
||||
void write(const char* buf, size_t buflen)
|
||||
{
|
||||
size_t count = fwrite(buf, buflen, 1, m_fp);
|
||||
if(count < 1) {
|
||||
std::cout << buflen << std::endl;
|
||||
std::cout << count << std::endl;
|
||||
throw std::runtime_error(strerror(errno));
|
||||
}
|
||||
}
|
||||
|
||||
void flush() { fflush(m_fp); }
|
||||
|
||||
void close() { fclose(m_fp); }
|
||||
|
||||
private:
|
||||
FILE* m_fp;
|
||||
};
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int pair[2];
|
||||
pipe(pair);
|
||||
|
||||
// run server thread
|
||||
Server srv(pair[0]);
|
||||
pthread_t thread;
|
||||
pthread_create(&thread, NULL,
|
||||
run_server, reinterpret_cast<void*>(&srv));
|
||||
|
||||
// client thread:
|
||||
fwriter writer(pair[1]);
|
||||
msgpack::packer<fwriter> pk(writer);
|
||||
|
||||
typedef msgpack::type::tuple<std::string, std::string, std::string> put_t;
|
||||
typedef msgpack::type::tuple<std::string, std::string> get_t;
|
||||
|
||||
put_t req1("put", "apple", "red");
|
||||
put_t req2("put", "lemon", "yellow");
|
||||
get_t req3("get", "apple");
|
||||
pk.pack(req1);
|
||||
pk.pack(req2);
|
||||
pk.pack(req3);
|
||||
writer.flush();
|
||||
writer.close();
|
||||
|
||||
pthread_join(thread, NULL);
|
||||
}
|
||||
|
@@ -21,6 +21,7 @@
|
||||
* @}
|
||||
*/
|
||||
|
||||
#include "msgpack/util.h"
|
||||
#include "msgpack/object.h"
|
||||
#include "msgpack/zone.h"
|
||||
#include "msgpack/pack.h"
|
@@ -16,9 +16,10 @@
|
||||
// limitations under the License.
|
||||
//
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/iterator.hpp"
|
||||
#include "msgpack/zone.hpp"
|
||||
#include "msgpack/pack.hpp"
|
||||
#include "msgpack/unpack.hpp"
|
||||
#include "msgpack/sbuffer.hpp"
|
||||
#include "msgpack/vrefbuffer.hpp"
|
||||
#include "msgpack.h"
|
||||
#include "msgpack/version.hpp"
|
58
include/msgpack/adaptor/bool.hpp
Normal file
58
include/msgpack/adaptor/bool.hpp
Normal file
@@ -0,0 +1,58 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_BOOL_HPP
|
||||
#define MSGPACK_TYPE_BOOL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, bool& v)
|
||||
{
|
||||
if(o.type != msgpack::type::BOOLEAN) { throw msgpack::type_error(); }
|
||||
v = o.via.boolean;
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const bool& v)
|
||||
{
|
||||
if(v) { o.pack_true(); }
|
||||
else { o.pack_false(); }
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, bool v)
|
||||
{
|
||||
o.type = msgpack::type::BOOLEAN;
|
||||
o.via.boolean = v;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, bool v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOL_HPP
|
@@ -15,41 +15,25 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_BOOL_HPP__
|
||||
#define MSGPACK_TYPE_BOOL_HPP__
|
||||
#ifndef MSGPACK_TYPE_BOOL_FWD_HPP
|
||||
#define MSGPACK_TYPE_BOOL_FWD_HPP
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include <vector>
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
inline bool& operator>> (object o, bool& v)
|
||||
{
|
||||
if(o.type != type::BOOLEAN) { throw type_error(); }
|
||||
v = o.via.boolean;
|
||||
return v;
|
||||
}
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, bool& v);
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const bool& v)
|
||||
{
|
||||
if(v) { o.pack_true(); }
|
||||
else { o.pack_false(); }
|
||||
return o;
|
||||
}
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const bool& v);
|
||||
void operator<< (msgpack::object& o, bool v);
|
||||
void operator<< (msgpack::object::with_zone& o, bool v);
|
||||
|
||||
inline void operator<< (object& o, bool v)
|
||||
{
|
||||
o.type = type::BOOLEAN;
|
||||
o.via.boolean = v;
|
||||
}
|
||||
|
||||
inline void operator<< (object::with_zone& o, bool v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/bool.hpp */
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOL_FWD_HPP
|
78
include/msgpack/adaptor/char_ptr.hpp
Normal file
78
include/msgpack/adaptor/char_ptr.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_CHAR_PTR_HPP
|
||||
#define MSGPACK_TYPE_CHAR_PTR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const char* v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, const char* v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v, size);
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, const char* v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = size;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, char* v)
|
||||
{
|
||||
return msgpack::operator<<(o, static_cast<const char*>(v));
|
||||
}
|
||||
|
||||
inline void operator<< (object::with_zone& o, char* v)
|
||||
{
|
||||
msgpack::operator<<(o, static_cast<const char*>(v));
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, char* v)
|
||||
{
|
||||
msgpack::operator<<(o, static_cast<const char*>(v));
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_CHAR_PTR_HPP
|
43
include/msgpack/adaptor/char_ptr_fwd.hpp
Normal file
43
include/msgpack/adaptor/char_ptr_fwd.hpp
Normal file
@@ -0,0 +1,43 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_CHAR_PTR_FWD_HPP
|
||||
#define MSGPACK_TYPE_CHAR_PTR_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <cstring>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const char* v);
|
||||
void operator<< (msgpack::object::with_zone& o, const char* v);
|
||||
void operator<< (msgpack::object& o, const char* v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, char* v);
|
||||
void operator<< (object::with_zone& o, char* v);
|
||||
void operator<< (object& o, char* v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_CHAR_PTR_FWD_HPP
|
61
include/msgpack/adaptor/check_container_size.hpp
Normal file
61
include/msgpack/adaptor/check_container_size.hpp
Normal file
@@ -0,0 +1,61 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CHECK_CONTAINER_SIZE_HPP
|
||||
#define MSGPACK_CHECK_CONTAINER_SIZE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include <stdexcept>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
struct container_size_overflow : public std::runtime_error {
|
||||
explicit container_size_overflow(const std::string& msg)
|
||||
:std::runtime_error(msg) {}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
explicit container_size_overflow(const char* msg):
|
||||
std::runtime_error(msg) {}
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
|
||||
template <std::size_t N>
|
||||
inline void check_container_size(std::size_t size) {
|
||||
if (size > 0xffffffff) throw container_size_overflow("container size overflow");
|
||||
}
|
||||
|
||||
template <>
|
||||
inline void check_container_size<4>(std::size_t size) {
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
|
||||
template <typename T>
|
||||
inline uint32_t checked_get_container_size(T size) {
|
||||
detail::check_container_size<sizeof(T)>(size);
|
||||
return static_cast<uint32_t>(size);
|
||||
}
|
||||
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CHECK_CONTAINER_SIZE_HPP
|
76
include/msgpack/adaptor/cpp11/array.hpp
Normal file
76
include/msgpack/adaptor/cpp11/array.hpp
Normal file
@@ -0,0 +1,76 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef MSGPACK_CPP11_ARRAY_HPP
|
||||
#define MSGPACK_CPP11_ARRAY_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::array<T, N>& v) {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != N) { throw msgpack::type_error(); }
|
||||
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;
|
||||
T* it = &v[0];
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T, std::size_t N>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::array<T, N>& v) {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::array<T, N>& v) {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.size = size;
|
||||
o.via.array.ptr = p;
|
||||
for (auto const& e : v) *p++ = msgpack::object(e, o.zone);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_ARRAY_HPP
|
84
include/msgpack/adaptor/cpp11/array_char.hpp
Normal file
84
include/msgpack/adaptor/cpp11/array_char.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_ARRAY_CHAR_HPP
|
||||
#define MSGPACK_TYPE_ARRAY_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <std::size_t N>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::array<char, N>& v)
|
||||
{
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
if(o.via.bin.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
if(o.via.str.size != N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, std::size_t N>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::array<char, N>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(v.data(), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
inline void operator<< (msgpack::object& o, const std::array<char, N>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = v.data();
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
|
||||
template <std::size_t N>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::array<char, N>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, v.data(), size);
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_CHAR_HPP
|
45
include/msgpack/adaptor/cpp11/array_char_fwd.hpp
Normal file
45
include/msgpack/adaptor/cpp11/array_char_fwd.hpp
Normal file
@@ -0,0 +1,45 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP
|
||||
#define MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <std::size_t N>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::array<char, N>& v);
|
||||
|
||||
template <typename Stream, std::size_t N>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::array<char, N>& v);
|
||||
|
||||
template <std::size_t N>
|
||||
void operator<< (msgpack::object& o, const std::array<char, N>& v);
|
||||
|
||||
template <std::size_t N>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::array<char, N>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP
|
44
include/msgpack/adaptor/cpp11/array_fwd.hpp
Normal file
44
include/msgpack/adaptor/cpp11/array_fwd.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef MSGPACK_CPP11_ARRAY_FWD_HPP
|
||||
#define MSGPACK_CPP11_ARRAY_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::array<T, N>& v);
|
||||
|
||||
template <typename Stream, typename T, std::size_t N>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::array<T, N>& v);
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::array<T, N>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_ARRAY_FWD_HPP
|
75
include/msgpack/adaptor/cpp11/forward_list.hpp
Normal file
75
include/msgpack/adaptor/cpp11/forward_list.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO-2015 Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef MSGPACK_CPP11_FORWARD_LIST_HPP
|
||||
#define MSGPACK_CPP11_FORWARD_LIST_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::forward_list<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
for (auto &e : v) {
|
||||
p->convert(e);
|
||||
++p;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::forward_list<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
||||
o.pack_array(size);
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::forward_list<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end()));
|
||||
o.via.array.size = size;
|
||||
msgpack::object* p = static_cast<msgpack::object*>(
|
||||
o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.ptr = p;
|
||||
for(auto const& e : v) *p++ = msgpack::object(e, o.zone);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_FORWARD_LIST_HPP
|
44
include/msgpack/adaptor/cpp11/forward_list_fwd.hpp
Normal file
44
include/msgpack/adaptor/cpp11/forward_list_fwd.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
|
||||
#ifndef MSGPACK_CPP11_FORWARD_LIST_FWD_HPP
|
||||
#define MSGPACK_CPP11_FORWARD_LIST_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::forward_list<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::forward_list<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::forward_list<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_FORWARD_LIST_FWD_HPP
|
152
include/msgpack/adaptor/cpp11/tuple.hpp
Normal file
152
include/msgpack/adaptor/cpp11/tuple.hpp
Normal file
@@ -0,0 +1,152 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP11_TUPLE_HPP
|
||||
#define MSGPACK_CPP11_TUPLE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
// --- Pack from tuple to packer stream ---
|
||||
template <typename Stream, typename Tuple, std::size_t N>
|
||||
struct StdTuplePacker {
|
||||
static void pack(
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
StdTuplePacker<Stream, Tuple, N-1>::pack(o, v);
|
||||
o.pack(std::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename Tuple>
|
||||
struct StdTuplePacker<Stream, Tuple, 1> {
|
||||
static void pack (
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
o.pack(std::get<0>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename Tuple>
|
||||
struct StdTuplePacker<Stream, Tuple, 0> {
|
||||
static void pack (
|
||||
msgpack::packer<Stream>&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
template <typename Stream, typename... Args>
|
||||
inline const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const std::tuple<Args...>& v) {
|
||||
uint32_t size = checked_get_container_size(sizeof...(Args));
|
||||
o.pack_array(size);
|
||||
StdTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
|
||||
return o;
|
||||
}
|
||||
|
||||
// --- Convert from tuple to object ---
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleConverter {
|
||||
static void convert(
|
||||
msgpack::object const& o,
|
||||
Tuple& v) {
|
||||
StdTupleConverter<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(std::get<N-1>(v))>::type>(std::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct StdTupleConverter<Tuple, 1> {
|
||||
static void convert (
|
||||
msgpack::object const& o,
|
||||
Tuple& v) {
|
||||
o.via.array.ptr[0].convert<typename std::remove_reference<decltype(std::get<0>(v))>::type>(std::get<0>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct StdTupleConverter<Tuple, 0> {
|
||||
static void convert (
|
||||
msgpack::object const&,
|
||||
Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
inline msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
std::tuple<Args...>& v) {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
StdTupleConverter<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
return o;
|
||||
}
|
||||
|
||||
// --- Convert from tuple to object with zone ---
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleToObjectWithZone {
|
||||
static void convert(
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
StdTupleToObjectWithZone<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1] = msgpack::object(std::get<N-1>(v), o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct StdTupleToObjectWithZone<Tuple, 1> {
|
||||
static void convert (
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
o.via.array.ptr[0] = msgpack::object(std::get<0>(v), o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct StdTupleToObjectWithZone<Tuple, 0> {
|
||||
static void convert (
|
||||
msgpack::object::with_zone&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
inline void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
std::tuple<Args...> const& v) {
|
||||
uint32_t size = checked_get_container_size(sizeof...(Args));
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
o.via.array.size = size;
|
||||
StdTupleToObjectWithZone<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_TUPLE_HPP
|
62
include/msgpack/adaptor/cpp11/tuple_fwd.hpp
Normal file
62
include/msgpack/adaptor/cpp11/tuple_fwd.hpp
Normal file
@@ -0,0 +1,62 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP11_TUPLE_FWD_HPP
|
||||
#define MSGPACK_CPP11_TUPLE_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
// --- Pack from tuple to packer stream ---
|
||||
template <typename Stream, typename Tuple, std::size_t N>
|
||||
struct StdTuplePacker;
|
||||
|
||||
template <typename Stream, typename... Args>
|
||||
const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const std::tuple<Args...>& v);
|
||||
|
||||
// --- Convert from tuple to object ---
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleConverter;
|
||||
|
||||
template <typename... Args>
|
||||
msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
std::tuple<Args...>& v);
|
||||
|
||||
// --- Convert from tuple to object with zone ---
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleToObjectWithZone;
|
||||
|
||||
template <typename... Args>
|
||||
void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
std::tuple<Args...> const& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_TUPLE_FWD_HPP
|
142
include/msgpack/adaptor/cpp11/unordered_map.hpp
Normal file
142
include/msgpack/adaptor/cpp11/unordered_map.hpp
Normal file
@@ -0,0 +1,142 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_UNORDERED_MAP_HPP
|
||||
#define MSGPACK_TYPE_UNORDERED_MAP_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename K, typename V>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::unordered_map<K, V>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::unordered_map<K, V> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
K key;
|
||||
p->key.convert(key);
|
||||
p->val.convert(tmp[key]);
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_map<K,V>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::unordered_map<K,V>& v)
|
||||
{
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::unordered_map<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::unordered_multimap<K, V>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::unordered_multimap<K, V> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
std::pair<K, V> value;
|
||||
p->key.convert(value.first);
|
||||
p->val.convert(value.second);
|
||||
tmp.insert(value);
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_multimap<K,V>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::unordered_multimap<K,V>& v)
|
||||
{
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::unordered_multimap<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_MAP_HPP
|
53
include/msgpack/adaptor/cpp11/unordered_map_fwd.hpp
Normal file
53
include/msgpack/adaptor/cpp11/unordered_map_fwd.hpp
Normal file
@@ -0,0 +1,53 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_UNORDERED_MAP_FWD_HPP
|
||||
#define MSGPACK_TYPE_UNORDERED_MAP_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename K, typename V>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::unordered_map<K, V>& v);
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::unordered_map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::unordered_multimap<K, V>& v);
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_multimap<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::unordered_multimap<K,V>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_MAP_FWD_HPP
|
134
include/msgpack/adaptor/cpp11/unordered_set.hpp
Normal file
134
include/msgpack/adaptor/cpp11/unordered_set.hpp
Normal file
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_UNORDERED_SET_HPP
|
||||
#define MSGPACK_TYPE_UNORDERED_SET_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::unordered_set<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::unordered_set<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_set<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::unordered_set<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::unordered_set<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::unordered_multiset<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::unordered_multiset<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_multiset<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::unordered_multiset<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::unordered_multiset<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_SET_HPP
|
52
include/msgpack/adaptor/cpp11/unordered_set_fwd.hpp
Normal file
52
include/msgpack/adaptor/cpp11/unordered_set_fwd.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_UNORDERED_SET_FWD_HPP
|
||||
#define MSGPACK_TYPE_UNORDERED_SET_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::unordered_set<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::unordered_set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::unordered_multiset<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::unordered_multiset<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::unordered_multiset<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_SET_FWD_HPP
|
29
include/msgpack/adaptor/define.hpp
Normal file
29
include/msgpack/adaptor/define.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_DEFINE_HPP
|
||||
#define MSGPACK_DEFINE_HPP
|
||||
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
#include "detail/cpp03_define.hpp"
|
||||
#else // MSGPACK_USE_CPP03
|
||||
#include "detail/cpp11_define.hpp"
|
||||
#endif // MSGPACK_USE_CPP03
|
||||
|
||||
#endif // MSGPACK_DEFINE_HPP
|
83
include/msgpack/adaptor/deque.hpp
Normal file
83
include/msgpack/adaptor/deque.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_DEQUE_HPP
|
||||
#define MSGPACK_TYPE_DEQUE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::deque<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::deque<T>::iterator it = v.begin();
|
||||
for(; p < pend; ++p, ++it) {
|
||||
p->convert(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::deque<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::deque<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::deque<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::deque<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/deque.hpp */
|
40
include/msgpack/adaptor/deque_fwd.hpp
Normal file
40
include/msgpack/adaptor/deque_fwd.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_DEQUE_FWD_HPP
|
||||
#define MSGPACK_TYPE_DEQUE_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <deque>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::deque<T>& v);
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::deque<T>& v);
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::deque<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_DEQUE_FWD_HPP
|
3475
include/msgpack/adaptor/detail/cpp03_define.hpp
Normal file
3475
include/msgpack/adaptor/detail/cpp03_define.hpp
Normal file
File diff suppressed because it is too large
Load Diff
13918
include/msgpack/adaptor/detail/cpp03_msgpack_tuple.hpp
Normal file
13918
include/msgpack/adaptor/detail/cpp03_msgpack_tuple.hpp
Normal file
File diff suppressed because it is too large
Load Diff
4341
include/msgpack/adaptor/detail/cpp03_msgpack_tuple_fwd.hpp
Normal file
4341
include/msgpack/adaptor/detail/cpp03_msgpack_tuple_fwd.hpp
Normal file
File diff suppressed because it is too large
Load Diff
184
include/msgpack/adaptor/detail/cpp11_define.hpp
Normal file
184
include/msgpack/adaptor/detail/cpp11_define.hpp
Normal file
@@ -0,0 +1,184 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP11_DEFINE_HPP
|
||||
#define MSGPACK_CPP11_DEFINE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
// for MSGPACK_ADD_ENUM
|
||||
#include "msgpack/adaptor/int_fwd.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
|
||||
#define MSGPACK_DEFINE(...) \
|
||||
template <typename Packer> \
|
||||
void msgpack_pack(Packer& pk) const \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
|
||||
} \
|
||||
void msgpack_unpack(msgpack::object const& o) \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
|
||||
}\
|
||||
template <typename MSGPACK_OBJECT> \
|
||||
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
|
||||
{ \
|
||||
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
|
||||
}
|
||||
|
||||
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||
#define MSGPACK_ADD_ENUM(enum) \
|
||||
namespace msgpack { \
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) { \
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, enum& v) \
|
||||
{ \
|
||||
std::underlying_type<enum>::type tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
inline void operator<< (msgpack::object& o, const enum& v) \
|
||||
{ \
|
||||
auto tmp = static_cast<std::underlying_type<enum>::type>(v); \
|
||||
o << tmp; \
|
||||
} \
|
||||
inline void operator<< (msgpack::object::with_zone& o, const enum& v) \
|
||||
{ \
|
||||
auto tmp = static_cast<std::underlying_type<enum>::type>(v); \
|
||||
o << tmp; \
|
||||
} \
|
||||
namespace detail { \
|
||||
template <typename Stream> \
|
||||
struct packer_serializer<Stream, enum> { \
|
||||
static msgpack::packer<Stream>& pack(msgpack::packer<Stream>& o, const enum& v) { \
|
||||
return o << static_cast<std::underlying_type<enum>::type>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
} \
|
||||
}
|
||||
|
||||
namespace msgpack {
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
namespace type {
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct define_imp {
|
||||
template <typename Packer>
|
||||
static void pack(Packer& pk, Tuple const& t) {
|
||||
define_imp<Tuple, N-1>::pack(pk, t);
|
||||
pk.pack(std::get<N-1>(t));
|
||||
}
|
||||
static void unpack(msgpack::object const& o, Tuple& t) {
|
||||
define_imp<Tuple, N-1>::unpack(o, t);
|
||||
const size_t size = o.via.array.size;
|
||||
if(size <= N-1) { return; }
|
||||
o.via.array.ptr[N-1].convert(std::get<N-1>(t));
|
||||
}
|
||||
static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) {
|
||||
define_imp<Tuple, N-1>::object(o, z, t);
|
||||
o->via.array.ptr[N-1] = msgpack::object(std::get<N-1>(t), z);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct define_imp<Tuple, 1> {
|
||||
template <typename Packer>
|
||||
static void pack(Packer& pk, Tuple const& t) {
|
||||
pk.pack(std::get<0>(t));
|
||||
}
|
||||
static void unpack(msgpack::object const& o, Tuple& t) {
|
||||
const size_t size = o.via.array.size;
|
||||
if(size <= 0) { return; }
|
||||
o.via.array.ptr[0].convert(std::get<0>(t));
|
||||
}
|
||||
static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) {
|
||||
o->via.array.ptr[0] = msgpack::object(std::get<0>(t), z);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
struct define {
|
||||
typedef define<Args...> value_type;
|
||||
typedef std::tuple<Args...> tuple_type;
|
||||
define(Args&... args) :
|
||||
a(args...) {}
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
pk.pack_array(sizeof...(Args));
|
||||
|
||||
define_imp<std::tuple<Args&...>, sizeof...(Args)>::pack(pk, a);
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
|
||||
define_imp<std::tuple<Args&...>, sizeof...(Args)>::unpack(o, a);
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
|
||||
{
|
||||
o->type = msgpack::type::ARRAY;
|
||||
o->via.array.ptr = static_cast<msgpack::object*>(z.allocate_align(sizeof(msgpack::object)*sizeof...(Args)));
|
||||
o->via.array.size = sizeof...(Args);
|
||||
|
||||
define_imp<std::tuple<Args&...>, sizeof...(Args)>::object(o, z, a);
|
||||
}
|
||||
|
||||
std::tuple<Args&...> a;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct define<> {
|
||||
typedef define<> value_type;
|
||||
typedef std::tuple<> tuple_type;
|
||||
template <typename Packer>
|
||||
void msgpack_pack(Packer& pk) const
|
||||
{
|
||||
pk.pack_array(0);
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||
{
|
||||
o->type = msgpack::type::ARRAY;
|
||||
o->via.array.ptr = NULL;
|
||||
o->via.array.size = 0;
|
||||
}
|
||||
};
|
||||
|
||||
inline define<> make_define()
|
||||
{
|
||||
return define<>();
|
||||
}
|
||||
|
||||
template <typename... Args>
|
||||
define<Args...> make_define(Args&... args)
|
||||
{
|
||||
return define<Args...>(args...);
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_DEFINE_HPP
|
212
include/msgpack/adaptor/detail/cpp11_msgpack_tuple.hpp
Normal file
212
include/msgpack/adaptor/detail/cpp11_msgpack_tuple.hpp
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP11_MSGPACK_TUPLE_HPP
|
||||
#define MSGPACK_CPP11_MSGPACK_TUPLE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
// tuple
|
||||
using std::get;
|
||||
using std::tuple_size;
|
||||
using std::tuple_element;
|
||||
using std::uses_allocator;
|
||||
using std::ignore;
|
||||
using std::make_tuple;
|
||||
using std::tie;
|
||||
using std::forward_as_tuple;
|
||||
using std::swap;
|
||||
|
||||
template< class... Types >
|
||||
class tuple : public std::tuple<Types...> {
|
||||
public:
|
||||
using base = std::tuple<Types...>;
|
||||
|
||||
using base::base;
|
||||
|
||||
tuple() = default;
|
||||
tuple(tuple const&) = default;
|
||||
tuple(tuple&&) = default;
|
||||
|
||||
template<typename... OtherTypes>
|
||||
tuple(tuple<OtherTypes...> const& other):base(static_cast<std::tuple<OtherTypes...> const&>(other)) {}
|
||||
template<typename... OtherTypes>
|
||||
tuple(tuple<OtherTypes...> && other):base(static_cast<std::tuple<OtherTypes...> &&>(other)) {}
|
||||
|
||||
tuple& operator=(tuple const&) = default;
|
||||
tuple& operator=(tuple&&) = default;
|
||||
|
||||
template<typename... OtherTypes>
|
||||
tuple& operator=(tuple<OtherTypes...> const& other) {
|
||||
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> const&>(other);
|
||||
return *this;
|
||||
}
|
||||
template<typename... OtherTypes>
|
||||
tuple& operator=(tuple<OtherTypes...> && other) {
|
||||
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> &&>(other);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template< std::size_t I>
|
||||
typename tuple_element<I, base >::type&
|
||||
get() { return std::get<I>(*this); }
|
||||
|
||||
template< std::size_t I>
|
||||
typename tuple_element<I, base >::type const&
|
||||
get() const { return std::get<I>(*this); }
|
||||
|
||||
template< std::size_t I>
|
||||
typename tuple_element<I, base >::type&&
|
||||
get() && { return std::get<I>(*this); }
|
||||
};
|
||||
|
||||
template< class... Tuples >
|
||||
auto tuple_cat(Tuples&&... args) ->
|
||||
decltype(
|
||||
std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...)
|
||||
) {
|
||||
return std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...);
|
||||
}
|
||||
} // namespace type
|
||||
|
||||
// --- Pack from tuple to packer stream ---
|
||||
template <typename Stream, typename Tuple, std::size_t N>
|
||||
struct MsgpackTuplePacker {
|
||||
static void pack(
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
MsgpackTuplePacker<Stream, Tuple, N-1>::pack(o, v);
|
||||
o.pack(type::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename Tuple>
|
||||
struct MsgpackTuplePacker<Stream, Tuple, 1> {
|
||||
static void pack (
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
o.pack(type::get<0>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename Tuple>
|
||||
struct MsgpackTuplePacker<Stream, Tuple, 0> {
|
||||
static void pack (
|
||||
msgpack::packer<Stream>&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename... Args>
|
||||
const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<Args...>& v) {
|
||||
o.pack_array(sizeof...(Args));
|
||||
MsgpackTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
|
||||
return o;
|
||||
}
|
||||
|
||||
// --- Convert from tuple to object ---
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct MsgpackTupleConverter {
|
||||
static void convert(
|
||||
msgpack::object const& o,
|
||||
Tuple& v) {
|
||||
MsgpackTupleConverter<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(type::get<N-1>(v))>::type>(type::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct MsgpackTupleConverter<Tuple, 1> {
|
||||
static void convert (
|
||||
msgpack::object const& o,
|
||||
Tuple& v) {
|
||||
o.via.array.ptr[0].convert<typename std::remove_reference<decltype(type::get<0>(v))>::type>(type::get<0>(v));
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct MsgpackTupleConverter<Tuple, 0> {
|
||||
static void convert (
|
||||
msgpack::object const&,
|
||||
Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<Args...>& v) {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
MsgpackTupleConverter<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
return o;
|
||||
}
|
||||
|
||||
// --- Convert from tuple to object with zone ---
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct MsgpackTupleToObjectWithZone {
|
||||
static void convert(
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
MsgpackTupleToObjectWithZone<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1] = msgpack::object(type::get<N-1>(v), o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct MsgpackTupleToObjectWithZone<Tuple, 1> {
|
||||
static void convert (
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
o.via.array.ptr[0] = msgpack::object(type::get<0>(v), o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct MsgpackTupleToObjectWithZone<Tuple, 0> {
|
||||
static void convert (
|
||||
msgpack::object::with_zone&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
inline void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
type::tuple<Args...> const& v) {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*sizeof...(Args)));
|
||||
o.via.array.size = sizeof...(Args);
|
||||
MsgpackTupleToObjectWithZone<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_MSGPACK_TUPLE_HPP
|
84
include/msgpack/adaptor/detail/cpp11_msgpack_tuple_fwd.hpp
Normal file
84
include/msgpack/adaptor/detail/cpp11_msgpack_tuple_fwd.hpp
Normal file
@@ -0,0 +1,84 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_CPP11_MSGPACK_TUPLE_FWD_HPP
|
||||
#define MSGPACK_CPP11_MSGPACK_TUPLE_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
// tuple
|
||||
using std::get;
|
||||
using std::tuple_size;
|
||||
using std::tuple_element;
|
||||
using std::uses_allocator;
|
||||
using std::ignore;
|
||||
using std::make_tuple;
|
||||
using std::tie;
|
||||
using std::forward_as_tuple;
|
||||
using std::swap;
|
||||
|
||||
template< class... Types >
|
||||
class tuple;
|
||||
|
||||
template< class... Tuples >
|
||||
auto tuple_cat(Tuples&&... args) ->
|
||||
decltype(
|
||||
std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...)
|
||||
);
|
||||
} // namespace type
|
||||
|
||||
// --- Pack ( from tuple to packer stream ---
|
||||
template <typename Stream, typename Tuple, std::size_t N>
|
||||
struct MsgpackTuplePacker;
|
||||
|
||||
template <typename Stream, typename... Args>
|
||||
const msgpack::packer<Stream>& operator<< (
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<Args...>& v);
|
||||
|
||||
// --- Convert from tuple to object ---
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct MsgpackTupleConverter;
|
||||
|
||||
template <typename... Args>
|
||||
msgpack::object const& operator>> (
|
||||
msgpack::object const& o,
|
||||
type::tuple<Args...>& v);
|
||||
|
||||
// --- Convert from tuple to object with zone ---
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct MsgpackTupleToObjectWithZone;
|
||||
|
||||
template <typename... Args>
|
||||
void operator<< (
|
||||
msgpack::object::with_zone& o,
|
||||
type::tuple<Args...> const& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_MSGPACK_TUPLE_FWD_HPP
|
212
include/msgpack/adaptor/fixint.hpp
Normal file
212
include/msgpack/adaptor/fixint.hpp
Normal file
@@ -0,0 +1,212 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2020 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_FIXINT_HPP
|
||||
#define MSGPACK_TYPE_FIXINT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct fix_int {
|
||||
fix_int() : value(0) { }
|
||||
fix_int(T value) : value(value) { }
|
||||
|
||||
operator T() const { return value; }
|
||||
|
||||
T get() const { return value; }
|
||||
|
||||
private:
|
||||
T value;
|
||||
};
|
||||
|
||||
|
||||
typedef fix_int<uint8_t> fix_uint8;
|
||||
typedef fix_int<uint16_t> fix_uint16;
|
||||
typedef fix_int<uint32_t> fix_uint32;
|
||||
typedef fix_int<uint64_t> fix_uint64;
|
||||
|
||||
typedef fix_int<int8_t> fix_int8;
|
||||
typedef fix_int<int16_t> fix_int16;
|
||||
typedef fix_int<int32_t> fix_int32;
|
||||
typedef fix_int<int64_t> fix_int64;
|
||||
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_int8& v)
|
||||
{ v = type::detail::convert_integer<int8_t>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_int16& v)
|
||||
{ v = type::detail::convert_integer<int16_t>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_int32& v)
|
||||
{ v = type::detail::convert_integer<int32_t>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_int64& v)
|
||||
{ v = type::detail::convert_integer<int64_t>(o); return o; }
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint8& v)
|
||||
{ v = type::detail::convert_integer<uint8_t>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint16& v)
|
||||
{ v = type::detail::convert_integer<uint16_t>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint32& v)
|
||||
{ v = type::detail::convert_integer<uint32_t>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint64& v)
|
||||
{ v = type::detail::convert_integer<uint64_t>(o); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int8& v)
|
||||
{ o.pack_fix_int8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int16& v)
|
||||
{ o.pack_fix_int16(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int32& v)
|
||||
{ o.pack_fix_int32(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int64& v)
|
||||
{ o.pack_fix_int64(v); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint8& v)
|
||||
{ o.pack_fix_uint8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint16& v)
|
||||
{ o.pack_fix_uint16(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint32& v)
|
||||
{ o.pack_fix_uint32(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint64& v)
|
||||
{ o.pack_fix_uint64(v); return o; }
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_int8 v)
|
||||
{
|
||||
if (v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_int16 v)
|
||||
{
|
||||
if(v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_int32 v)
|
||||
{
|
||||
if (v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_int64 v)
|
||||
{
|
||||
if (v.get() < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_uint8 v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_uint16 v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_uint32 v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::fix_uint64 v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_int8 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_int16 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_int32 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_int64 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_uint8 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_uint16 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_uint32 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::fix_uint64 v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/fixint.hpp */
|
100
include/msgpack/adaptor/fixint_fwd.hpp
Normal file
100
include/msgpack/adaptor/fixint_fwd.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_FIXINT_FWD_HPP
|
||||
#define MSGPACK_TYPE_FIXINT_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct fix_int;
|
||||
|
||||
typedef fix_int<uint8_t> fix_uint8;
|
||||
typedef fix_int<uint16_t> fix_uint16;
|
||||
typedef fix_int<uint32_t> fix_uint32;
|
||||
typedef fix_int<uint64_t> fix_uint64;
|
||||
|
||||
typedef fix_int<int8_t> fix_int8;
|
||||
typedef fix_int<int16_t> fix_int16;
|
||||
typedef fix_int<int32_t> fix_int32;
|
||||
typedef fix_int<int64_t> fix_int64;
|
||||
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_int8& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_int16& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_int32& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_int64& v);
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint8& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint16& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint32& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::fix_uint64& v);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int8& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int16& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int32& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_int64& v);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint8& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint16& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint32& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::fix_uint64& v);
|
||||
|
||||
void operator<< (msgpack::object& o, type::fix_int8 v);
|
||||
void operator<< (msgpack::object& o, type::fix_int16 v);
|
||||
void operator<< (msgpack::object& o, type::fix_int32 v);
|
||||
void operator<< (msgpack::object& o, type::fix_int64 v);
|
||||
|
||||
void operator<< (msgpack::object& o, type::fix_uint8 v);
|
||||
void operator<< (msgpack::object& o, type::fix_uint16 v);
|
||||
void operator<< (msgpack::object& o, type::fix_uint32 v);
|
||||
void operator<< (msgpack::object& o, type::fix_uint64 v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_int8 v);
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_int16 v);
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_int32 v);
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_int64 v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_uint8 v);
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_uint16 v);
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_uint32 v);
|
||||
void operator<< (msgpack::object::with_zone& o, type::fix_uint64 v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_FIXINT_FWD_HPP
|
105
include/msgpack/adaptor/float.hpp
Normal file
105
include/msgpack/adaptor/float.hpp
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_FLOAT_HPP
|
||||
#define MSGPACK_TYPE_FLOAT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
// FIXME check overflow, underflow
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, float& v)
|
||||
{
|
||||
if(o.type == msgpack::type::FLOAT) {
|
||||
v = static_cast<float>(o.via.f64);
|
||||
}
|
||||
else if (o.type == msgpack::type::POSITIVE_INTEGER) {
|
||||
v = static_cast<float>(o.via.u64);
|
||||
}
|
||||
else if (o.type == msgpack::type::NEGATIVE_INTEGER) {
|
||||
v = static_cast<float>(o.via.i64);
|
||||
}
|
||||
else {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const float& v)
|
||||
{
|
||||
o.pack_float(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, double& v)
|
||||
{
|
||||
if(o.type == msgpack::type::FLOAT) {
|
||||
v = o.via.f64;
|
||||
}
|
||||
else if (o.type == msgpack::type::POSITIVE_INTEGER) {
|
||||
v = static_cast<double>(o.via.u64);
|
||||
}
|
||||
else if (o.type == msgpack::type::NEGATIVE_INTEGER) {
|
||||
v = static_cast<double>(o.via.i64);
|
||||
}
|
||||
else {
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const double& v)
|
||||
{
|
||||
o.pack_double(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object& o, float v)
|
||||
{
|
||||
o.type = msgpack::type::FLOAT;
|
||||
o.via.f64 = static_cast<double>(v);
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, double v)
|
||||
{
|
||||
o.type = msgpack::type::FLOAT;
|
||||
o.via.f64 = v;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, float v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, double v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_FLOAT_HPP
|
44
include/msgpack/adaptor/float_fwd.hpp
Normal file
44
include/msgpack/adaptor/float_fwd.hpp
Normal file
@@ -0,0 +1,44 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_FLOAT_FWD_HPP
|
||||
#define MSGPACK_TYPE_FLOAT_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, float& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const float& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, double& v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const double& v);
|
||||
void operator<< (msgpack::object& o, float v);
|
||||
void operator<< (msgpack::object& o, double v);
|
||||
void operator<< (msgpack::object::with_zone& o, float v);
|
||||
void operator<< (msgpack::object::with_zone& o, double v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_FLOAT_FWD_HPP
|
308
include/msgpack/adaptor/int.hpp
Normal file
308
include/msgpack/adaptor/int.hpp
Normal file
@@ -0,0 +1,308 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_INT_HPP
|
||||
#define MSGPACK_TYPE_INT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack_fwd.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1){
|
||||
|
||||
namespace type {
|
||||
namespace detail {
|
||||
template <typename T, bool Signed>
|
||||
struct convert_integer_sign;
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, true> {
|
||||
static inline T convert(msgpack::object const& o) {
|
||||
if(o.type == msgpack::type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.u64);
|
||||
} else if(o.type == msgpack::type::NEGATIVE_INTEGER) {
|
||||
if(o.via.i64 < static_cast<int64_t>(std::numeric_limits<T>::min()))
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.i64);
|
||||
}
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, false> {
|
||||
static inline T convert(msgpack::object const& o) {
|
||||
if(o.type == msgpack::type::POSITIVE_INTEGER) {
|
||||
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.u64);
|
||||
}
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct is_signed {
|
||||
static const bool value = std::numeric_limits<T>::is_signed;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static inline T convert_integer(msgpack::object const& o)
|
||||
{
|
||||
return detail::convert_integer_sign<T, is_signed<T>::value>::convert(o);
|
||||
}
|
||||
|
||||
template <bool Signed>
|
||||
struct object_char_sign;
|
||||
|
||||
template <>
|
||||
struct object_char_sign<true> {
|
||||
static inline void make(msgpack::object& o, char v) {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_char_sign<false> {
|
||||
static inline void make(msgpack::object& o, char v) {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||
}
|
||||
};
|
||||
|
||||
static inline void object_char(msgpack::object& o, char v) {
|
||||
return object_char_sign<is_signed<char>::value>::make(o, v);
|
||||
}
|
||||
|
||||
} // namespace detail
|
||||
} // namespace type
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, char& v)
|
||||
{ v = type::detail::convert_integer<char>(o); return o; }
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, signed char& v)
|
||||
{ v = type::detail::convert_integer<signed char>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, signed short& v)
|
||||
{ v = type::detail::convert_integer<signed short>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, signed int& v)
|
||||
{ v = type::detail::convert_integer<signed int>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, signed long& v)
|
||||
{ v = type::detail::convert_integer<signed long>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, signed long long& v)
|
||||
{ v = type::detail::convert_integer<signed long long>(o); return o; }
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, unsigned char& v)
|
||||
{ v = type::detail::convert_integer<unsigned char>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, unsigned short& v)
|
||||
{ v = type::detail::convert_integer<unsigned short>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, unsigned int& v)
|
||||
{ v = type::detail::convert_integer<unsigned int>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, unsigned long& v)
|
||||
{ v = type::detail::convert_integer<unsigned long>(o); return o; }
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, unsigned long long& v)
|
||||
{ v = type::detail::convert_integer<unsigned long long>(o); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, char v)
|
||||
{ o.pack_char(v); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed char v)
|
||||
{ o.pack_signed_char(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed short v)
|
||||
{ o.pack_short(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed int v)
|
||||
{ o.pack_int(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed long v)
|
||||
{ o.pack_long(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed long long v)
|
||||
{ o.pack_long_long(v); return o; }
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned char v)
|
||||
{ o.pack_unsigned_char(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned short v)
|
||||
{ o.pack_unsigned_short(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned int v)
|
||||
{ o.pack_unsigned_int(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned long v)
|
||||
{ o.pack_unsigned_long(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned long long v)
|
||||
{ o.pack_unsigned_long_long(v); return o; }
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object& o, char v)
|
||||
{ type::detail::object_char(o, v); }
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object& o, signed char v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, signed short v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, signed int v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, signed long v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, signed long long v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else{
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, unsigned char v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (msgpack::object& o, unsigned short v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (msgpack::object& o, unsigned int v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (msgpack::object& o, unsigned long v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (msgpack::object& o, unsigned long long v)
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, char v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, signed char v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, signed short v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, signed int v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, signed long v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, const signed long long& v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, unsigned char v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, unsigned short v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, unsigned int v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, unsigned long v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, const unsigned long long& v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/int.hpp */
|
100
include/msgpack/adaptor/int_fwd.hpp
Normal file
100
include/msgpack/adaptor/int_fwd.hpp
Normal file
@@ -0,0 +1,100 @@
|
||||
//
|
||||
// MessagePack for C++ forward declaration
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_INT_FWD_HPP
|
||||
#define MSGPACK_TYPE_INT_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1){
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, char& v);
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, signed char& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, signed short& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, signed int& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, signed long& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, signed long long& v);
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, unsigned char& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, unsigned short& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, unsigned int& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, unsigned long& v);
|
||||
msgpack::object const& operator>> (msgpack::object const& o, unsigned long long& v);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, char v);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed char v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed short v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed int v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed long v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, signed long long v);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned char v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned short v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned int v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned long v);
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, unsigned long long v);
|
||||
|
||||
|
||||
void operator<< (msgpack::object& o, char v);
|
||||
|
||||
void operator<< (msgpack::object& o, signed char v);
|
||||
void operator<< (msgpack::object& o, signed short v);
|
||||
void operator<< (msgpack::object& o, signed int v);
|
||||
void operator<< (msgpack::object& o, signed long v);
|
||||
void operator<< (msgpack::object& o, signed long long v);
|
||||
|
||||
void operator<< (msgpack::object& o, unsigned char v);
|
||||
void operator<< (msgpack::object& o, unsigned short v);
|
||||
void operator<< (msgpack::object& o, unsigned int v);
|
||||
void operator<< (msgpack::object& o, unsigned long v);
|
||||
void operator<< (msgpack::object& o, unsigned long long v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, char v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, signed char v);
|
||||
void operator<< (msgpack::object::with_zone& o, signed short v);
|
||||
void operator<< (msgpack::object::with_zone& o, signed int v);
|
||||
void operator<< (msgpack::object::with_zone& o, signed long v);
|
||||
void operator<< (msgpack::object::with_zone& o, const signed long long& v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, unsigned char v);
|
||||
void operator<< (msgpack::object::with_zone& o, unsigned short v);
|
||||
void operator<< (msgpack::object::with_zone& o, unsigned int v);
|
||||
void operator<< (msgpack::object::with_zone& o, unsigned long v);
|
||||
void operator<< (msgpack::object::with_zone& o, const unsigned long long& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_INT_FWD_HPP
|
83
include/msgpack/adaptor/list.hpp
Normal file
83
include/msgpack/adaptor/list.hpp
Normal file
@@ -0,0 +1,83 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_LIST_HPP
|
||||
#define MSGPACK_TYPE_LIST_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::list<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
typename std::list<T>::iterator it = v.begin();
|
||||
for(; p < pend; ++p, ++it) {
|
||||
p->convert(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::list<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::list<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::list<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::list<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_LIST_HPP
|
40
include/msgpack/adaptor/list_fwd.hpp
Normal file
40
include/msgpack/adaptor/list_fwd.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_LIST_FWD_HPP
|
||||
#define MSGPACK_TYPE_LIST_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::list<T>& v);
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::list<T>& v);
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::list<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_LIST_FWD_HPP
|
219
include/msgpack/adaptor/map.hpp
Normal file
219
include/msgpack/adaptor/map.hpp
Normal file
@@ -0,0 +1,219 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_MAP_HPP
|
||||
#define MSGPACK_TYPE_MAP_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename K, typename V>
|
||||
class assoc_vector : public std::vector< std::pair<K, V> > {};
|
||||
|
||||
namespace detail {
|
||||
template <typename K, typename V>
|
||||
struct pair_first_less {
|
||||
bool operator() (const std::pair<K, V>& x, const std::pair<K, V>& y) const
|
||||
{ return x.first < y.first; }
|
||||
};
|
||||
}
|
||||
|
||||
} //namespace type
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::assoc_vector<K,V>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.map.size);
|
||||
msgpack::object_kv* p = o.via.map.ptr;
|
||||
msgpack::object_kv* const pend = o.via.map.ptr + o.via.map.size;
|
||||
std::pair<K, V>* it(&v.front());
|
||||
for(; p < pend; ++p, ++it) {
|
||||
p->key.convert(it->first);
|
||||
p->val.convert(it->second);
|
||||
}
|
||||
std::sort(v.begin(), v.end(), type::detail::pair_first_less<K,V>());
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::assoc_vector<K,V>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename type::assoc_vector<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const type::assoc_vector<K,V>& v)
|
||||
{
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename type::assoc_vector<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::map<K, V>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::map<K, V> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
K key;
|
||||
p->key.convert(key);
|
||||
typename std::map<K,V>::iterator it(tmp.lower_bound(key));
|
||||
if(it != tmp.end() && !(key < it->first)) {
|
||||
p->val.convert(it->second);
|
||||
} else {
|
||||
V val;
|
||||
p->val.convert(val);
|
||||
tmp.insert(it, std::pair<K,V>(key, val));
|
||||
}
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::map<K,V>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::map<K,V>& v)
|
||||
{
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::map<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::multimap<K, V>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
std::multimap<K, V> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
std::pair<K, V> value;
|
||||
p->key.convert(value.first);
|
||||
p->val.convert(value.second);
|
||||
tmp.insert(value);
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::multimap<K,V>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::multimap<K,V>& v)
|
||||
{
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename std::multimap<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_MAP_HPP
|
69
include/msgpack/adaptor/map_fwd.hpp
Normal file
69
include/msgpack/adaptor/map_fwd.hpp
Normal file
@@ -0,0 +1,69 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_MAP_FWD_HPP
|
||||
#define MSGPACK_TYPE_MAP_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename K, typename V>
|
||||
class assoc_vector;
|
||||
|
||||
namespace detail {
|
||||
template <typename K, typename V>
|
||||
struct pair_first_less;
|
||||
} // namespace detail
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::assoc_vector<K,V>& v);
|
||||
template <typename Stream, typename K, typename V>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::assoc_vector<K,V>& v);
|
||||
template <typename K, typename V>
|
||||
void operator<< (msgpack::object::with_zone& o, const type::assoc_vector<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::map<K, V>& v);
|
||||
template <typename Stream, typename K, typename V>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::map<K,V>& v);
|
||||
template <typename K, typename V>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::multimap<K, V>& v);
|
||||
template <typename Stream, typename K, typename V>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::multimap<K,V>& v);
|
||||
template <typename K, typename V>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::multimap<K,V>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_MAP_HPP
|
29
include/msgpack/adaptor/msgpack_tuple.hpp
Normal file
29
include/msgpack/adaptor/msgpack_tuple.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_MSGPACK_TUPLE_HPP
|
||||
#define MSGPACK_MSGPACK_TUPLE_HPP
|
||||
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
#include "detail/cpp03_msgpack_tuple.hpp"
|
||||
#else // MSGPACK_USE_CPP03
|
||||
#include "detail/cpp11_msgpack_tuple.hpp"
|
||||
#endif // MSGPACK_USE_CPP03
|
||||
|
||||
#endif // MSGPACK_MSGPACK_TUPLE_HPP
|
29
include/msgpack/adaptor/msgpack_tuple_fwd.hpp
Normal file
29
include/msgpack/adaptor/msgpack_tuple_fwd.hpp
Normal file
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_MSGPACK_TUPLE_FWD_HPP
|
||||
#define MSGPACK_MSGPACK_TUPLE_FWD_HPP
|
||||
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
#include "detail/cpp03_msgpack_tuple_fwd.hpp"
|
||||
#else // MSGPACK_USE_CPP03
|
||||
#include "detail/cpp11_msgpack_tuple_fwd.hpp"
|
||||
#endif // MSGPACK_USE_CPP03
|
||||
|
||||
#endif // MSGPACK_MSGPACK_TUPLE_FWD_HPP
|
68
include/msgpack/adaptor/nil.hpp
Normal file
68
include/msgpack/adaptor/nil.hpp
Normal file
@@ -0,0 +1,68 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_NIL_HPP
|
||||
#define MSGPACK_TYPE_NIL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
struct nil { };
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, type::nil&)
|
||||
{
|
||||
if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); }
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::nil&)
|
||||
{
|
||||
o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, type::nil)
|
||||
{
|
||||
o.type = msgpack::type::NIL;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, type::nil v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
template <>
|
||||
inline void msgpack::object::as<void>() const
|
||||
{
|
||||
msgpack::type::nil v;
|
||||
convert(v);
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_NIL_HPP
|
51
include/msgpack/adaptor/nil_fwd.hpp
Normal file
51
include/msgpack/adaptor/nil_fwd.hpp
Normal file
@@ -0,0 +1,51 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_NIL_FWD_HPP
|
||||
#define MSGPACK_TYPE_NIL_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
struct nil;
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::nil&);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::nil&);
|
||||
|
||||
void operator<< (msgpack::object& o, type::nil);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, type::nil v);
|
||||
|
||||
template <>
|
||||
inline void msgpack::object::as<void>() const;
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_NIL_FWD_HPP
|
63
include/msgpack/adaptor/pair.hpp
Normal file
63
include/msgpack/adaptor/pair.hpp
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_PAIR_HPP
|
||||
#define MSGPACK_TYPE_PAIR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::pair<T1, T2>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != 2) { throw msgpack::type_error(); }
|
||||
o.via.array.ptr[0].convert(v.first);
|
||||
o.via.array.ptr[1].convert(v.second);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T1, typename T2>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::pair<T1, T2>& v)
|
||||
{
|
||||
o.pack_array(2);
|
||||
o.pack(v.first);
|
||||
o.pack(v.second);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::pair<T1, T2>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*2));
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = 2;
|
||||
p[0] = msgpack::object(v.first, o.zone);
|
||||
p[1] = msgpack::object(v.second, o.zone);
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_PAIR_HPP
|
@@ -15,47 +15,28 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_PAIR_HPP__
|
||||
#define MSGPACK_TYPE_PAIR_HPP__
|
||||
#ifndef MSGPACK_TYPE_PAIR_FWD_HPP
|
||||
#define MSGPACK_TYPE_PAIR_FWD_HPP
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline std::pair<T1, T2>& operator>> (object o, std::pair<T1, T2>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
if(o.via.array.size != 2) { throw type_error(); }
|
||||
o.via.array.ptr[0].convert(&v.first);
|
||||
o.via.array.ptr[1].convert(&v.second);
|
||||
return v;
|
||||
}
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::pair<T1, T2>& v);
|
||||
|
||||
template <typename Stream, typename T1, typename T2>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::pair<T1, T2>& v)
|
||||
{
|
||||
o.pack_array(2);
|
||||
o.pack(v.first);
|
||||
o.pack(v.second);
|
||||
return o;
|
||||
}
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::pair<T1, T2>& v);
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline void operator<< (object::with_zone& o, const std::pair<T1, T2>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
object* p = (object*)o.zone->malloc(sizeof(object)*2);
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = 2;
|
||||
p[0] = object(v.first, o.zone);
|
||||
p[1] = object(v.second, o.zone);
|
||||
}
|
||||
void operator<< (msgpack::object::with_zone& o, const std::pair<T1, T2>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/pair.hpp */
|
||||
|
||||
#endif // MSGPACK_TYPE_PAIR_FWD_HPP
|
98
include/msgpack/adaptor/raw.hpp
Normal file
98
include/msgpack/adaptor/raw.hpp
Normal file
@@ -0,0 +1,98 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_RAW_HPP
|
||||
#define MSGPACK_TYPE_RAW_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
struct raw_ref {
|
||||
raw_ref() : size(0), ptr(nullptr) {}
|
||||
raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {}
|
||||
|
||||
uint32_t size;
|
||||
const char* ptr;
|
||||
|
||||
std::string str() const { return std::string(ptr, size); }
|
||||
|
||||
bool operator== (const raw_ref& x) const
|
||||
{
|
||||
return size == x.size && std::memcmp(ptr, x.ptr, size) == 0;
|
||||
}
|
||||
|
||||
bool operator!= (const raw_ref& x) const
|
||||
{
|
||||
return !(*this != x);
|
||||
}
|
||||
|
||||
bool operator< (const raw_ref& x) const
|
||||
{
|
||||
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; }
|
||||
else { return size < x.size; }
|
||||
}
|
||||
|
||||
bool operator> (const raw_ref& x) const
|
||||
{
|
||||
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; }
|
||||
else { return size > x.size; }
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, msgpack::type::raw_ref& v)
|
||||
{
|
||||
if(o.type != msgpack::type::BIN) { throw msgpack::type_error(); }
|
||||
v.ptr = o.via.bin.ptr;
|
||||
v.size = o.via.bin.size;
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const msgpack::type::raw_ref& v)
|
||||
{
|
||||
o.pack_bin(v.size);
|
||||
o.pack_bin_body(v.ptr, v.size);
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, const msgpack::type::raw_ref& v)
|
||||
{
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = v.ptr;
|
||||
o.via.bin.size = v.size;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, const msgpack::type::raw_ref& v)
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_RAW_HPP
|
@@ -15,51 +15,36 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_NIL_HPP__
|
||||
#define MSGPACK_TYPE_NIL_HPP__
|
||||
#ifndef MSGPACK_TYPE_RAW_FWD_HPP
|
||||
#define MSGPACK_TYPE_RAW_FWD_HPP
|
||||
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
namespace type {
|
||||
|
||||
struct nil { };
|
||||
struct raw_ref;
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
inline type::nil& operator>> (object o, type::nil& v)
|
||||
{
|
||||
if(o.type != type::NIL) { throw type_error(); }
|
||||
return v;
|
||||
}
|
||||
msgpack::object const& operator>> (msgpack::object const& o, type::raw_ref& v);
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::nil& v)
|
||||
{
|
||||
o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const type::raw_ref& v);
|
||||
|
||||
inline void operator<< (object& o, type::nil v)
|
||||
{
|
||||
o.type = type::NIL;
|
||||
}
|
||||
void operator<< (msgpack::object& o, const type::raw_ref& v);
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::nil v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
template <>
|
||||
inline void object::as<void>() const
|
||||
{
|
||||
msgpack::type::nil v;
|
||||
convert(&v);
|
||||
}
|
||||
void operator<< (msgpack::object::with_zone& o, const type::raw_ref& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif /* msgpack/type/nil.hpp */
|
||||
|
||||
#endif // MSGPACK_TYPE_RAW_FWD_HPP
|
134
include/msgpack/adaptor/set.hpp
Normal file
134
include/msgpack/adaptor/set.hpp
Normal file
@@ -0,0 +1,134 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_SET_HPP
|
||||
#define MSGPACK_TYPE_SET_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::set<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::set<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::set<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::set<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::set<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::set<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::multiset<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
std::multiset<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::multiset<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::multiset<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::multiset<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::multiset<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_SET_HPP
|
52
include/msgpack/adaptor/set_fwd.hpp
Normal file
52
include/msgpack/adaptor/set_fwd.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_SET_FWD_HPP
|
||||
#define MSGPACK_TYPE_SET_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::set<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::multiset<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::multiset<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const std::multiset<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_SET_FWD_HPP
|
78
include/msgpack/adaptor/string.hpp
Normal file
78
include/msgpack/adaptor/string.hpp
Normal file
@@ -0,0 +1,78 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_STRING_HPP
|
||||
#define MSGPACK_TYPE_STRING_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::string& v)
|
||||
{
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
v.assign(o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
v.assign(o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::string& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v.data(), size);
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::string& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = size;
|
||||
std::memcpy(ptr, v.data(), v.size());
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, const std::string& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::STR;
|
||||
o.via.str.ptr = v.data();
|
||||
o.via.str.size = size;
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_STRING_HPP
|
42
include/msgpack/adaptor/string_fwd.hpp
Normal file
42
include/msgpack/adaptor/string_fwd.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_STRING_FWD_HPP
|
||||
#define MSGPACK_TYPE_STRING_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::string& v);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::string& v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, const std::string& v);
|
||||
|
||||
void operator<< (msgpack::object& o, const std::string& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_STRING_FWD_HPP
|
164
include/msgpack/adaptor/tr1/unordered_map.hpp
Normal file
164
include/msgpack/adaptor/tr1/unordered_map.hpp
Normal file
@@ -0,0 +1,164 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP
|
||||
#define MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#define MSGPACK_HAS_STD_UNORDERED_MAP
|
||||
#include <unordered_map>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNORDERED_MAP
|
||||
|
||||
#include <tr1/unordered_map>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if defined(MSGPACK_STD_TR1)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename K, typename V>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_map<K, V>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
MSGPACK_STD_TR1::unordered_map<K, V> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
K key;
|
||||
p->key.convert(key);
|
||||
p->val.convert(tmp[key]);
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v)
|
||||
{
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_multimap<K, V>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); }
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
MSGPACK_STD_TR1::unordered_multimap<K, V> tmp;
|
||||
for(; p != pend; ++p) {
|
||||
std::pair<K, V> value;
|
||||
p->key.convert(value.first);
|
||||
p->val.convert(value.second);
|
||||
tmp.insert(value);
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_map(size);
|
||||
for(typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v)
|
||||
{
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object_kv* p = static_cast<msgpack::object_kv*>(o.zone.allocate_align(sizeof(msgpack::object_kv)*size));
|
||||
msgpack::object_kv* const pend = p + size;
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = size;
|
||||
typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = msgpack::object(it->first, o.zone);
|
||||
p->val = msgpack::object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#undef MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP
|
75
include/msgpack/adaptor/tr1/unordered_map_fwd.hpp
Normal file
75
include/msgpack/adaptor/tr1/unordered_map_fwd.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_TR1_UNORDERED_MAP_FWD_HPP
|
||||
#define MSGPACK_TYPE_TR1_UNORDERED_MAP_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#define MSGPACK_HAS_STD_UNORDERED_MAP
|
||||
#include <unordered_map>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNORDERED_MAP
|
||||
|
||||
#include <tr1/unordered_map>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if defined(MSGPACK_STD_TR1)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename K, typename V>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_map<K, V>& v);
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_multimap<K, V>& v);
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#undef MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_TYPE_TR1_UNORDERED_MAP_FWD_HPP
|
157
include/msgpack/adaptor/tr1/unordered_set.hpp
Normal file
157
include/msgpack/adaptor/tr1/unordered_set.hpp
Normal file
@@ -0,0 +1,157 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2015 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_TR1_UNORDERED_SET_HPP
|
||||
#define MSGPACK_TYPE_TR1_UNORDERED_SET_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#define MSGPACK_HAS_STD_UNORDERED_SET
|
||||
#include <unordered_set>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNORDERED_SET
|
||||
|
||||
#include <tr1/unordered_set>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if defined(MSGPACK_STD_TR1)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_set<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
MSGPACK_STD_TR1::unordered_set<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_multiset<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
msgpack::object* p = o.via.array.ptr + o.via.array.size;
|
||||
msgpack::object* const pbegin = o.via.array.ptr;
|
||||
MSGPACK_STD_TR1::unordered_multiset<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#undef MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_TYPE_TR1_UNORDERED_SET_HPP
|
75
include/msgpack/adaptor/tr1/unordered_set_fwd.hpp
Normal file
75
include/msgpack/adaptor/tr1/unordered_set_fwd.hpp
Normal file
@@ -0,0 +1,75 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_TR1_UNORDERED_SET_FWD_HPP
|
||||
#define MSGPACK_TYPE_TR1_UNORDERED_SET_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#define MSGPACK_HAS_STD_UNORDERED_SET
|
||||
#include <unordered_set>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNORDERED_SET
|
||||
|
||||
#include <tr1/unordered_set>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if defined(MSGPACK_STD_TR1)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_set<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
msgpack::object const& operator>> (msgpack::object const& o, MSGPACK_STD_TR1::unordered_multiset<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#undef MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_TYPE_TR1_UNORDERED_SET_FWD_HPP
|
87
include/msgpack/adaptor/vector.hpp
Normal file
87
include/msgpack/adaptor/vector.hpp
Normal file
@@ -0,0 +1,87 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_VECTOR_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::vector<T>& v)
|
||||
{
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
v.resize(o.via.array.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;
|
||||
T* it = &v[0];
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::vector<T>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::vector<T>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*size));
|
||||
msgpack::object* const pend = p + size;
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = size;
|
||||
typename std::vector<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_HPP
|
80
include/msgpack/adaptor/vector_bool.hpp
Normal file
80
include/msgpack/adaptor/vector_bool.hpp
Normal file
@@ -0,0 +1,80 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_VECTOR_BOOL_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_BOOL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::vector<bool>& v)
|
||||
{
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size > 0) {
|
||||
v.resize(o.via.array.size);
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
for (std::vector<bool>::iterator it = v.begin(), end = v.end();
|
||||
it != end;
|
||||
++it) {
|
||||
*it = p->as<bool>();
|
||||
++p;
|
||||
}
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::vector<bool>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(std::vector<bool>::const_iterator it(v.begin()), it_end(v.end());
|
||||
it != it_end; ++it) {
|
||||
o.pack(static_cast<bool>(*it));
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::vector<bool>& v)
|
||||
{
|
||||
o.type = msgpack::type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
msgpack::object* p = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object)*v.size()));
|
||||
msgpack::object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
std::vector<bool>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(static_cast<bool>(*it), o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_BOOL_HPP
|
40
include/msgpack/adaptor/vector_bool_fwd.hpp
Normal file
40
include/msgpack/adaptor/vector_bool_fwd.hpp
Normal file
@@ -0,0 +1,40 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_VECTOR_BOOL_FWD_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_BOOL_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
object const& operator>> (object const& o, std::vector<bool>& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::vector<bool>& v);
|
||||
|
||||
void operator<< (object::with_zone& o, const std::vector<bool>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_BOOL_FWD_HPP
|
81
include/msgpack/adaptor/vector_char.hpp
Normal file
81
include/msgpack/adaptor/vector_char.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014-2015 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_VECTOR_CHAR_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
inline msgpack::object const& operator>> (msgpack::object const& o, std::vector<char>& v)
|
||||
{
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
v.resize(o.via.bin.size);
|
||||
std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
v.resize(o.via.str.size);
|
||||
std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
break;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::vector<char>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(&v.front(), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object& o, const std::vector<char>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = &v.front();
|
||||
o.via.bin.size = size;
|
||||
}
|
||||
|
||||
inline void operator<< (msgpack::object::with_zone& o, const std::vector<char>& v)
|
||||
{
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.type = msgpack::type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = size;
|
||||
std::memcpy(ptr, &v.front(), size);
|
||||
}
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_CHAR_HPP
|
42
include/msgpack/adaptor/vector_char_fwd.hpp
Normal file
42
include/msgpack/adaptor/vector_char_fwd.hpp
Normal file
@@ -0,0 +1,42 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
//
|
||||
#ifndef MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
msgpack::object const& operator>> (msgpack::object const& o, std::vector<char>& v);
|
||||
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const std::vector<char>& v);
|
||||
|
||||
void operator<< (msgpack::object& o, const std::vector<char>& v);
|
||||
|
||||
void operator<< (msgpack::object::with_zone& o, const std::vector<char>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user