mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-20 22:31:33 +02:00
Compare commits
183 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
a277ea7c64 | ||
![]() |
285ccfeeea | ||
![]() |
232b8039a0 | ||
![]() |
10a315e00e | ||
![]() |
904dd65965 | ||
![]() |
dff7af2075 | ||
![]() |
ed91c18af8 | ||
![]() |
616b1d8fb0 | ||
![]() |
ce98964348 | ||
![]() |
07a509a53a | ||
![]() |
35483b95ae | ||
![]() |
a2c8154960 | ||
![]() |
e8d3c8d6c5 | ||
![]() |
ae5734e8d1 | ||
![]() |
6ec09053b1 | ||
![]() |
5401660b07 | ||
![]() |
f3caa8e160 | ||
![]() |
8921f9dcfc | ||
![]() |
1911513acb | ||
![]() |
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 | ||
![]() |
bf4a57da34 | ||
![]() |
2fcbe6116d | ||
![]() |
0176dd760a | ||
![]() |
d30548af3f | ||
![]() |
ab12b2b2b9 | ||
![]() |
7ce69a362f | ||
![]() |
cc08146b1c | ||
![]() |
6896cc602f | ||
![]() |
d8f366daf2 | ||
![]() |
ef649009e4 | ||
![]() |
847a7852e5 | ||
![]() |
e265beef91 | ||
![]() |
dc679a2572 | ||
![]() |
b6bc7f7ecb | ||
![]() |
501260eb54 | ||
![]() |
8615358515 | ||
![]() |
dd083ca933 | ||
![]() |
c203928fae |
2
.gitignore
vendored
2
.gitignore
vendored
@@ -1,5 +1,7 @@
|
||||
# Files generated by the bootstrap script.
|
||||
/INSTALL
|
||||
/AUTHORS
|
||||
/ChangeLog
|
||||
/NEWS
|
||||
/README
|
||||
/ac/
|
||||
|
119
CHANGELOG.md
Normal file
119
CHANGELOG.md
Normal file
@@ -0,0 +1,119 @@
|
||||
2015-04-03 version 1.1.0
|
||||
<< breaking change >>
|
||||
* Remove msgpack_fwd.hpp
|
||||
* Improve user types adaptation mechanism (#262)
|
||||
Since version 1.0.0, users need to obey the correct include order.
|
||||
However, it is very difficult to maintain the correct order in big
|
||||
projects. version 1.1.0 removed this order. Users don't need to
|
||||
care about include order. Migration guide from 1.0.x to 1.1.0 has
|
||||
been written. See https://github.com/msgpack/msgpack-c/wiki
|
||||
|
||||
* Fix vector<bool> size check (#251)
|
||||
* Fix inttypes.h inclusion on MSVC (#257)
|
||||
* Support documents generation by Doxygen (#259)
|
||||
* Remove C99 style variable declaration (#253)
|
||||
* Improve documents (https://github.com/msgpack/msgpack-c/wiki)
|
||||
2015-03-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)
|
||||
* Remove some warnings (#56)
|
||||
* Fix segmentation fault after malloc failures (#58, #59)
|
||||
* Fix alloc/dealloc mismatch (#52, #61)
|
||||
* Fix sample codes (#60, #64)
|
||||
* Support implicit conversion from integer to float/double (#54)
|
||||
* Improve documents (#45, #75, #82, #83)
|
||||
* Support CMake (#20, #87)
|
||||
* Remove Ruby dependencies in bootstrap (#86, #87)
|
||||
* Add FILE* buffer (#40)
|
||||
* Other bug fixes and refactoring: #39, #73, #77, #79, #80, #81, #84, #90
|
||||
|
||||
2013-12-23 version 0.5.8:
|
||||
|
||||
* Move to the new github repository msgpack/msgpack-c
|
||||
* Support the new deserialization specification
|
||||
* fixes the problem of unpack helpers for array and map with 32bit compilers (#37, #38)
|
||||
* Other bug fixes and refactoring: #46, #41, #36, #35, #33, #32, #30, #29, #28, #27, #26, #25, #8, #3
|
||||
* Update of documents: #23, #18, #17
|
||||
|
||||
2011-08-08 version 0.5.7:
|
||||
|
||||
* fixes compile error problem with llvm-gcc and Mac OS X Lion
|
||||
|
||||
2011-04-24 version 0.5.6:
|
||||
|
||||
* #42 fixes double-free problem on msgpack_unpacker_release_zone
|
||||
|
||||
2011-02-24 version 0.5.5:
|
||||
|
||||
* eliminates dependency of winsock2.h header
|
||||
* fixes msgpack_vc.postbuild.bat file
|
||||
* fixes some implicit cast warnings
|
||||
|
||||
2010-08-29 version 0.5.4:
|
||||
|
||||
* includes msgpack_vc2008.vcproj file in source package
|
||||
* fixes type::fix_int types
|
||||
|
||||
2010-08-27 version 0.5.3:
|
||||
|
||||
* adds type::fix_{u,}int{8,16,32,64} types
|
||||
* adds msgpack_pack_fix_{u,}int{8,16,32,64} functions
|
||||
* adds packer<Stream>::pack_fix_{u,}int{8,16,32,64} functions
|
||||
* fixes include paths
|
||||
|
||||
2010-07-14 version 0.5.2:
|
||||
|
||||
* type::raw::str(), operator==, operator!=, operator< and operator> are now const
|
||||
* generates version.h using AC_OUTPUT macro in ./configure
|
||||
|
||||
2010-07-06 version 0.5.1:
|
||||
|
||||
* Add msgpack_vrefbuffer_new and msgpack_vrefbuffer_free
|
||||
* Add msgpack_sbuffer_new and msgpack_sbuffer_free
|
||||
* Add msgpack_unpacker_next and msgpack_unpack_next
|
||||
* msgpack::unpack returns void
|
||||
* Add MSGPACK_VERSION{,_MAJOR,_MINOR} macros to check header version
|
||||
* Add msgpack_version{,_major,_minor} functions to check library version
|
||||
* ./configure supports --disable-cxx option not to build C++ API
|
||||
|
||||
2010-04-29 version 0.5.0:
|
||||
|
||||
* msgpack_object_type is changed. MSGPACK_OBJECT_NIL is now 0x00.
|
||||
* New safe streaming deserializer API.
|
||||
* Add object::object(const T&) and object::operator=(const T&)
|
||||
* Add operator==(object, const T&)
|
||||
* MSGPACK_DEFINE macro defines msgpack_object(object* obj, zone* z)
|
||||
* C++ programs doesn't need to link "msgpackc" library.
|
||||
|
@@ -1,7 +1,7 @@
|
||||
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.6)
|
||||
PROJECT (msgpack)
|
||||
|
||||
FILE (READ ${CMAKE_SOURCE_DIR}/include/msgpack/version_master.h contents)
|
||||
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})
|
||||
@@ -83,6 +83,7 @@ LIST (APPEND msgpack_HEADERS
|
||||
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
|
||||
@@ -97,58 +98,38 @@ LIST (APPEND msgpack_HEADERS
|
||||
IF (MSGPACK_ENABLE_CXX)
|
||||
LIST (APPEND msgpack_HEADERS
|
||||
include/msgpack.hpp
|
||||
include/msgpack_fwd.hpp
|
||||
include/msgpack/adaptor/adaptor_base.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_set.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_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
|
||||
@@ -211,12 +192,16 @@ IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" ST
|
||||
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}")
|
||||
STRING(REGEX REPLACE "/W[0-4]" "/W3" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
|
||||
ELSE ()
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
|
||||
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W3")
|
||||
ENDIF ()
|
||||
ENDIF ()
|
||||
|
||||
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 ()
|
||||
@@ -233,6 +218,8 @@ IF (DOXYGEN_FOUND)
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.h" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_c" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "EXTRACT_ALL = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
|
||||
VERBATIM
|
||||
@@ -242,6 +229,8 @@ IF (DOXYGEN_FOUND)
|
||||
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.hpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_cpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "EXTRACT_ALL = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C++\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
|
||||
VERBATIM
|
||||
|
72
ChangeLog
72
ChangeLog
@@ -1,72 +0,0 @@
|
||||
2014-07-02 version 0.5.9:
|
||||
|
||||
* Support std::tr1 unordered containers by default (#51, #63, #68, #69)
|
||||
* Remove some warnings (#56)
|
||||
* Fix segmentation fault after malloc failures (#58, #59)
|
||||
* Fix alloc/dealloc mismatch (#52, #61)
|
||||
* Fix sample codes (#60, #64)
|
||||
* Support implicit conversion from integer to float/double (#54)
|
||||
* Improve documents (#45, #75, #82, #83)
|
||||
* Support CMake (#20, #87)
|
||||
* Remove Ruby dependencies in bootstrap (#86, #87)
|
||||
* Add FILE* buffer (#40)
|
||||
* Other bug fixes and refactoring: #39, #73, #77, #79, #80, #81, #84, #90
|
||||
|
||||
2013-12-23 version 0.5.8:
|
||||
|
||||
* Move to the new github repository msgpack/msgpack-c
|
||||
* Support the new deserialization specification
|
||||
* fixes the problem of unpack helpers for array and map with 32bit compilers (#37, #38)
|
||||
* Other bug fixes and refactoring: #46, #41, #36, #35, #33, #32, #30, #29, #28, #27, #26, #25, #8, #3
|
||||
* Update of documents: #23, #18, #17
|
||||
|
||||
2011-08-08 version 0.5.7:
|
||||
|
||||
* fixes compile error problem with llvm-gcc and Mac OS X Lion
|
||||
|
||||
2011-04-24 version 0.5.6:
|
||||
|
||||
* #42 fixes double-free problem on msgpack_unpacker_release_zone
|
||||
|
||||
2011-02-24 version 0.5.5:
|
||||
|
||||
* eliminates dependency of winsock2.h header
|
||||
* fixes msgpack_vc.postbuild.bat file
|
||||
* fixes some implicit cast warnings
|
||||
|
||||
2010-08-29 version 0.5.4:
|
||||
|
||||
* includes msgpack_vc2008.vcproj file in source package
|
||||
* fixes type::fix_int types
|
||||
|
||||
2010-08-27 version 0.5.3:
|
||||
|
||||
* adds type::fix_{u,}int{8,16,32,64} types
|
||||
* adds msgpack_pack_fix_{u,}int{8,16,32,64} functions
|
||||
* adds packer<Stream>::pack_fix_{u,}int{8,16,32,64} functions
|
||||
* fixes include paths
|
||||
|
||||
2010-07-14 version 0.5.2:
|
||||
|
||||
* type::raw::str(), operator==, operator!=, operator< and operator> are now const
|
||||
* generates version.h using AC_OUTPUT macro in ./configure
|
||||
|
||||
2010-07-06 version 0.5.1:
|
||||
|
||||
* Add msgpack_vrefbuffer_new and msgpack_vrefbuffer_free
|
||||
* Add msgpack_sbuffer_new and msgpack_sbuffer_free
|
||||
* Add msgpack_unpacker_next and msgpack_unpack_next
|
||||
* msgpack::unpack returns void
|
||||
* Add MSGPACK_VERSION{,_MAJOR,_MINOR} macros to check header version
|
||||
* Add msgpack_version{,_major,_minor} functions to check library version
|
||||
* ./configure supports --disable-cxx option not to build C++ API
|
||||
|
||||
2010-04-29 version 0.5.0:
|
||||
|
||||
* msgpack_object_type is changed. MSGPACK_OBJECT_NIL is now 0x00.
|
||||
* New safe streaming deserializer API.
|
||||
* Add object::object(const T&) and object::operator=(const T&)
|
||||
* Add operator==(object, const T&)
|
||||
* MSGPACK_DEFINE macro defines msgpack_object(object* obj, zone* z)
|
||||
* C++ programs doesn't need to link "msgpackc" library.
|
||||
|
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
|
||||
|
||||
|
231
README.md
231
README.md
@@ -1,71 +1,163 @@
|
||||
# Msgpack for C/C++
|
||||
`msgpack` for C/C++
|
||||
===================
|
||||
|
||||
Version 1.1.0 [](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-2014 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);
|
||||
|
||||
## Version
|
||||
0.6.0 [](https://travis-ci.org/msgpack/msgpack-c)
|
||||
/* print the deserialized object. */
|
||||
msgpack_object_print(stdout, deserialized);
|
||||
puts("");
|
||||
|
||||
## Using Msgpack
|
||||
msgpack_zone_destroy(&mempool);
|
||||
msgpack_sbuffer_destroy(&sbuf);
|
||||
|
||||
### Header only library for C++
|
||||
When you use msgpack on C++03 and C++11, you just add msgpack-c/include to your include path. You don't need to link any msgpack libraries.
|
||||
return 0;
|
||||
}
|
||||
```
|
||||
|
||||
e.g.)
|
||||
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 C and C++ version of msgpack.
|
||||
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.
|
||||
|
||||
For C:
|
||||
C++03 and C:
|
||||
You will need:
|
||||
|
||||
$ git clone https://github.com/redboltz/msgpack-c/tree/cxx_separate
|
||||
$ cd msgpack-c
|
||||
$ ./bootstrap
|
||||
$ ./configure
|
||||
$ make
|
||||
$ sudo make install
|
||||
- `gcc >= 4.1.0` or `clang >= 3.3.0`
|
||||
- `autoconf >= 2.60`
|
||||
- `automake >= 1.10`
|
||||
- `libtool >= 2.2.4`
|
||||
|
||||
For C++11:
|
||||
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.
|
||||
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
$ ./bootstrap
|
||||
$ ./configure CXXFLAGS="-std=c++11"
|
||||
$ make
|
||||
$ sudo make install
|
||||
```bash
|
||||
$ git clone https://github.com/msgpack/msgpack-c
|
||||
$ cd msgpack-c
|
||||
$ ./bootstrap
|
||||
$ ./configure
|
||||
$ make
|
||||
```
|
||||
|
||||
You need the compiler that fully supports C++11.
|
||||
You can install the resulting library like this:
|
||||
|
||||
```bash
|
||||
$ sudo make install
|
||||
```
|
||||
##### Using cmake
|
||||
|
||||
###### CUI
|
||||
###### Using the Terminal (CLI)
|
||||
|
||||
You will need gcc (4.1.0 or higher), cmake.
|
||||
You will need:
|
||||
|
||||
- `gcc >= 4.1.0`
|
||||
- `cmake >= 2.8.0`
|
||||
|
||||
C and C++03:
|
||||
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
@@ -73,15 +165,14 @@ You will need gcc (4.1.0 or higher), cmake.
|
||||
$ make
|
||||
$ sudo make install
|
||||
|
||||
If you want to setup C++11 version of msgpack, execute the following command:
|
||||
If you want to setup C++11 version of msgpack instead,
|
||||
execute the following commands:
|
||||
|
||||
$ git clone https://github.com/msgpack/msgpack-c.git
|
||||
$ cd msgpack-c
|
||||
$ cmake -DMSGPACK_CXX11=ON .
|
||||
$ sudo make install
|
||||
|
||||
You need the compiler that fully supports C++11.
|
||||
|
||||
##### GUI on Windows
|
||||
|
||||
Clone msgpack-c git repository.
|
||||
@@ -92,61 +183,37 @@ or using GUI git client.
|
||||
|
||||
e.g.) tortoise git https://code.google.com/p/tortoisegit/
|
||||
|
||||
1. 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).
|
||||
|
||||
1. 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.
|
||||
|
||||
1. Click 'Configure' button.
|
||||
3. Click 'Configure' button.
|
||||
|
||||
1. Choose your Visual Studio version.
|
||||
4. Choose your Visual Studio version.
|
||||
|
||||
1. Click 'Generate' button.
|
||||
5. Click 'Generate' button.
|
||||
|
||||
1. Open the created msgpack.sln on Visual Studio.
|
||||
6. Open the created msgpack.sln on Visual Studio.
|
||||
|
||||
1. Build all.
|
||||
7. Build all.
|
||||
|
||||
### Documentation
|
||||
|
||||
#### Install from package
|
||||
You can get addtional information on the
|
||||
[wiki](https://github.com/msgpack/msgpack-c/wiki).
|
||||
|
||||
Install from package for this branch (poc/0.6) is not supported yet.
|
||||
Contributing
|
||||
------------
|
||||
|
||||
### Code Example
|
||||
`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).
|
||||
|
||||
#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!");
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
### Documents
|
||||
|
||||
You can get addtional information on the wiki:
|
||||
|
||||
https://github.com/msgpack/msgpack-c/wiki/cpp_overview
|
||||
License
|
||||
-------
|
||||
|
||||
`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"
|
||||
|
@@ -80,5 +80,4 @@ then
|
||||
fi
|
||||
fi
|
||||
|
||||
|
||||
exit 0
|
||||
|
@@ -1,4 +1,4 @@
|
||||
AC_INIT(msgpack, m4_esyscmd([cat include/msgpack/version_master.h | tr -d "\n" | sed -e 's/#define MSGPACK_VERSION_MAJOR\s*\(\w*\)/\1./g' -e 's/#define MSGPACK_VERSION_MINOR\s*\(\w*\)/\1./g' -e 's/#define MSGPACK_VERSION_REVISION\s*\(\w*\)/\1/g']))
|
||||
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
|
||||
AC_CONFIG_HEADER(config.h)
|
||||
|
@@ -19,7 +19,8 @@
|
||||
#define MSGPACK_CPP03_DEFINE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple_fwd.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
#define MSGPACK_DEFINE(...) \
|
||||
@@ -39,42 +40,57 @@
|
||||
}
|
||||
|
||||
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||
#define MSGPACK_ADD_ENUM(enum) \
|
||||
#define MSGPACK_ADD_ENUM(enum_name) \
|
||||
namespace msgpack { \
|
||||
/** @cond */ \
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) { \
|
||||
template <> \
|
||||
inline object const& operator>> (object const& o, enum& v) \
|
||||
{ \
|
||||
int tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
template <> \
|
||||
inline void operator<< (object::with_zone& o, const enum& v) \
|
||||
{ \
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
namespace detail { \
|
||||
/** @endcond */ \
|
||||
namespace adaptor { \
|
||||
template<> \
|
||||
struct convert<enum_name> { \
|
||||
msgpack::object const& operator()(msgpack::object const& o, enum_name& v) const {\
|
||||
int tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum_name>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object<enum_name> { \
|
||||
void operator()(msgpack::object& o, const enum_name& v) const {\
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object_with_zone<enum_name> { \
|
||||
void operator()(msgpack::object::with_zone& o, const enum_name& v) const { \
|
||||
o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct pack<enum_name> { \
|
||||
template <typename Stream> \
|
||||
struct packer_serializer<Stream, enum> { \
|
||||
static packer<Stream>& pack(packer<Stream>& o, const enum& v) { \
|
||||
return o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const enum_name& v) const { \
|
||||
return o << static_cast<int>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
/** @cond */ \
|
||||
} \
|
||||
/** @endcond */ \
|
||||
}
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
namespace type {
|
||||
|
||||
|
||||
/// @cond
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct define;
|
||||
|
||||
/// @endcond
|
||||
|
||||
template <>
|
||||
struct define<> {
|
||||
@@ -87,15 +103,17 @@ struct define<> {
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||
{
|
||||
o->type = type::ARRAY;
|
||||
o->type = msgpack::type::ARRAY;
|
||||
o->via.array.ptr = nullptr;
|
||||
o->via.array.size = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
@@ -112,7 +130,7 @@ struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
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;
|
||||
@@ -124,21 +142,24 @@ struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
|
||||
{
|
||||
o->type = type::ARRAY;
|
||||
o->via.array.ptr = static_cast<object*>(z.allocate_align(sizeof(object)*<%=i+1%>));
|
||||
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%>] = object(a<%=j%>, z);<%}%>
|
||||
o->via.array.ptr[<%=j%>] = msgpack::object(a<%=j%>, z);<%}%>
|
||||
}
|
||||
<%0.upto(i) {|j|%>
|
||||
A<%=j%>& a<%=j%>;<%}%>
|
||||
};
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
inline define<> make_define()
|
||||
{
|
||||
return define<>();
|
||||
}
|
||||
|
||||
/// @cond
|
||||
<%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%><%}%>)
|
||||
@@ -146,9 +167,12 @@ define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define(A0& a0<%1.upto(i) {|j|%>,
|
||||
return define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
|
||||
}
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
} // namespace type
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
|
@@ -20,10 +20,13 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
@@ -31,8 +34,10 @@ namespace type {
|
||||
// FIXME operator!=
|
||||
<% GENERATION_LIMIT = 31 %>
|
||||
|
||||
template <typename A0<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%><%}%>>
|
||||
/// @cond
|
||||
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
|
||||
struct tuple;
|
||||
/// @endcond
|
||||
|
||||
template <typename Tuple, int N>
|
||||
struct tuple_element;
|
||||
@@ -67,6 +72,7 @@ struct tuple_type<const T&> {
|
||||
typedef const T& transparent_reference;
|
||||
};
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
<%0.upto(i) {|j|%>
|
||||
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
|
||||
@@ -91,13 +97,16 @@ private:
|
||||
};
|
||||
<%}%>
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
template <>
|
||||
struct tuple<> {
|
||||
tuple() {}
|
||||
tuple(object const& o) { o.convert(*this); }
|
||||
tuple(msgpack::object const& o) { o.convert(*this); }
|
||||
typedef tuple<> value_type;
|
||||
};
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
@@ -105,7 +114,7 @@ struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
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(object const& o) { o.convert(*this); }
|
||||
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
|
||||
@@ -121,11 +130,14 @@ 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>(); }
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
inline tuple<> make_tuple()
|
||||
{
|
||||
return tuple<>();
|
||||
}
|
||||
|
||||
/// @cond
|
||||
<%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%><%}%>)
|
||||
@@ -133,84 +145,102 @@ inline tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<
|
||||
return tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
|
||||
}
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
} // namespace type
|
||||
|
||||
inline object const& operator>> (
|
||||
object const& o,
|
||||
type::tuple<>&) {
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
return o;
|
||||
}
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<type::tuple<> > {
|
||||
msgpack::object const& operator()(
|
||||
msgpack::object const& o,
|
||||
type::tuple<>&) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline object const& operator>> (
|
||||
object const& o,
|
||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
if(o.via.array.size < <%=i+1%>) { throw 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;
|
||||
}
|
||||
struct convert<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> > {
|
||||
msgpack::object const& operator()(
|
||||
msgpack::object const& o,
|
||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) const {
|
||||
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|%>
|
||||
// In order to avoid clang++'s invalid warning, msgpack::object:: has been added.
|
||||
o.via.array.ptr[<%=j%>].msgpack::object::convert<typename type::tuple_type<A<%=j%>>::type>(v.template get<<%=j%>>());<%}%>
|
||||
return o;
|
||||
}
|
||||
};
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
template <typename Stream>
|
||||
inline const packer<Stream>& operator<< (
|
||||
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 packer<Stream>& operator<< (
|
||||
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;
|
||||
}
|
||||
<%}%>
|
||||
template <>
|
||||
struct pack<type::tuple<> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<>&) const {
|
||||
o.pack_array(0);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (
|
||||
object::with_zone& o,
|
||||
const type::tuple<>&) {
|
||||
o.type = type::ARRAY;
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
inline void operator<< (
|
||||
object::with_zone& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
|
||||
o.type = type::ARRAY;
|
||||
o.via.array.ptr = static_cast<object*>(o.zone.allocate_align(sizeof(object)*<%=i+1%>));
|
||||
o.via.array.size = <%=i+1%>;
|
||||
<%0.upto(i) {|j|%>
|
||||
o.via.array.ptr[<%=j%>] = object(v.template get<<%=j%>>(), o.zone);<%}%>
|
||||
}
|
||||
struct pack<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) const {
|
||||
o.pack_array(<%=i+1%>);
|
||||
<%0.upto(i) {|j|%>
|
||||
o.pack(v.template get<<%=j%>>());<%}%>
|
||||
return o;
|
||||
}
|
||||
};
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::tuple<> > {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
const type::tuple<>&) const {
|
||||
o.type = msgpack::type::ARRAY;
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
}
|
||||
};
|
||||
|
||||
/// @cond
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct object_with_zone<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> > {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) const {
|
||||
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);<%}%>
|
||||
}
|
||||
};
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // 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
|
||||
|
@@ -1,125 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
object const& operator>> (
|
||||
object const& o,
|
||||
type::tuple<>&);
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
object const& operator>> (
|
||||
object const& o,
|
||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v);
|
||||
<%}%>
|
||||
|
||||
template <typename Stream>
|
||||
const packer<Stream>& operator<< (
|
||||
packer<Stream>& o,
|
||||
const type::tuple<>&);
|
||||
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename Stream, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
const packer<Stream>& operator<< (
|
||||
packer<Stream>& o,
|
||||
const type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v);
|
||||
<%}%>
|
||||
|
||||
void operator<< (
|
||||
object::with_zone& o,
|
||||
const type::tuple<>&);
|
||||
<%0.upto(GENERATION_LIMIT) {|i|%>
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
void operator<< (
|
||||
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
|
@@ -29,13 +29,15 @@
|
||||
#endif
|
||||
|
||||
#ifndef MSGPACK_ZONE_ALIGN
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(int)
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(void*)
|
||||
#endif
|
||||
|
||||
<% GENERATION_LIMIT = 15 %>
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
class zone {
|
||||
struct finalizer {
|
||||
@@ -150,7 +152,7 @@ public:
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
|
||||
|
||||
public:
|
||||
void* allocate_align(size_t size);
|
||||
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);
|
||||
@@ -161,28 +163,30 @@ public:
|
||||
void clear();
|
||||
|
||||
void swap(zone& o);
|
||||
static void* operator new(std::size_t size) throw(std::bad_alloc)
|
||||
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()
|
||||
static void operator delete(void *p) /* throw() */
|
||||
{
|
||||
::free(p);
|
||||
}
|
||||
static void* operator new(std::size_t size, void* place) throw()
|
||||
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()
|
||||
static void operator delete(void* p, void* place) /* throw() */
|
||||
{
|
||||
::operator delete(p, place);
|
||||
}
|
||||
/// @cond
|
||||
<%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(', ')%>);
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
private:
|
||||
void undo_allocate(size_t size);
|
||||
@@ -194,16 +198,30 @@ private:
|
||||
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)
|
||||
inline void* zone::allocate_align(size_t size, size_t align)
|
||||
{
|
||||
return allocate_no_align(
|
||||
((size)+((MSGPACK_ZONE_ALIGN)-1)) & ~((MSGPACK_ZONE_ALIGN)-1));
|
||||
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)
|
||||
@@ -226,7 +244,12 @@ inline void* zone::allocate_expand(size_t size)
|
||||
size_t sz = m_chunk_size;
|
||||
|
||||
while(sz < size) {
|
||||
sz *= 2;
|
||||
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));
|
||||
@@ -261,7 +284,10 @@ inline void zone::clear()
|
||||
|
||||
inline void zone::swap(zone& o)
|
||||
{
|
||||
std::swap(*this, 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>
|
||||
@@ -282,6 +308,7 @@ inline void zone::undo_allocate(size_t size)
|
||||
m_chunk_list.m_free += size;
|
||||
}
|
||||
|
||||
/// @cond
|
||||
<%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(', ')%>)
|
||||
@@ -302,8 +329,11 @@ T* zone::allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>)
|
||||
}
|
||||
}
|
||||
<%}%>
|
||||
/// @endcond
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -8,9 +8,7 @@ typedef struct receiver {
|
||||
size_t rest;
|
||||
} receiver;
|
||||
|
||||
receiver r;
|
||||
|
||||
size_t receiver_init(receiver *r) {
|
||||
void receiver_init(receiver *r) {
|
||||
msgpack_packer pk;
|
||||
|
||||
msgpack_sbuffer_init(&r->sbuf);
|
||||
@@ -52,6 +50,8 @@ void unpack(receiver* r) {
|
||||
msgpack_unpack_return ret;
|
||||
char* buf;
|
||||
size_t recv_len;
|
||||
int recv_count = 0;
|
||||
int i = 0;
|
||||
|
||||
msgpack_unpacked_init(&result);
|
||||
if (msgpack_unpacker_buffer_capacity(unp) < EACH_RECV_SIZE) {
|
||||
@@ -64,16 +64,14 @@ void unpack(receiver* r) {
|
||||
msgpack_unpacker_buffer_consumed(unp, recv_len);
|
||||
|
||||
|
||||
int recv_count = 0;
|
||||
while (recv_len > 0) {
|
||||
int i = 0;
|
||||
printf("receive count: %d %d bytes received.:\n", recv_count++, recv_len);
|
||||
while (recv_len > 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++);
|
||||
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. */
|
||||
@@ -110,10 +108,16 @@ int main(void) {
|
||||
/* Output */
|
||||
|
||||
/*
|
||||
receive count: 0 4 bytes received.
|
||||
receive count: 1 4 bytes received.
|
||||
receive count: 2 4 bytes received.
|
||||
Object no 1:
|
||||
[1, true, "example"]
|
||||
receive count: 3 4 bytes received.
|
||||
receive count: 4 4 bytes received.
|
||||
Object no 2:
|
||||
"second"
|
||||
receive count: 5 1 bytes received.
|
||||
Object no 3:
|
||||
[42, false]
|
||||
*/
|
@@ -3,12 +3,15 @@
|
||||
|
||||
int main(void)
|
||||
{
|
||||
/* msgpack::sbuffer is a simple buffer implementation. */
|
||||
msgpack_sbuffer sbuf;
|
||||
msgpack_packer pk;
|
||||
msgpack_zone mempool;
|
||||
msgpack_object deserialized;
|
||||
|
||||
/* msgpack::sbuffer is a simple buffer implementation. */
|
||||
msgpack_sbuffer_init(&sbuf);
|
||||
|
||||
/* serialize values into the buffer using msgpack_sbuffer_write callback function. */
|
||||
msgpack_packer pk;
|
||||
msgpack_packer_init(&pk, &sbuf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(&pk, 3);
|
||||
@@ -19,10 +22,8 @@ int main(void)
|
||||
|
||||
/* 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. */
|
@@ -1,13 +1,16 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_packer * pk;
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
@@ -17,9 +20,6 @@ void test()
|
||||
}
|
||||
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)) {
|
@@ -1,14 +1,17 @@
|
||||
#include <msgpack.h>
|
||||
#include <assert.h>
|
||||
|
||||
void test()
|
||||
{
|
||||
uint64_t test_u64 = 0xFFF0000000000001LL;
|
||||
size_t size = 10000000;
|
||||
msgpack_sbuffer buf;
|
||||
msgpack_packer * pk;
|
||||
size_t upk_pos = 0;
|
||||
msgpack_unpacked msg;
|
||||
|
||||
msgpack_sbuffer_init(&buf);
|
||||
|
||||
msgpack_packer * pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
pk = msgpack_packer_new(&buf, msgpack_sbuffer_write);
|
||||
|
||||
msgpack_pack_array(pk, size);
|
||||
{
|
||||
@@ -18,9 +21,6 @@ void test()
|
||||
}
|
||||
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)) {
|
@@ -33,7 +33,7 @@ void unpack(char const* buf, size_t len) {
|
||||
msgpack_object obj = result.data;
|
||||
|
||||
/* Use obj. */
|
||||
printf("Object no %d:\n", i++);
|
||||
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. */
|
||||
@@ -72,4 +72,5 @@ Object no 2:
|
||||
"second"
|
||||
Object no 3:
|
||||
[42, false]
|
||||
All msgpack_object in the buffer is consumed.
|
||||
*/
|
80
example/cpp03/class_intrusive.cpp
Normal file
80
example/cpp03/class_intrusive.cpp
Normal file
@@ -0,0 +1,80 @@
|
||||
// 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>
|
||||
|
||||
#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) {}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
126
example/cpp03/class_non_intrusive.cpp
Normal file
126
example/cpp03/class_non_intrusive.cpp
Normal file
@@ -0,0 +1,126 @@
|
||||
// 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>
|
||||
|
||||
#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_;
|
||||
};
|
||||
|
||||
// User defined class template specialization
|
||||
namespace msgpack {
|
||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||
namespace adaptor {
|
||||
|
||||
template<>
|
||||
struct convert<my_class> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, my_class& v) const {
|
||||
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<>
|
||||
struct pack<my_class> {
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator()(msgpack::packer<Stream>& o, my_class const& v) const {
|
||||
// packing member variables as an array.
|
||||
o.pack_array(2);
|
||||
o.pack(v.get_name());
|
||||
o.pack(v.get_age());
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<my_class> {
|
||||
void operator()(msgpack::object::with_zone& o, my_class const& v) const {
|
||||
o.type = type::ARRAY;
|
||||
o.via.array.size = 2;
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(
|
||||
o.zone.allocate_align(sizeof(msgpack::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);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
} // 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;
|
||||
}
|
||||
}
|
67
example/cpp03/enum.cpp
Normal file
67
example/cpp03/enum.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
// 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 <sstream>
|
||||
#include <iostream>
|
||||
#include <cassert>
|
||||
|
||||
#include <msgpack.hpp>
|
||||
|
||||
enum my_enum {
|
||||
elem1,
|
||||
elem2,
|
||||
elem3
|
||||
};
|
||||
|
||||
MSGPACK_ADD_ENUM(my_enum);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
@@ -1,8 +1,27 @@
|
||||
// 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>
|
||||
|
||||
// This example uses obsolete APIs
|
||||
// See protocol_new.cpp
|
||||
namespace myprotocol {
|
||||
using namespace msgpack::type;
|
||||
using msgpack::define;
|
||||
@@ -84,4 +103,3 @@ int main(void)
|
||||
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);
|
||||
}
|
@@ -1,3 +1,20 @@
|
||||
// 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>
|
||||
@@ -35,4 +52,3 @@ int main(void)
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@@ -1,3 +1,20 @@
|
||||
// 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
|
||||
|
||||
@@ -52,4 +69,3 @@ int main(void)
|
||||
{
|
||||
test_map_pack_unpack();
|
||||
}
|
||||
|
@@ -1,3 +1,20 @@
|
||||
// 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
|
||||
|
||||
@@ -75,4 +92,3 @@ int main(void)
|
||||
{
|
||||
test_array_of_array();
|
||||
}
|
||||
|
@@ -1,3 +1,20 @@
|
||||
// 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>
|
||||
@@ -13,7 +30,7 @@ public:
|
||||
|
||||
~Server() { }
|
||||
|
||||
typedef msgpack::unique_ptr<msgpack::zone> auto_zone;
|
||||
typedef msgpack::unique_ptr<msgpack::zone> unique_zone;
|
||||
|
||||
void socket_readable()
|
||||
{
|
||||
@@ -37,7 +54,7 @@ public:
|
||||
msgpack::unpacked result;
|
||||
while (m_pac.next(&result)) {
|
||||
msgpack::object msg = result.get();
|
||||
auto_zone& life = result.zone();
|
||||
unique_zone& life = result.zone();
|
||||
process_message(msg, life);
|
||||
}
|
||||
|
||||
@@ -47,7 +64,7 @@ public:
|
||||
}
|
||||
|
||||
private:
|
||||
void process_message(msgpack::object msg, auto_zone& life)
|
||||
void process_message(msgpack::object msg, unique_zone&)
|
||||
{
|
||||
std::cout << "message reached: " << msg << std::endl;
|
||||
}
|
||||
@@ -59,26 +76,27 @@ private:
|
||||
|
||||
|
||||
static void* run_server(void* arg)
|
||||
try {
|
||||
Server* srv = reinterpret_cast<Server*>(arg);
|
||||
{
|
||||
try {
|
||||
Server* srv = reinterpret_cast<Server*>(arg);
|
||||
|
||||
while(true) {
|
||||
srv->socket_readable();
|
||||
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;
|
||||
}
|
||||
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") ) { }
|
||||
|
||||
@@ -130,4 +148,3 @@ int main(void)
|
||||
|
||||
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::unpacked result;
|
||||
msgpack::unpack(result, sbuf.data(), sbuf.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;
|
||||
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, nc);
|
||||
|
||||
msgpack::unpacked result;
|
||||
msgpack::unpack(result, sbuf.data(), sbuf.size());
|
||||
msgpack::object obj = result.get();
|
||||
|
||||
obj.convert(&oc);
|
||||
|
||||
std::cout << obj << " value=" << oc.value << std::endl;
|
||||
}
|
||||
}
|
||||
|
@@ -16,9 +16,11 @@
|
||||
// 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/version.hpp"
|
||||
#include "msgpack/type.hpp"
|
||||
|
92
include/msgpack/adaptor/adaptor_base.hpp
Normal file
92
include/msgpack/adaptor/adaptor_base.hpp
Normal file
@@ -0,0 +1,92 @@
|
||||
//
|
||||
// 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_ADAPTOR_BASE_HPP
|
||||
#define MSGPACK_ADAPTOR_BASE_HPP
|
||||
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
template <typename Stream>
|
||||
class packer;
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
// Adaptor functors
|
||||
|
||||
template <typename T>
|
||||
struct convert {
|
||||
msgpack::object const& operator()(msgpack::object const& o, T& v) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, T const& v) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object {
|
||||
void operator()(msgpack::object& o, T const& v) const;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone {
|
||||
void operator()(msgpack::object::with_zone& o, T const& v) const;
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// operators
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
msgpack::object const& operator>> (msgpack::object const& o, T& v) {
|
||||
return adaptor::convert<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, T const& v) {
|
||||
return adaptor::pack<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
void operator<< (msgpack::object& o, T const& v) {
|
||||
adaptor::object<T>()(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
void operator<< (msgpack::object::with_zone& o, T const& v) {
|
||||
adaptor::object_with_zone<T>()(o, v);
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_ADAPTOR_BASE_HPP
|
@@ -19,39 +19,55 @@
|
||||
#define MSGPACK_TYPE_BOOL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
inline object const& operator>> (object const& o, bool& v)
|
||||
{
|
||||
if(o.type != type::BOOLEAN) { throw type_error(); }
|
||||
v = o.via.boolean;
|
||||
return o;
|
||||
}
|
||||
namespace adaptor {
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const bool& v)
|
||||
{
|
||||
if(v) { o.pack_true(); }
|
||||
else { o.pack_false(); }
|
||||
return o;
|
||||
}
|
||||
template <>
|
||||
struct convert<bool> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, bool& v) const {
|
||||
if(o.type != msgpack::type::BOOLEAN) { throw msgpack::type_error(); }
|
||||
v = o.via.boolean;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, bool v)
|
||||
{
|
||||
o.type = type::BOOLEAN;
|
||||
o.via.boolean = v;
|
||||
}
|
||||
template <>
|
||||
struct pack<bool> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const bool& v) const {
|
||||
if(v) { o.pack_true(); }
|
||||
else { o.pack_false(); }
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, bool v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object<bool> {
|
||||
void operator()(msgpack::object& o, bool v) const {
|
||||
o.type = msgpack::type::BOOLEAN;
|
||||
o.via.boolean = v;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<bool> {
|
||||
void operator()(msgpack::object::with_zone& o, bool v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,39 +0,0 @@
|
||||
//
|
||||
// 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_FWD_HPP
|
||||
#define MSGPACK_TYPE_BOOL_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
object const& operator>> (object const& o, bool& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const bool& v);
|
||||
void operator<< (object& o, bool v);
|
||||
void operator<< (object::with_zone& o, bool v);
|
||||
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_BOOL_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
// 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.
|
||||
@@ -20,40 +20,145 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <cstring>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const char* v)
|
||||
{
|
||||
std::size_t size = std::strlen(v);
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
namespace adaptor {
|
||||
|
||||
inline void operator<< (object::with_zone& o, const char* v)
|
||||
{
|
||||
std::size_t size = std::strlen(v);
|
||||
o.type = type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = static_cast<uint32_t>(size);
|
||||
memcpy(ptr, v, size);
|
||||
}
|
||||
template <>
|
||||
struct pack<const char*> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
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<< (object& o, const char* v)
|
||||
{
|
||||
std::size_t size = std::strlen(v);
|
||||
o.type = type::STR;
|
||||
o.via.str.ptr = v;
|
||||
o.via.str.size = static_cast<uint32_t>(size);
|
||||
}
|
||||
template <>
|
||||
struct object_with_zone<const char*> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<const char*> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
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 <>
|
||||
struct pack<char*> {
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator()(packer<Stream>& o, char* v) const {
|
||||
return o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<char*> {
|
||||
void operator()(msgpack::object::with_zone& o, char* v) const {
|
||||
o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<char*> {
|
||||
void operator()(msgpack::object& o, char* v) const {
|
||||
o << static_cast<const char*>(v);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct pack<char[N]> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<char[N]> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<char[N]> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
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 <std::size_t N>
|
||||
struct pack<const char[N]> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const char* v) const {
|
||||
uint32_t size = checked_get_container_size(std::strlen(v));
|
||||
o.pack_str(size);
|
||||
o.pack_str_body(v, size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<const char[N]> {
|
||||
void operator()(msgpack::object::with_zone& o, const char* v) const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
struct object<const char[N]> {
|
||||
void operator()(msgpack::object& o, const char* v) const {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,38 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const char* v);
|
||||
void operator<< (object::with_zone& o, const char* v);
|
||||
void operator<< (object& o, const char* v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_CHAR_PTR_FWD_HPP
|
65
include/msgpack/adaptor/check_container_size.hpp
Normal file
65
include/msgpack/adaptor/check_container_size.hpp
Normal file
@@ -0,0 +1,65 @@
|
||||
//
|
||||
// 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 {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CHECK_CONTAINER_SIZE_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
// 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.
|
||||
@@ -20,53 +20,71 @@
|
||||
#define MSGPACK_CPP11_ARRAY_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
inline object const& operator>> (object const& o, std::array<T, N>& v) {
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
if(o.via.array.size != N) { throw type_error(); }
|
||||
if(o.via.array.size > 0) {
|
||||
object* p = o.via.array.ptr;
|
||||
object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
T* it = &v[0];
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct convert<std::array<T, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<T, N>& v) const {
|
||||
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;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T, std::size_t N>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::array<T, N>& v) {
|
||||
o.pack_array(v.size());
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
inline void operator<< (object::with_zone& o, const std::array<T, N>& v) {
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
o.via.array.size = v.size();
|
||||
o.via.array.ptr = p;
|
||||
for (auto const& e : v) *p++ = object(e, o.zone);
|
||||
struct pack<std::array<T, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<T, N>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(size);
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
template <typename T, std::size_t N>
|
||||
struct object_with_zone<std::array<T, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<T, N>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
// 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.
|
||||
@@ -19,61 +19,79 @@
|
||||
#define MSGPACK_TYPE_ARRAY_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <array>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <std::size_t N>
|
||||
inline object const& operator>> (object const& o, std::array<char, N>& v)
|
||||
{
|
||||
switch (o.type) {
|
||||
case type::BIN:
|
||||
if(o.via.bin.size != N) { throw type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case type::STR:
|
||||
if(o.via.str.size != N) { throw type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
throw type_error();
|
||||
break;
|
||||
struct convert<std::array<char, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<char, N>& v) const {
|
||||
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;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, std::size_t N>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::array<char, N>& v)
|
||||
{
|
||||
o.pack_bin(v.size());
|
||||
o.pack_bin_body(v.data(), v.size());
|
||||
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <std::size_t N>
|
||||
inline void operator<< (object& o, const std::array<char, N>& v)
|
||||
{
|
||||
o.type = type::BIN;
|
||||
o.via.bin.ptr = v.data();
|
||||
o.via.bin.size = static_cast<uint32_t>(v.size());
|
||||
}
|
||||
struct pack<std::array<char, N>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::array<char, N>& v) const {
|
||||
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<< (object::with_zone& o, const std::array<char, N>& v)
|
||||
{
|
||||
o.type = type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.size()));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = static_cast<uint32_t>(v.size());
|
||||
std::memcpy(ptr, v.data(), v.size());
|
||||
}
|
||||
struct object<std::array<char, N>> {
|
||||
void operator()(msgpack::object& o, const std::array<char, N>& v) const {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
template <std::size_t N>
|
||||
struct object_with_zone<std::array<char, N>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::array<char, N>& v) const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace msgpack
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_CHAR_HPP
|
||||
|
@@ -1,45 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
object const& operator>> (object const& o, std::array<char, N>& v);
|
||||
|
||||
template <typename Stream, std::size_t N>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::array<char, N>& v);
|
||||
|
||||
template <std::size_t N>
|
||||
void operator<< (object& o, const std::array<char, N>& v);
|
||||
|
||||
template <std::size_t N>
|
||||
void operator<< (object::with_zone& o, const std::array<char, N>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP
|
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
object const& operator>> (object const& o, std::array<T, N>& v);
|
||||
|
||||
template <typename Stream, typename T, std::size_t N>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::array<T, N>& v);
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
void operator<< (object::with_zone& o, const std::array<T, N>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_ARRAY_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
// 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.
|
||||
@@ -20,53 +20,67 @@
|
||||
#define MSGPACK_CPP11_FORWARD_LIST_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <forward_list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
inline object const& operator>> (object const& o, std::forward_list<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
object* p = o.via.array.ptr;
|
||||
for (auto &e : v) {
|
||||
p->convert(e);
|
||||
++p;
|
||||
struct convert<std::forward_list<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::forward_list<T>& v) const {
|
||||
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;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::forward_list<T>& v)
|
||||
{
|
||||
o.pack_array(std::distance(v.begin(), v.end()));
|
||||
for(auto const& e : v) o.pack(e);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::forward_list<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
std::size_t size = std::distance(v.begin(), v.end());
|
||||
o.via.array.size = size;
|
||||
object* p = static_cast<object*>(
|
||||
o.zone.allocate_align(sizeof(object)*size));
|
||||
o.via.array.ptr = p;
|
||||
for(auto const& e : v) *p++ = object(e, o.zone);
|
||||
struct pack<std::forward_list<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::forward_list<T>& v) const {
|
||||
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;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
template <typename T>
|
||||
struct object_with_zone<std::forward_list<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::forward_list<T>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
object const& operator>> (object const& o, std::forward_list<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::forward_list<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const std::forward_list<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_FORWARD_LIST_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
|
||||
// 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.
|
||||
@@ -19,19 +19,22 @@
|
||||
#define MSGPACK_CPP11_TUPLE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <tuple>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
// --- Pack ( from tuple to packer stream ---
|
||||
// --- Pack from tuple to packer stream ---
|
||||
template <typename Stream, typename Tuple, std::size_t N>
|
||||
struct StdTuplePacker {
|
||||
static void pack(
|
||||
packer<Stream>& o,
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
StdTuplePacker<Stream, Tuple, N-1>::pack(o, v);
|
||||
o.pack(std::get<N-1>(v));
|
||||
@@ -41,7 +44,7 @@ struct StdTuplePacker {
|
||||
template <typename Stream, typename Tuple>
|
||||
struct StdTuplePacker<Stream, Tuple, 1> {
|
||||
static void pack (
|
||||
packer<Stream>& o,
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
o.pack(std::get<0>(v));
|
||||
}
|
||||
@@ -50,27 +53,34 @@ struct StdTuplePacker<Stream, Tuple, 1> {
|
||||
template <typename Stream, typename Tuple>
|
||||
struct StdTuplePacker<Stream, Tuple, 0> {
|
||||
static void pack (
|
||||
packer<Stream>&,
|
||||
msgpack::packer<Stream>&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename Stream, typename... Args>
|
||||
inline const packer<Stream>& operator<< (
|
||||
packer<Stream>& o,
|
||||
const std::tuple<Args...>& v) {
|
||||
o.pack_array(sizeof...(Args));
|
||||
StdTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
|
||||
return o;
|
||||
}
|
||||
template <typename... Args>
|
||||
struct pack<std::tuple<Args...>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(
|
||||
msgpack::packer<Stream>& o,
|
||||
const std::tuple<Args...>& v) const {
|
||||
uint32_t size = checked_get_container_size(sizeof...(Args));
|
||||
o.pack_array(size);
|
||||
StdTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// --- Convert from tuple to object ---
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleConverter {
|
||||
static void convert(
|
||||
object const& o,
|
||||
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));
|
||||
@@ -80,7 +90,7 @@ struct StdTupleConverter {
|
||||
template <typename Tuple>
|
||||
struct StdTupleConverter<Tuple, 1> {
|
||||
static void convert (
|
||||
object const& o,
|
||||
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));
|
||||
}
|
||||
@@ -89,60 +99,75 @@ struct StdTupleConverter<Tuple, 1> {
|
||||
template <typename Tuple>
|
||||
struct StdTupleConverter<Tuple, 0> {
|
||||
static void convert (
|
||||
object const&,
|
||||
msgpack::object const&,
|
||||
Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
inline object const& operator>> (
|
||||
object const& o,
|
||||
std::tuple<Args...>& v) {
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
if(o.via.array.size < sizeof...(Args)) { throw type_error(); }
|
||||
StdTupleConverter<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
return o;
|
||||
}
|
||||
struct convert<std::tuple<Args...>> {
|
||||
msgpack::object const& operator()(
|
||||
msgpack::object const& o,
|
||||
std::tuple<Args...>& v) const {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// --- Convert from tuple to object with zone ---
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct StdTupleToObjectWithZone {
|
||||
static void convert(
|
||||
object::with_zone& o,
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
StdTupleToObjectWithZone<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1] = object(std::get<N-1>(v), o.zone);
|
||||
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 (
|
||||
object::with_zone& o,
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
o.via.array.ptr[0] = object(std::get<0>(v), o.zone);
|
||||
o.via.array.ptr[0] = msgpack::object(std::get<0>(v), o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct StdTupleToObjectWithZone<Tuple, 0> {
|
||||
static void convert (
|
||||
object::with_zone&,
|
||||
msgpack::object::with_zone&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
inline void operator<< (
|
||||
object::with_zone& o,
|
||||
std::tuple<Args...> const& v) {
|
||||
o.type = type::ARRAY;
|
||||
o.via.array.ptr = static_cast<object*>(o.zone.allocate_align(sizeof(object)*sizeof...(Args)));
|
||||
o.via.array.size = sizeof...(Args);
|
||||
StdTupleToObjectWithZone<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
}
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
struct object_with_zone<std::tuple<Args...>> {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
std::tuple<Args...> const& v) const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,62 +0,0 @@
|
||||
//
|
||||
// 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 packer<Stream>& operator<< (
|
||||
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>
|
||||
object const& operator>> (
|
||||
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<< (
|
||||
object::with_zone& o,
|
||||
std::tuple<Args...> const& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_TUPLE_FWD_HPP
|
158
include/msgpack/adaptor/cpp11/unordered_map.hpp
Normal file
158
include/msgpack/adaptor/cpp11/unordered_map.hpp
Normal file
@@ -0,0 +1,158 @@
|
||||
//
|
||||
// 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/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <unordered_map>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename K, typename V>
|
||||
struct convert<std::unordered_map<K, V>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_map<K, V>& v) const {
|
||||
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 K, typename V>
|
||||
struct pack<std::unordered_map<K, V>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_map<K,V>& v) const {
|
||||
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>
|
||||
struct object_with_zone<std::unordered_map<K, V>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_map<K,V>& v) const {
|
||||
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>
|
||||
struct convert<std::unordered_multimap<K, V>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multimap<K, V>& v) const {
|
||||
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 K, typename V>
|
||||
struct pack<std::unordered_multimap<K, V>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multimap<K,V>& v) const {
|
||||
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>
|
||||
struct object_with_zone<std::unordered_multimap<K, V>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_multimap<K,V>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_MAP_HPP
|
150
include/msgpack/adaptor/cpp11/unordered_set.hpp
Normal file
150
include/msgpack/adaptor/cpp11/unordered_set.hpp
Normal file
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// 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/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <unordered_set>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct convert<std::unordered_set<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_set<T>& v) const {
|
||||
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 T>
|
||||
struct pack<std::unordered_set<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_set<T>& v) const {
|
||||
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>
|
||||
struct object_with_zone<std::unordered_set<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_set<T>& v) const {
|
||||
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>
|
||||
struct convert<std::unordered_multiset<T>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::unordered_multiset<T>& v) const {
|
||||
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 T>
|
||||
struct pack<std::unordered_multiset<T>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::unordered_multiset<T>& v) const {
|
||||
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>
|
||||
struct object_with_zone<std::unordered_multiset<T>> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::unordered_multiset<T>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_UNORDERED_SET_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// 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.
|
||||
@@ -19,60 +19,76 @@
|
||||
#define MSGPACK_TYPE_DEQUE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <deque>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
inline object const& operator>> (object const& o, std::deque<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
object* p = o.via.array.ptr;
|
||||
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);
|
||||
struct convert<std::deque<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::deque<T>& v) const {
|
||||
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;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::deque<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename std::deque<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename T>
|
||||
struct pack<std::deque<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::deque<T>& v) const {
|
||||
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);
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::deque<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename std::deque<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<std::deque<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::deque<T>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
object const& operator>> (object const& o, std::deque<T>& v);
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::deque<T>& v);
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const std::deque<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_DEQUE_FWD_HPP
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -19,10 +19,10 @@
|
||||
#define MSGPACK_CPP11_DEFINE_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
// for MSGPACK_ADD_ENUM
|
||||
#include "msgpack/adaptor/int_fwd.hpp"
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
|
||||
#include <type_traits>
|
||||
#include <tuple>
|
||||
@@ -44,36 +44,52 @@
|
||||
}
|
||||
|
||||
// MSGPACK_ADD_ENUM must be used in the global namespace.
|
||||
#define MSGPACK_ADD_ENUM(enum) \
|
||||
#define MSGPACK_ADD_ENUM(enum_name) \
|
||||
namespace msgpack { \
|
||||
/** @cond */ \
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) { \
|
||||
/** @endcond */ \
|
||||
namespace adaptor { \
|
||||
template<> \
|
||||
struct convert<enum_name> { \
|
||||
msgpack::object const& operator()(msgpack::object const& o, enum_name& v) const { \
|
||||
std::underlying_type<enum_name>::type tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum_name>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object<enum_name> { \
|
||||
void operator()(msgpack::object& o, const enum_name& v) const { \
|
||||
auto tmp = static_cast<std::underlying_type<enum_name>::type>(v); \
|
||||
o << tmp; \
|
||||
} \
|
||||
}; \
|
||||
template<> \
|
||||
struct object_with_zone<enum_name> { \
|
||||
void operator()(msgpack::object::with_zone& o, const enum_name& v) const { \
|
||||
auto tmp = static_cast<std::underlying_type<enum_name>::type>(v); \
|
||||
o << tmp; \
|
||||
} \
|
||||
}; \
|
||||
template <> \
|
||||
inline object const& operator>> (object const& o, enum& v) \
|
||||
{ \
|
||||
int tmp; \
|
||||
o >> tmp; \
|
||||
v = static_cast<enum>(tmp); \
|
||||
return o; \
|
||||
} \
|
||||
template <> \
|
||||
inline void operator<< (object::with_zone& o, const enum& v) \
|
||||
{ \
|
||||
int tmp = static_cast<std::underlying_type<enum>::type>(v); \
|
||||
o << tmp; \
|
||||
} \
|
||||
namespace detail { \
|
||||
struct pack<enum_name> { \
|
||||
template <typename Stream> \
|
||||
struct packer_serializer<Stream, enum> { \
|
||||
static packer<Stream>& pack(packer<Stream>& o, const enum& v) { \
|
||||
return o << static_cast<std::underlying_type<enum>::type>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const enum_name& v) const { \
|
||||
return o << static_cast<std::underlying_type<enum_name>::type>(v); \
|
||||
} \
|
||||
}; \
|
||||
} \
|
||||
/** @cond */ \
|
||||
} \
|
||||
/** @endcond */ \
|
||||
}
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
namespace type {
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
@@ -126,14 +142,14 @@ struct define {
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
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 = type::ARRAY;
|
||||
o->via.array.ptr = static_cast<object*>(z.allocate_align(sizeof(object)*sizeof...(Args)));
|
||||
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);
|
||||
@@ -153,11 +169,11 @@ struct define<> {
|
||||
}
|
||||
void msgpack_unpack(msgpack::object const& o)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
}
|
||||
void msgpack_object(msgpack::object* o, msgpack::zone&) const
|
||||
{
|
||||
o->type = type::ARRAY;
|
||||
o->type = msgpack::type::ARRAY;
|
||||
o->via.array.ptr = NULL;
|
||||
o->via.array.size = 0;
|
||||
}
|
||||
@@ -175,7 +191,9 @@ define<Args...> make_define(Args&... args)
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_DEFINE_HPP
|
||||
|
@@ -25,7 +25,9 @@
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
// tuple
|
||||
@@ -44,7 +46,7 @@ namespace type {
|
||||
public:
|
||||
using base = std::tuple<Types...>;
|
||||
|
||||
using base::tuple;
|
||||
using base::base;
|
||||
|
||||
tuple() = default;
|
||||
tuple(tuple const&) = default;
|
||||
@@ -91,11 +93,11 @@ namespace type {
|
||||
}
|
||||
} // namespace type
|
||||
|
||||
// --- Pack ( from tuple to packer stream ---
|
||||
// --- Pack from tuple to packer stream ---
|
||||
template <typename Stream, typename Tuple, std::size_t N>
|
||||
struct MsgpackTuplePacker {
|
||||
static void pack(
|
||||
packer<Stream>& o,
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
MsgpackTuplePacker<Stream, Tuple, N-1>::pack(o, v);
|
||||
o.pack(type::get<N-1>(v));
|
||||
@@ -105,7 +107,7 @@ struct MsgpackTuplePacker {
|
||||
template <typename Stream, typename Tuple>
|
||||
struct MsgpackTuplePacker<Stream, Tuple, 1> {
|
||||
static void pack (
|
||||
packer<Stream>& o,
|
||||
msgpack::packer<Stream>& o,
|
||||
const Tuple& v) {
|
||||
o.pack(type::get<0>(v));
|
||||
}
|
||||
@@ -114,26 +116,33 @@ struct MsgpackTuplePacker<Stream, Tuple, 1> {
|
||||
template <typename Stream, typename Tuple>
|
||||
struct MsgpackTuplePacker<Stream, Tuple, 0> {
|
||||
static void pack (
|
||||
packer<Stream>&,
|
||||
msgpack::packer<Stream>&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename... Args>
|
||||
const packer<Stream>& operator<< (
|
||||
packer<Stream>& o,
|
||||
const type::tuple<Args...>& v) {
|
||||
o.pack_array(sizeof...(Args));
|
||||
MsgpackTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
|
||||
return o;
|
||||
}
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
struct pack<type::tuple<Args...>> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(
|
||||
msgpack::packer<Stream>& o,
|
||||
const type::tuple<Args...>& v) const {
|
||||
o.pack_array(sizeof...(Args));
|
||||
MsgpackTuplePacker<Stream, decltype(v), sizeof...(Args)>::pack(o, v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// --- Convert from tuple to object ---
|
||||
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct MsgpackTupleConverter {
|
||||
static void convert(
|
||||
object const& o,
|
||||
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));
|
||||
@@ -143,7 +152,7 @@ struct MsgpackTupleConverter {
|
||||
template <typename Tuple>
|
||||
struct MsgpackTupleConverter<Tuple, 1> {
|
||||
static void convert (
|
||||
object const& o,
|
||||
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));
|
||||
}
|
||||
@@ -152,60 +161,74 @@ struct MsgpackTupleConverter<Tuple, 1> {
|
||||
template <typename Tuple>
|
||||
struct MsgpackTupleConverter<Tuple, 0> {
|
||||
static void convert (
|
||||
object const&,
|
||||
msgpack::object const&,
|
||||
Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
object const& operator>> (
|
||||
object const& o,
|
||||
type::tuple<Args...>& v) {
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
if(o.via.array.size < sizeof...(Args)) { throw type_error(); }
|
||||
MsgpackTupleConverter<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
return o;
|
||||
}
|
||||
struct convert<type::tuple<Args...>> {
|
||||
msgpack::object const& operator()(
|
||||
msgpack::object const& o,
|
||||
type::tuple<Args...>& v) const {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
// --- Convert from tuple to object with zone ---
|
||||
template <typename Tuple, std::size_t N>
|
||||
struct MsgpackTupleToObjectWithZone {
|
||||
static void convert(
|
||||
object::with_zone& o,
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
MsgpackTupleToObjectWithZone<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1] = object(type::get<N-1>(v), o.zone);
|
||||
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 (
|
||||
object::with_zone& o,
|
||||
msgpack::object::with_zone& o,
|
||||
const Tuple& v) {
|
||||
o.via.array.ptr[0] = object(type::get<0>(v), o.zone);
|
||||
o.via.array.ptr[0] = msgpack::object(type::get<0>(v), o.zone);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Tuple>
|
||||
struct MsgpackTupleToObjectWithZone<Tuple, 0> {
|
||||
static void convert (
|
||||
object::with_zone&,
|
||||
msgpack::object::with_zone&,
|
||||
const Tuple&) {
|
||||
}
|
||||
};
|
||||
|
||||
template <typename... Args>
|
||||
inline void operator<< (
|
||||
object::with_zone& o,
|
||||
type::tuple<Args...> const& v) {
|
||||
o.type = type::ARRAY;
|
||||
o.via.array.ptr = static_cast<object*>(o.zone.allocate_align(sizeof(object)*sizeof...(Args)));
|
||||
o.via.array.size = sizeof...(Args);
|
||||
MsgpackTupleToObjectWithZone<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
}
|
||||
namespace adaptor {
|
||||
|
||||
template <typename... Args>
|
||||
struct object_with_zone<type::tuple<Args...>> {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
type::tuple<Args...> const& v) const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
///@endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,84 +0,0 @@
|
||||
//
|
||||
// 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 packer<Stream>& operator<< (
|
||||
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>
|
||||
object const& operator>> (
|
||||
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<< (
|
||||
object::with_zone& o,
|
||||
type::tuple<Args...> const& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_CPP11_MSGPACK_TUPLE_FWD_HPP
|
@@ -19,12 +19,14 @@
|
||||
#define MSGPACK_TYPE_FIXINT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/int.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
@@ -56,156 +58,248 @@ typedef fix_int<int64_t> fix_int64;
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_int8& v)
|
||||
template <>
|
||||
struct convert<type::fix_int8> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int8& v) const
|
||||
{ v = type::detail::convert_integer<int8_t>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_int16& v)
|
||||
template <>
|
||||
struct convert<type::fix_int16> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int16& v) const
|
||||
{ v = type::detail::convert_integer<int16_t>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_int32& v)
|
||||
template <>
|
||||
struct convert<type::fix_int32> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int32& v) const
|
||||
{ v = type::detail::convert_integer<int32_t>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_int64& v)
|
||||
template <>
|
||||
struct convert<type::fix_int64> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_int64& v) const
|
||||
{ v = type::detail::convert_integer<int64_t>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_uint8& v)
|
||||
template <>
|
||||
struct convert<type::fix_uint8> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint8& v) const
|
||||
{ v = type::detail::convert_integer<uint8_t>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_uint16& v)
|
||||
template <>
|
||||
struct convert<type::fix_uint16> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint16& v) const
|
||||
{ v = type::detail::convert_integer<uint16_t>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_uint32& v)
|
||||
template <>
|
||||
struct convert<type::fix_uint32> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint32& v) const
|
||||
{ v = type::detail::convert_integer<uint32_t>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, type::fix_uint64& v)
|
||||
template <>
|
||||
struct convert<type::fix_uint64> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::fix_uint64& v) const
|
||||
{ v = type::detail::convert_integer<uint64_t>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int8& v)
|
||||
template <>
|
||||
struct pack<type::fix_int8> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int8& v) const
|
||||
{ o.pack_fix_int8(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int16& v)
|
||||
template <>
|
||||
struct pack<type::fix_int16> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int16& v) const
|
||||
{ o.pack_fix_int16(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int32& v)
|
||||
template <>
|
||||
struct pack<type::fix_int32> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int32& v) const
|
||||
{ o.pack_fix_int32(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int64& v)
|
||||
template <>
|
||||
struct pack<type::fix_int64> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_int64& v) const
|
||||
{ o.pack_fix_int64(v); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint8& v)
|
||||
template <>
|
||||
struct pack<type::fix_uint8> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint8& v) const
|
||||
{ o.pack_fix_uint8(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint16& v)
|
||||
template <>
|
||||
struct pack<type::fix_uint16> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint16& v) const
|
||||
{ o.pack_fix_uint16(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint32& v)
|
||||
template <>
|
||||
struct pack<type::fix_uint32> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint32& v) const
|
||||
{ o.pack_fix_uint32(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v)
|
||||
template <>
|
||||
struct pack<type::fix_uint64> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::fix_uint64& v) const
|
||||
{ o.pack_fix_uint64(v); return o; }
|
||||
};
|
||||
|
||||
|
||||
inline void operator<< (object& o, type::fix_int8 v)
|
||||
{
|
||||
if (v.get() < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
template <>
|
||||
struct object<type::fix_int8> {
|
||||
void operator()(msgpack::object& o, type::fix_int8 v) const {
|
||||
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();
|
||||
}
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_int16> {
|
||||
void operator()(msgpack::object& o, type::fix_int16 v) const {
|
||||
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<< (object& o, type::fix_int16 v)
|
||||
{
|
||||
if(v.get() < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
template <>
|
||||
struct object<type::fix_int32> {
|
||||
void operator()(msgpack::object& o, type::fix_int32 v) const {
|
||||
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();
|
||||
}
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_int64> {
|
||||
void operator()(msgpack::object& o, type::fix_int64 v) const {
|
||||
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<< (object& o, type::fix_int32 v)
|
||||
{
|
||||
if (v.get() < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
template <>
|
||||
struct object<type::fix_uint8> {
|
||||
void operator()(msgpack::object& o, type::fix_uint8 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, type::fix_int64 v)
|
||||
{
|
||||
if (v.get() < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v.get();
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v.get();
|
||||
}
|
||||
}
|
||||
template <>
|
||||
struct object<type::fix_uint16> {
|
||||
void operator()(msgpack::object& o, type::fix_uint16 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_uint32> {
|
||||
void operator()(msgpack::object& o, type::fix_uint32 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::fix_uint64> {
|
||||
void operator()(msgpack::object& o, type::fix_uint64 v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int8> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int8 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int16> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int16 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int32> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int32 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::fix_int64> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_int64 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint8 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint8> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint8 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint16 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint16> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint16 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint32 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint32> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint32 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, type::fix_uint64 v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
|
||||
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int8 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int16 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int32 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_int64 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint8 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint16 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint32 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::fix_uint64 v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<type::fix_uint64> {
|
||||
void operator()(msgpack::object::with_zone& o, type::fix_uint64 v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,100 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
|
||||
object const& operator>> (object const& o, type::fix_int8& v);
|
||||
object const& operator>> (object const& o, type::fix_int16& v);
|
||||
object const& operator>> (object const& o, type::fix_int32& v);
|
||||
object const& operator>> (object const& o, type::fix_int64& v);
|
||||
|
||||
object const& operator>> (object const& o, type::fix_uint8& v);
|
||||
object const& operator>> (object const& o, type::fix_uint16& v);
|
||||
object const& operator>> (object const& o, type::fix_uint32& v);
|
||||
object const& operator>> (object const& o, type::fix_uint64& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int8& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int16& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int32& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int64& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint8& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint16& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint32& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v);
|
||||
|
||||
void operator<< (object& o, type::fix_int8 v);
|
||||
void operator<< (object& o, type::fix_int16 v);
|
||||
void operator<< (object& o, type::fix_int32 v);
|
||||
void operator<< (object& o, type::fix_int64 v);
|
||||
|
||||
void operator<< (object& o, type::fix_uint8 v);
|
||||
void operator<< (object& o, type::fix_uint16 v);
|
||||
void operator<< (object& o, type::fix_uint32 v);
|
||||
void operator<< (object& o, type::fix_uint64 v);
|
||||
|
||||
void operator<< (object::with_zone& o, type::fix_int8 v);
|
||||
void operator<< (object::with_zone& o, type::fix_int16 v);
|
||||
void operator<< (object::with_zone& o, type::fix_int32 v);
|
||||
void operator<< (object::with_zone& o, type::fix_int64 v);
|
||||
|
||||
void operator<< (object::with_zone& o, type::fix_uint8 v);
|
||||
void operator<< (object::with_zone& o, type::fix_uint16 v);
|
||||
void operator<< (object::with_zone& o, type::fix_uint32 v);
|
||||
void operator<< (object::with_zone& o, type::fix_uint64 v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_FIXINT_FWD_HPP
|
@@ -24,81 +24,107 @@
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
// FIXME check overflow, underflow
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
inline object const& operator>> (object const& o, float& v)
|
||||
{
|
||||
if(o.type == type::DOUBLE) {
|
||||
v = static_cast<float>(o.via.dec);
|
||||
template <>
|
||||
struct convert<float> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, float& v) const {
|
||||
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;
|
||||
}
|
||||
else if (o.type == type::POSITIVE_INTEGER) {
|
||||
v = static_cast<float>(o.via.u64);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<float> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const float& v) const {
|
||||
o.pack_float(v);
|
||||
return o;
|
||||
}
|
||||
else if (o.type == type::NEGATIVE_INTEGER) {
|
||||
v = static_cast<float>(o.via.i64);
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct convert<double> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, double& v) const {
|
||||
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;
|
||||
}
|
||||
else {
|
||||
throw type_error();
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<double> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const double& v) const {
|
||||
o.pack_double(v);
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const float& v)
|
||||
{
|
||||
o.pack_float(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
inline object const& operator>> (object const& o, double& v)
|
||||
{
|
||||
if(o.type == type::DOUBLE) {
|
||||
v = o.via.dec;
|
||||
template <>
|
||||
struct object<float> {
|
||||
void operator()(msgpack::object& o, float v) const {
|
||||
o.type = msgpack::type::FLOAT;
|
||||
o.via.f64 = static_cast<double>(v);
|
||||
}
|
||||
else if (o.type == type::POSITIVE_INTEGER) {
|
||||
v = static_cast<double>(o.via.u64);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<double> {
|
||||
void operator()(msgpack::object& o, double v) const {
|
||||
o.type = msgpack::type::FLOAT;
|
||||
o.via.f64 = v;
|
||||
}
|
||||
else if (o.type == type::NEGATIVE_INTEGER) {
|
||||
v = static_cast<double>(o.via.i64);
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<float> {
|
||||
void operator()(msgpack::object::with_zone& o, float v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
else {
|
||||
throw type_error();
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<double> {
|
||||
void operator()(msgpack::object::with_zone& o, double v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const double& v)
|
||||
{
|
||||
o.pack_double(v);
|
||||
return o;
|
||||
}
|
||||
|
||||
|
||||
inline void operator<< (object& o, float v)
|
||||
{
|
||||
o.type = type::DOUBLE;
|
||||
o.via.dec = static_cast<double>(v);
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, double v)
|
||||
{
|
||||
o.type = type::DOUBLE;
|
||||
o.via.dec = v;
|
||||
}
|
||||
|
||||
inline void operator<< (object::with_zone& o, float v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, double v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,44 +0,0 @@
|
||||
//
|
||||
// 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) {
|
||||
|
||||
object const& operator>> (object const& o, float& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const float& v);
|
||||
object const& operator>> (object const& o, double& v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const double& v);
|
||||
void operator<< (object& o, float v);
|
||||
void operator<< (object& o, double v);
|
||||
void operator<< (object::with_zone& o, float v);
|
||||
void operator<< (object::with_zone& o, double v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_FLOAT_FWD_HPP
|
@@ -19,12 +19,14 @@
|
||||
#define MSGPACK_TYPE_INT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include <limits>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1){
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
namespace detail {
|
||||
@@ -33,29 +35,29 @@ namespace detail {
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, true> {
|
||||
static inline T convert(object const& o) {
|
||||
if(o.type == type::POSITIVE_INTEGER) {
|
||||
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 type_error(); }
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.u64);
|
||||
} else if(o.type == type::NEGATIVE_INTEGER) {
|
||||
} else if(o.type == msgpack::type::NEGATIVE_INTEGER) {
|
||||
if(o.via.i64 < static_cast<int64_t>(std::numeric_limits<T>::min()))
|
||||
{ throw type_error(); }
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.i64);
|
||||
}
|
||||
throw type_error();
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct convert_integer_sign<T, false> {
|
||||
static inline T convert(object const& o) {
|
||||
if(o.type == type::POSITIVE_INTEGER) {
|
||||
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 type_error(); }
|
||||
{ throw msgpack::type_error(); }
|
||||
return static_cast<T>(o.via.u64);
|
||||
}
|
||||
throw type_error();
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
};
|
||||
|
||||
@@ -65,47 +67,23 @@ namespace detail {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
static inline T convert_integer(object const& o)
|
||||
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 pack_char_sign;
|
||||
|
||||
template <>
|
||||
struct pack_char_sign<true> {
|
||||
template <typename Stream>
|
||||
static inline packer<Stream>& pack(packer<Stream>& o, char v) {
|
||||
o.pack_int8(v); return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack_char_sign<false> {
|
||||
template <typename Stream>
|
||||
static inline packer<Stream>& pack(packer<Stream>& o, char v) {
|
||||
o.pack_uint8(v); return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
static inline packer<Stream>& pack_char(packer<Stream>& o, char v) {
|
||||
return pack_char_sign<is_signed<char>::value>::pack(o, v);
|
||||
}
|
||||
|
||||
template <bool Signed>
|
||||
struct object_char_sign;
|
||||
|
||||
template <>
|
||||
struct object_char_sign<true> {
|
||||
static inline void make(object& o, char v) {
|
||||
static inline void make(msgpack::object& o, char v) {
|
||||
if (v < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
@@ -113,219 +91,345 @@ namespace detail {
|
||||
|
||||
template <>
|
||||
struct object_char_sign<false> {
|
||||
static inline void make(object& o, char v) {
|
||||
o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||
static inline void make(msgpack::object& o, char v) {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v;
|
||||
}
|
||||
};
|
||||
|
||||
static inline void object_char(object& o, char 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 object const& operator>> (object const& o, char& v)
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<char> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, char& v) const
|
||||
{ v = type::detail::convert_integer<char>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
inline object const& operator>> (object const& o, signed char& v)
|
||||
template <>
|
||||
struct convert<signed char> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed char& v) const
|
||||
{ v = type::detail::convert_integer<signed char>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, signed short& v)
|
||||
template <>
|
||||
struct convert<signed short> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed short& v) const
|
||||
{ v = type::detail::convert_integer<signed short>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, signed int& v)
|
||||
template <>
|
||||
struct convert<signed int> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed int& v) const
|
||||
{ v = type::detail::convert_integer<signed int>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, signed long& v)
|
||||
template <>
|
||||
struct convert<signed long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed long& v) const
|
||||
{ v = type::detail::convert_integer<signed long>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, signed long long& v)
|
||||
template <>
|
||||
struct convert<signed long long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, signed long long& v) const
|
||||
{ v = type::detail::convert_integer<signed long long>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
inline object const& operator>> (object const& o, unsigned char& v)
|
||||
template <>
|
||||
struct convert<unsigned char> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned char& v) const
|
||||
{ v = type::detail::convert_integer<unsigned char>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, unsigned short& v)
|
||||
template <>
|
||||
struct convert<unsigned short> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned short& v) const
|
||||
{ v = type::detail::convert_integer<unsigned short>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, unsigned int& v)
|
||||
template <>
|
||||
struct convert<unsigned int> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned int& v) const
|
||||
{ v = type::detail::convert_integer<unsigned int>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, unsigned long& v)
|
||||
template <>
|
||||
struct convert<unsigned long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned long& v) const
|
||||
{ v = type::detail::convert_integer<unsigned long>(o); return o; }
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, unsigned long long& v)
|
||||
template <>
|
||||
struct convert<unsigned long long> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, unsigned long long& v) const
|
||||
{ v = type::detail::convert_integer<unsigned long long>(o); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, char v)
|
||||
{ return type::detail::pack_char(o, v); }
|
||||
template <>
|
||||
struct pack<char> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, char v) const
|
||||
{ o.pack_char(v); return o; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<signed char> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed char v) const
|
||||
{ o.pack_signed_char(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed char v)
|
||||
{ o.pack_int8(v); return o; }
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed short v)
|
||||
template <>
|
||||
struct pack<signed short> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed short v) const
|
||||
{ o.pack_short(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed int v)
|
||||
template <>
|
||||
struct pack<signed int> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed int v) const
|
||||
{ o.pack_int(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed long v)
|
||||
template <>
|
||||
struct pack<signed long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed long v) const
|
||||
{ o.pack_long(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, signed long long v)
|
||||
template <>
|
||||
struct pack<signed long long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, signed long long v) const
|
||||
{ o.pack_long_long(v); return o; }
|
||||
};
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned char v)
|
||||
{ o.pack_uint8(v); return o; }
|
||||
template <>
|
||||
struct pack<unsigned char> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned char v) const
|
||||
{ o.pack_unsigned_char(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned short v)
|
||||
template <>
|
||||
struct pack<unsigned short> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned short v) const
|
||||
{ o.pack_unsigned_short(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned int v)
|
||||
template <>
|
||||
struct pack<unsigned int> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned int v) const
|
||||
{ o.pack_unsigned_int(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long v)
|
||||
template <>
|
||||
struct pack<unsigned long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned long v) const
|
||||
{ o.pack_unsigned_long(v); return o; }
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long long v)
|
||||
template <>
|
||||
struct pack<unsigned long long> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, unsigned long long v) const
|
||||
{ o.pack_unsigned_long_long(v); return o; }
|
||||
};
|
||||
|
||||
|
||||
inline void operator<< (object& o, char v)
|
||||
template <>
|
||||
struct object<char> {
|
||||
void operator()(msgpack::object& o, char v) const
|
||||
{ type::detail::object_char(o, v); }
|
||||
};
|
||||
|
||||
|
||||
inline void operator<< (object& o, signed char v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
template <>
|
||||
struct object<signed char> {
|
||||
void operator()(msgpack::object& o, signed char v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<signed short> {
|
||||
void operator()(msgpack::object& o, signed short v) const {
|
||||
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<< (object& o, signed short v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
template <>
|
||||
struct object<signed int> {
|
||||
void operator()(msgpack::object& o, signed int v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<signed long> {
|
||||
void operator()(msgpack::object& o, signed long v) const {
|
||||
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<< (object& o, signed int v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
template <>
|
||||
struct object<signed long long> {
|
||||
void operator()(msgpack::object& o, signed long long v) const {
|
||||
if (v < 0) {
|
||||
o.type = msgpack::type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else{
|
||||
o.type = msgpack::type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, signed long v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else {
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
template <>
|
||||
struct object<unsigned char> {
|
||||
void operator()(msgpack::object& o, unsigned char v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, signed long long v)
|
||||
{
|
||||
if (v < 0) {
|
||||
o.type = type::NEGATIVE_INTEGER;
|
||||
o.via.i64 = v;
|
||||
}
|
||||
else{
|
||||
o.type = type::POSITIVE_INTEGER;
|
||||
o.via.u64 = v;
|
||||
}
|
||||
}
|
||||
template <>
|
||||
struct object<unsigned short> {
|
||||
void operator()(msgpack::object& o, unsigned short v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, unsigned char v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
template <>
|
||||
struct object<unsigned int> {
|
||||
void operator()(msgpack::object& o, unsigned int v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, unsigned short v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
template <>
|
||||
struct object<unsigned long> {
|
||||
void operator()(msgpack::object& o, unsigned long v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, unsigned int v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, unsigned long v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
|
||||
inline void operator<< (object& o, unsigned long long v)
|
||||
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
template <>
|
||||
struct object<unsigned long long> {
|
||||
void operator()(msgpack::object& o, unsigned long long v) const
|
||||
{ o.type = msgpack::type::POSITIVE_INTEGER, o.via.u64 = v; }
|
||||
};
|
||||
|
||||
|
||||
template <>
|
||||
struct object_with_zone<char> {
|
||||
void operator()(msgpack::object::with_zone& o, char v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, char v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<signed char> {
|
||||
void operator()(msgpack::object::with_zone& o, signed char v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<signed short> {
|
||||
void operator()(msgpack::object::with_zone& o, signed short v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed char v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<signed int> {
|
||||
void operator()(msgpack::object::with_zone& o, signed int v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed short v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<signed long> {
|
||||
void operator()(msgpack::object::with_zone& o, signed long v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed int v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<signed long long> {
|
||||
void operator()(msgpack::object::with_zone& o, const signed long long& v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, signed long v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<unsigned char> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned char v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, const signed long long& v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<unsigned short> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned short v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<unsigned int> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned int v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned char v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<unsigned long> {
|
||||
void operator()(msgpack::object::with_zone& o, unsigned long v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned short v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned int v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, unsigned long v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
inline void operator<< (object::with_zone& o, const unsigned long long& v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<unsigned long long> {
|
||||
void operator()(msgpack::object::with_zone& o, const unsigned long long& v) const
|
||||
{ static_cast<msgpack::object&>(o) << v; }
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,100 +0,0 @@
|
||||
//
|
||||
// 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){
|
||||
|
||||
object const& operator>> (object const& o, char& v);
|
||||
|
||||
object const& operator>> (object const& o, signed char& v);
|
||||
object const& operator>> (object const& o, signed short& v);
|
||||
object const& operator>> (object const& o, signed int& v);
|
||||
object const& operator>> (object const& o, signed long& v);
|
||||
object const& operator>> (object const& o, signed long long& v);
|
||||
|
||||
object const& operator>> (object const& o, unsigned char& v);
|
||||
object const& operator>> (object const& o, unsigned short& v);
|
||||
object const& operator>> (object const& o, unsigned int& v);
|
||||
object const& operator>> (object const& o, unsigned long& v);
|
||||
object const& operator>> (object const& o, unsigned long long& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, char v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, signed char v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, signed short v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, signed int v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, signed long v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, signed long long v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, unsigned char v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, unsigned short v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, unsigned int v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, unsigned long v);
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, unsigned long long v);
|
||||
|
||||
|
||||
void operator<< (object& o, char v);
|
||||
|
||||
void operator<< (object& o, signed char v);
|
||||
void operator<< (object& o, signed short v);
|
||||
void operator<< (object& o, signed int v);
|
||||
void operator<< (object& o, signed long v);
|
||||
void operator<< (object& o, signed long long v);
|
||||
|
||||
void operator<< (object& o, unsigned char v);
|
||||
void operator<< (object& o, unsigned short v);
|
||||
void operator<< (object& o, unsigned int v);
|
||||
void operator<< (object& o, unsigned long v);
|
||||
void operator<< (object& o, unsigned long long v);
|
||||
|
||||
void operator<< (object::with_zone& o, char v);
|
||||
|
||||
void operator<< (object::with_zone& o, signed char v);
|
||||
void operator<< (object::with_zone& o, signed short v);
|
||||
void operator<< (object::with_zone& o, signed int v);
|
||||
void operator<< (object::with_zone& o, signed long v);
|
||||
void operator<< (object::with_zone& o, const signed long long& v);
|
||||
|
||||
void operator<< (object::with_zone& o, unsigned char v);
|
||||
void operator<< (object::with_zone& o, unsigned short v);
|
||||
void operator<< (object::with_zone& o, unsigned int v);
|
||||
void operator<< (object::with_zone& o, unsigned long v);
|
||||
void operator<< (object::with_zone& o, const unsigned long long& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_INT_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// 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.
|
||||
@@ -19,60 +19,76 @@
|
||||
#define MSGPACK_TYPE_LIST_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <list>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
inline object const& operator>> (object const& o, std::list<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
object* p = o.via.array.ptr;
|
||||
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);
|
||||
struct convert<std::list<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::list<T>& v) const {
|
||||
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;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::list<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename std::list<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename T>
|
||||
struct pack<std::list<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::list<T>& v) const {
|
||||
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);
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::list<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename std::list<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<std::list<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::list<T>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,40 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
object const& operator>> (object const& o, std::list<T>& v);
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::list<T>& v);
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const std::list<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_LIST_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// 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.
|
||||
@@ -20,13 +20,17 @@
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <map>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
@@ -43,168 +47,190 @@ namespace detail {
|
||||
|
||||
} //namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename K, typename V>
|
||||
inline object const& operator>> (object const& o, type::assoc_vector<K,V>& v)
|
||||
{
|
||||
if(o.type != type::MAP) { throw type_error(); }
|
||||
v.resize(o.via.map.size);
|
||||
object_kv* p = o.via.map.ptr;
|
||||
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 packer<Stream>& operator<< (packer<Stream>& o, const type::assoc_vector<K,V>& v)
|
||||
{
|
||||
o.pack_map(v.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<< (object::with_zone& o, const type::assoc_vector<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename type::assoc_vector<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename K, typename V>
|
||||
inline object const& operator>> (object const& o, std::map<K, V>& v)
|
||||
{
|
||||
if(o.type != type::MAP) { throw type_error(); }
|
||||
object_kv* p(o.via.map.ptr);
|
||||
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)) {
|
||||
struct convert<type::assoc_vector<K, V> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::assoc_vector<K,V>& v) const {
|
||||
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 K, typename V>
|
||||
struct pack<type::assoc_vector<K, V> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::assoc_vector<K,V>& v) const {
|
||||
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>
|
||||
struct object_with_zone<type::assoc_vector<K, V> > {
|
||||
void operator()(msgpack::object::with_zone& o, const type::assoc_vector<K,V>& v) const {
|
||||
o.type = msgpack::type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
V val;
|
||||
p->val.convert(val);
|
||||
tmp.insert(it, std::pair<K,V>(key, val));
|
||||
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);
|
||||
}
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::map<K,V>& v)
|
||||
{
|
||||
o.pack_map(v.size());
|
||||
for(typename std::map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename K, typename V>
|
||||
struct convert<std::map<K, V> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::map<K, V>& v) const {
|
||||
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 K, typename V>
|
||||
struct pack<std::map<K, V> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::map<K,V>& v) const {
|
||||
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);
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (object::with_zone& o, const std::map<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename std::map<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<std::map<K, V> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::map<K,V>& v) const {
|
||||
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 object const& operator>> (object const& o, std::multimap<K, V>& v)
|
||||
{
|
||||
if(o.type != type::MAP) { throw type_error(); }
|
||||
object_kv* p(o.via.map.ptr);
|
||||
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);
|
||||
struct convert<std::multimap<K, V> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::multimap<K, V>& v) const {
|
||||
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;
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::multimap<K,V>& v)
|
||||
{
|
||||
o.pack_map(v.size());
|
||||
for(typename std::multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename K, typename V>
|
||||
struct pack<std::multimap<K, V> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multimap<K,V>& v) const {
|
||||
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);
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (object::with_zone& o, const std::multimap<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename std::multimap<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<std::multimap<K, V> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::multimap<K,V>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,69 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
object const& operator>> (object const& o, type::assoc_vector<K,V>& v);
|
||||
template <typename Stream, typename K, typename V>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::assoc_vector<K,V>& v);
|
||||
template <typename K, typename V>
|
||||
void operator<< (object::with_zone& o, const type::assoc_vector<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
object const& operator>> (object const& o, std::map<K, V>& v);
|
||||
template <typename Stream, typename K, typename V>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::map<K,V>& v);
|
||||
template <typename K, typename V>
|
||||
void operator<< (object::with_zone& o, const std::map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
object const& operator>> (object const& o, std::multimap<K, V>& v);
|
||||
template <typename Stream, typename K, typename V>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::multimap<K,V>& v);
|
||||
template <typename K, typename V>
|
||||
void operator<< (object::with_zone& o, const std::multimap<K,V>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_MAP_HPP
|
@@ -1,29 +0,0 @@
|
||||
//
|
||||
// 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
|
@@ -19,11 +19,13 @@
|
||||
#define MSGPACK_TYPE_NIL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
@@ -31,37 +33,51 @@ struct nil { };
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
inline object const& operator>> (object const& o, type::nil&)
|
||||
{
|
||||
if(o.type != type::NIL) { throw type_error(); }
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const type::nil&)
|
||||
{
|
||||
o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, type::nil)
|
||||
{
|
||||
o.type = type::NIL;
|
||||
}
|
||||
|
||||
inline void operator<< (object::with_zone& o, type::nil v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
inline void object::as<void>() const
|
||||
struct convert<type::nil> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::nil&) const {
|
||||
if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); }
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<type::nil> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::nil&) const {
|
||||
o.pack_nil();
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object<type::nil> {
|
||||
void operator()(msgpack::object& o, type::nil) const {
|
||||
o.type = msgpack::type::NIL;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<type::nil> {
|
||||
void operator()(msgpack::object::with_zone& o, type::nil v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptror
|
||||
|
||||
template <>
|
||||
inline void msgpack::object::as<void>() const
|
||||
{
|
||||
msgpack::type::nil v;
|
||||
convert(v);
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,51 +0,0 @@
|
||||
//
|
||||
// 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
|
||||
|
||||
|
||||
object const& operator>> (object const& o, type::nil&);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::nil&);
|
||||
|
||||
void operator<< (object& o, type::nil);
|
||||
|
||||
void operator<< (object::with_zone& o, type::nil v);
|
||||
|
||||
template <>
|
||||
inline void object::as<void>() const;
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_NIL_FWD_HPP
|
@@ -19,44 +19,56 @@
|
||||
#define MSGPACK_TYPE_PAIR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T1, typename T2>
|
||||
inline object const& operator>> (object const& 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 o;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
struct convert<std::pair<T1, T2> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::pair<T1, T2>& v) const {
|
||||
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 T1, typename T2>
|
||||
inline void operator<< (object::with_zone& o, const std::pair<T1, T2>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(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);
|
||||
}
|
||||
struct pack<std::pair<T1, T2> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::pair<T1, T2>& v) const {
|
||||
o.pack_array(2);
|
||||
o.pack(v.first);
|
||||
o.pack(v.second);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T1, typename T2>
|
||||
struct object_with_zone<std::pair<T1, T2> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::pair<T1, T2>& v) const {
|
||||
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);
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,42 +0,0 @@
|
||||
//
|
||||
// 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_FWD_HPP
|
||||
#define MSGPACK_TYPE_PAIR_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <utility>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T1, typename T2>
|
||||
object const& operator>> (object const& o, std::pair<T1, T2>& v);
|
||||
|
||||
template <typename Stream, typename T1, typename T2>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::pair<T1, T2>& v);
|
||||
|
||||
template <typename T1, typename T2>
|
||||
void operator<< (object::with_zone& o, const std::pair<T1, T2>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_PAIR_FWD_HPP
|
@@ -19,13 +19,15 @@
|
||||
#define MSGPACK_TYPE_RAW_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <string.h>
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include <cstring>
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
@@ -40,7 +42,7 @@ struct raw_ref {
|
||||
|
||||
bool operator== (const raw_ref& x) const
|
||||
{
|
||||
return size == x.size && memcmp(ptr, x.ptr, size) == 0;
|
||||
return size == x.size && std::memcmp(ptr, x.ptr, size) == 0;
|
||||
}
|
||||
|
||||
bool operator!= (const raw_ref& x) const
|
||||
@@ -50,49 +52,63 @@ struct raw_ref {
|
||||
|
||||
bool operator< (const raw_ref& x) const
|
||||
{
|
||||
if(size == x.size) { return memcmp(ptr, x.ptr, size) < 0; }
|
||||
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 memcmp(ptr, x.ptr, size) > 0; }
|
||||
if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; }
|
||||
else { return size > x.size; }
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace type
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
inline object const& operator>> (object const& o, type::raw_ref& v)
|
||||
{
|
||||
if(o.type != type::BIN) { throw type_error(); }
|
||||
v.ptr = o.via.bin.ptr;
|
||||
v.size = o.via.bin.size;
|
||||
return o;
|
||||
}
|
||||
template <>
|
||||
struct convert<msgpack::type::raw_ref> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::type::raw_ref& v) const {
|
||||
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 packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v)
|
||||
{
|
||||
o.pack_bin(v.size);
|
||||
o.pack_bin_body(v.ptr, v.size);
|
||||
return o;
|
||||
}
|
||||
template <>
|
||||
struct pack<msgpack::type::raw_ref> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const msgpack::type::raw_ref& v) const {
|
||||
o.pack_bin(v.size);
|
||||
o.pack_bin_body(v.ptr, v.size);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, const type::raw_ref& v)
|
||||
{
|
||||
o.type = type::BIN;
|
||||
o.via.bin.ptr = v.ptr;
|
||||
o.via.bin.size = v.size;
|
||||
}
|
||||
template <>
|
||||
struct object<msgpack::type::raw_ref> {
|
||||
void operator()(msgpack::object& o, const msgpack::type::raw_ref& v) const {
|
||||
o.type = msgpack::type::BIN;
|
||||
o.via.bin.ptr = v.ptr;
|
||||
o.via.bin.size = v.size;
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (object::with_zone& o, const type::raw_ref& v)
|
||||
{ static_cast<object&>(o) << v; }
|
||||
template <>
|
||||
struct object_with_zone<msgpack::type::raw_ref> {
|
||||
void operator()(msgpack::object::with_zone& o, const msgpack::type::raw_ref& v) const {
|
||||
static_cast<msgpack::object&>(o) << v;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_RAW_HPP
|
||||
|
@@ -1,50 +0,0 @@
|
||||
//
|
||||
// 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_FWD_HPP
|
||||
#define MSGPACK_TYPE_RAW_FWD_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;
|
||||
|
||||
} // namespace type
|
||||
|
||||
|
||||
object const& operator>> (object const& o, type::raw_ref& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const type::raw_ref& v);
|
||||
|
||||
void operator<< (object& o, const type::raw_ref& v);
|
||||
|
||||
void operator<< (object::with_zone& o, const type::raw_ref& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_RAW_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// 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.
|
||||
@@ -19,110 +19,130 @@
|
||||
#define MSGPACK_TYPE_SET_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <set>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
inline object const& operator>> (object const& o, std::set<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
object* p = o.via.array.ptr + o.via.array.size;
|
||||
object* const pbegin = o.via.array.ptr;
|
||||
std::set<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
struct convert<std::set<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::set<T>& v) const {
|
||||
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;
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::set<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename std::set<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename T>
|
||||
struct pack<std::set<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::set<T>& v) const {
|
||||
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);
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::set<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename std::set<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<std::set<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::set<T>& v) const {
|
||||
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 object const& operator>> (object const& o, std::multiset<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
object* p = o.via.array.ptr + o.via.array.size;
|
||||
object* const pbegin = o.via.array.ptr;
|
||||
std::multiset<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
struct convert<std::multiset<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::multiset<T>& v) const {
|
||||
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;
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::multiset<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename std::multiset<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename T>
|
||||
struct pack<std::multiset<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::multiset<T>& v) const {
|
||||
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);
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::multiset<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename std::multiset<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<std::multiset<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::multiset<T>& v) const {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,52 +0,0 @@
|
||||
//
|
||||
// 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>
|
||||
object const& operator>> (object const& o, std::set<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const std::set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
object const& operator>> (object const& o, std::multiset<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::multiset<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const std::multiset<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_SET_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// 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.
|
||||
@@ -19,54 +19,75 @@
|
||||
#define MSGPACK_TYPE_STRING_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
inline object const& operator>> (object const& o, std::string& v)
|
||||
{
|
||||
switch (o.type) {
|
||||
case type::BIN:
|
||||
v.assign(o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case type::STR:
|
||||
v.assign(o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw type_error();
|
||||
break;
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<std::string> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::string& v) const {
|
||||
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;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v)
|
||||
{
|
||||
o.pack_str(v.size());
|
||||
o.pack_str_body(v.data(), v.size());
|
||||
return o;
|
||||
}
|
||||
template <>
|
||||
struct pack<std::string> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::string& v) const {
|
||||
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<< (object::with_zone& o, const std::string& v)
|
||||
{
|
||||
o.type = type::STR;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.size()));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = static_cast<uint32_t>(v.size());
|
||||
memcpy(ptr, v.data(), v.size());
|
||||
}
|
||||
template <>
|
||||
struct object<std::string> {
|
||||
void operator()(msgpack::object& o, const std::string& v) const {
|
||||
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;
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, const std::string& v)
|
||||
{
|
||||
o.type = type::STR;
|
||||
o.via.str.ptr = v.data();
|
||||
o.via.str.size = static_cast<uint32_t>(v.size());
|
||||
}
|
||||
template <>
|
||||
struct object_with_zone<std::string> {
|
||||
void operator()(msgpack::object::with_zone& o, const std::string& v) const {
|
||||
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());
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -1,42 +0,0 @@
|
||||
//
|
||||
// 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) {
|
||||
|
||||
object const& operator>> (object const& o, std::string& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::string& v);
|
||||
|
||||
void operator<< (object::with_zone& o, const std::string& v);
|
||||
|
||||
void operator<< (object& o, const std::string& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_STRING_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// 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.
|
||||
@@ -19,11 +19,12 @@
|
||||
#define MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#define MSGPACK_HAS_STD_UNOURDERED_MAP
|
||||
#define MSGPACK_HAS_STD_UNORDERED_MAP
|
||||
#include <unordered_map>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
@@ -31,7 +32,7 @@
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNOURDERED_MAP
|
||||
#define MSGPACK_HAS_STD_TR1_UNORDERED_MAP
|
||||
|
||||
#include <tr1/unordered_map>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
@@ -40,117 +41,139 @@
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if defined(MSGPACK_STD_TR1)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename K, typename V>
|
||||
inline object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_map<K, V>& v)
|
||||
{
|
||||
if(o.type != type::MAP) { throw type_error(); }
|
||||
object_kv* p(o.via.map.ptr);
|
||||
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]);
|
||||
struct convert<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_map<K, V>& v) const {
|
||||
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;
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v)
|
||||
{
|
||||
o.pack_map(v.size());
|
||||
for(typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename K, typename V>
|
||||
struct pack<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v) const {
|
||||
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);
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename MSGPACK_STD_TR1::unordered_map<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_map<K, V> > {
|
||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v) const {
|
||||
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 object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_multimap<K, V>& v)
|
||||
{
|
||||
if(o.type != type::MAP) { throw type_error(); }
|
||||
object_kv* p(o.via.map.ptr);
|
||||
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);
|
||||
struct convert<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multimap<K, V>& v) const {
|
||||
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;
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v)
|
||||
{
|
||||
o.pack_map(v.size());
|
||||
for(typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename K, typename V>
|
||||
struct pack<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v) const {
|
||||
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);
|
||||
o.pack(it->first);
|
||||
o.pack(it->second);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename K, typename V>
|
||||
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v)
|
||||
{
|
||||
o.type = type::MAP;
|
||||
if(v.empty()) {
|
||||
o.via.map.ptr = nullptr;
|
||||
o.via.map.size = 0;
|
||||
} else {
|
||||
object_kv* p = static_cast<object_kv*>(o.zone.allocate_align(sizeof(object_kv)*v.size()));
|
||||
object_kv* const pend = p + v.size();
|
||||
o.via.map.ptr = p;
|
||||
o.via.map.size = v.size();
|
||||
typename MSGPACK_STD_TR1::unordered_multimap<K,V>::const_iterator it(v.begin());
|
||||
do {
|
||||
p->key = object(it->first, o.zone);
|
||||
p->val = object(it->second, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_multimap<K, V> > {
|
||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v) const {
|
||||
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 adaptor
|
||||
|
||||
} // namespace msgpack
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#undef MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP
|
||||
|
@@ -1,72 +0,0 @@
|
||||
//
|
||||
// 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_UNOURDERED_MAP
|
||||
#include <unordered_map>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNOURDERED_MAP
|
||||
|
||||
#include <tr1/unordered_map>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename K, typename V>
|
||||
object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_map<K, V>& v);
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_multimap<K, V>& v);
|
||||
|
||||
template <typename Stream, typename K, typename V>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v);
|
||||
|
||||
template <typename K, typename V>
|
||||
void operator<< (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_TYPE_TR1_UNORDERED_MAP_FWD_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
|
||||
// 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.
|
||||
@@ -19,11 +19,12 @@
|
||||
#define MSGPACK_TYPE_TR1_UNORDERED_SET_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#define MSGPACK_HAS_STD_UNOURDERED_SET
|
||||
#define MSGPACK_HAS_STD_UNORDERED_SET
|
||||
#include <unordered_set>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
@@ -31,7 +32,7 @@
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNOURDERED_SET
|
||||
#define MSGPACK_HAS_STD_TR1_UNORDERED_SET
|
||||
|
||||
#include <tr1/unordered_set>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
@@ -40,109 +41,133 @@
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if defined(MSGPACK_STD_TR1)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
inline object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_set<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
object* p = o.via.array.ptr + o.via.array.size;
|
||||
object* const pbegin = o.via.array.ptr;
|
||||
MSGPACK_STD_TR1::unordered_set<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
struct convert<MSGPACK_STD_TR1::unordered_set<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_set<T>& v) const {
|
||||
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;
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename T>
|
||||
struct pack<MSGPACK_STD_TR1::unordered_set<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v) const {
|
||||
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);
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_set<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T>& v) const {
|
||||
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 object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_multiset<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
object* p = o.via.array.ptr + o.via.array.size;
|
||||
object* const pbegin = o.via.array.ptr;
|
||||
MSGPACK_STD_TR1::unordered_multiset<T> tmp;
|
||||
while(p > pbegin) {
|
||||
--p;
|
||||
tmp.insert(p->as<T>());
|
||||
struct convert<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multiset<T>& v) const {
|
||||
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;
|
||||
}
|
||||
tmp.swap(v);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename T>
|
||||
struct pack<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v) const {
|
||||
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);
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<MSGPACK_STD_TR1::unordered_multiset<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v) const {
|
||||
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 adaptor
|
||||
|
||||
} // namespace msgpack
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#undef MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_STD_TR1
|
||||
|
||||
#endif // MSGPACK_TYPE_TR1_UNORDERED_SET_HPP
|
||||
|
@@ -1,71 +0,0 @@
|
||||
//
|
||||
// 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_UNOURDERED_SET
|
||||
#include <unordered_set>
|
||||
#define MSGPACK_STD_TR1 std
|
||||
|
||||
#else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
#if __GNUC__ >= 4
|
||||
|
||||
#define MSGPACK_HAS_STD_TR1_UNOURDERED_SET
|
||||
|
||||
#include <tr1/unordered_set>
|
||||
#define MSGPACK_STD_TR1 std::tr1
|
||||
|
||||
#endif // __GNUC__ >= 4
|
||||
|
||||
#endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700)
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_set<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T>& v);
|
||||
|
||||
template <typename T>
|
||||
object const& operator>> (object const& o, MSGPACK_STD_TR1::unordered_multiset<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (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_TYPE_TR1_UNORDERED_SET_FWD_HPP
|
@@ -19,65 +19,81 @@
|
||||
#define MSGPACK_TYPE_VECTOR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
inline object const& operator>> (object const& o, std::vector<T>& v)
|
||||
{
|
||||
if(o.type != type::ARRAY) { throw type_error(); }
|
||||
v.resize(o.via.array.size);
|
||||
if(o.via.array.size > 0) {
|
||||
object* p = o.via.array.ptr;
|
||||
object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
T* it = &v[0];
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct convert<std::vector<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<T>& v) const {
|
||||
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;
|
||||
typename std::vector<T>::iterator it = v.begin();
|
||||
do {
|
||||
p->convert(*it);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v)
|
||||
{
|
||||
o.pack_array(v.size());
|
||||
for(typename std::vector<T>::const_iterator it(v.begin()), it_end(v.end());
|
||||
template <typename T>
|
||||
struct pack<std::vector<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<T>& v) const {
|
||||
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);
|
||||
o.pack(*it);
|
||||
}
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const std::vector<T>& v)
|
||||
{
|
||||
o.type = type::ARRAY;
|
||||
if(v.empty()) {
|
||||
o.via.array.ptr = nullptr;
|
||||
o.via.array.size = 0;
|
||||
} else {
|
||||
object* p = static_cast<object*>(o.zone.allocate_align(sizeof(object)*v.size()));
|
||||
object* const pend = p + v.size();
|
||||
o.via.array.ptr = p;
|
||||
o.via.array.size = v.size();
|
||||
typename std::vector<T>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = object(*it, o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
struct object_with_zone<std::vector<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::vector<T>& v) const {
|
||||
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 adaptor
|
||||
|
||||
} // namespace msgpack
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_HPP
|
||||
|
96
include/msgpack/adaptor/vector_bool.hpp
Normal file
96
include/msgpack/adaptor/vector_bool.hpp
Normal file
@@ -0,0 +1,96 @@
|
||||
//
|
||||
// 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 {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<std::vector<bool> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<bool>& v) const {
|
||||
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 <>
|
||||
struct pack<std::vector<bool> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<bool>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_array(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;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<std::vector<bool> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::vector<bool>& v) const {
|
||||
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;
|
||||
std::vector<bool>::const_iterator it(v.begin());
|
||||
do {
|
||||
*p = msgpack::object(static_cast<bool>(*it), o.zone);
|
||||
++p;
|
||||
++it;
|
||||
} while(p < pend);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_BOOL_HPP
|
@@ -1,7 +1,7 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2014 KONDO Takatoshi
|
||||
// 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.
|
||||
@@ -19,58 +19,79 @@
|
||||
#define MSGPACK_TYPE_VECTOR_CHAR_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/check_container_size.hpp"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
inline object const& operator>> (object const& o, std::vector<char>& v)
|
||||
{
|
||||
switch (o.type) {
|
||||
case type::BIN:
|
||||
v.resize(o.via.bin.size);
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case type::STR:
|
||||
v.resize(o.via.str.size);
|
||||
std::memcpy(v.data(), o.via.str.ptr, o.via.str.size);
|
||||
break;
|
||||
default:
|
||||
throw type_error();
|
||||
break;
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<std::vector<char> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::vector<char>& v) const {
|
||||
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;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const std::vector<char>& v)
|
||||
{
|
||||
o.pack_bin(v.size());
|
||||
o.pack_bin_body(v.data(), v.size());
|
||||
template <>
|
||||
struct pack<std::vector<char> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const std::vector<char>& v) const {
|
||||
uint32_t size = checked_get_container_size(v.size());
|
||||
o.pack_bin(size);
|
||||
o.pack_bin_body(&v.front(), size);
|
||||
|
||||
return o;
|
||||
}
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
inline void operator<< (object& o, const std::vector<char>& v)
|
||||
{
|
||||
o.type = type::BIN;
|
||||
o.via.bin.ptr = v.data();
|
||||
o.via.bin.size = static_cast<uint32_t>(v.size());
|
||||
}
|
||||
template <>
|
||||
struct object<std::vector<char> > {
|
||||
void operator()(msgpack::object& o, const std::vector<char>& v) const {
|
||||
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<< (object::with_zone& o, const std::vector<char>& v)
|
||||
{
|
||||
o.type = type::BIN;
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.size()));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = static_cast<uint32_t>(v.size());
|
||||
std::memcpy(ptr, v.data(), v.size());
|
||||
}
|
||||
template <>
|
||||
struct object_with_zone<std::vector<char> > {
|
||||
void operator()(msgpack::object::with_zone& o, const std::vector<char>& v) const {
|
||||
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 adaptor
|
||||
|
||||
} // namespace msgpack
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_CHAR_HPP
|
||||
|
@@ -1,42 +0,0 @@
|
||||
//
|
||||
// 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) {
|
||||
|
||||
object const& operator>> (object const& o, std::vector<char>& v);
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::vector<char>& v);
|
||||
|
||||
void operator<< (object& o, const std::vector<char>& v);
|
||||
|
||||
void operator<< (object::with_zone& o, const std::vector<char>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP
|
@@ -1,42 +0,0 @@
|
||||
//
|
||||
// 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_FWD_HPP
|
||||
#define MSGPACK_TYPE_VECTOR_FWD_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include <vector>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
template <typename T>
|
||||
object const& operator>> (object const& o, std::vector<T>& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const std::vector<T>& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const std::vector<T>& v);
|
||||
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_TYPE_VECTOR_FWD_HPP
|
@@ -35,14 +35,18 @@
|
||||
#if __cplusplus < 201103
|
||||
|
||||
#if !defined(nullptr)
|
||||
#define nullptr (0)
|
||||
# if _MSC_VER < 1600
|
||||
# define nullptr (0)
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
template <typename T>
|
||||
struct unique_ptr : std::auto_ptr<T> {
|
||||
@@ -73,7 +77,9 @@ template <typename T>
|
||||
struct enable_if<false, T> {
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
@@ -84,7 +90,9 @@ struct enable_if<false, T> {
|
||||
#include <tuple>
|
||||
|
||||
namespace msgpack {
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
// unique_ptr
|
||||
using std::unique_ptr;
|
||||
@@ -96,7 +104,9 @@ MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
using std::swap;
|
||||
using std::enable_if;
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
} // namespace msgpack
|
||||
|
||||
|
||||
|
@@ -29,13 +29,15 @@
|
||||
#endif
|
||||
|
||||
#ifndef MSGPACK_ZONE_ALIGN
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(int)
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(void*)
|
||||
#endif
|
||||
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
class zone {
|
||||
struct finalizer {
|
||||
@@ -150,7 +152,7 @@ public:
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
|
||||
|
||||
public:
|
||||
void* allocate_align(size_t size);
|
||||
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);
|
||||
@@ -161,24 +163,25 @@ public:
|
||||
void clear();
|
||||
|
||||
void swap(zone& o);
|
||||
static void* operator new(std::size_t size) throw(std::bad_alloc)
|
||||
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()
|
||||
static void operator delete(void *p) /* throw() */
|
||||
{
|
||||
::free(p);
|
||||
}
|
||||
static void* operator new(std::size_t size, void* place) throw()
|
||||
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()
|
||||
static void operator delete(void* p, void* place) /* throw() */
|
||||
{
|
||||
::operator delete(p, place);
|
||||
}
|
||||
/// @cond
|
||||
|
||||
template <typename T>
|
||||
T* allocate();
|
||||
@@ -228,6 +231,7 @@ public:
|
||||
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10, typename A11, typename A12, typename A13, typename A14, typename A15>
|
||||
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11, A12 a12, A13 a13, A14 a14, A15 a15);
|
||||
|
||||
/// @endcond
|
||||
|
||||
private:
|
||||
void undo_allocate(size_t size);
|
||||
@@ -239,16 +243,30 @@ private:
|
||||
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)
|
||||
inline void* zone::allocate_align(size_t size, size_t align)
|
||||
{
|
||||
return allocate_no_align(
|
||||
((size)+((MSGPACK_ZONE_ALIGN)-1)) & ~((MSGPACK_ZONE_ALIGN)-1));
|
||||
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)
|
||||
@@ -271,7 +289,12 @@ inline void* zone::allocate_expand(size_t size)
|
||||
size_t sz = m_chunk_size;
|
||||
|
||||
while(sz < size) {
|
||||
sz *= 2;
|
||||
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));
|
||||
@@ -306,7 +329,10 @@ inline void zone::clear()
|
||||
|
||||
inline void zone::swap(zone& o)
|
||||
{
|
||||
std::swap(*this, 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>
|
||||
@@ -327,6 +353,7 @@ inline void zone::undo_allocate(size_t size)
|
||||
m_chunk_list.m_free += size;
|
||||
}
|
||||
|
||||
/// @cond
|
||||
|
||||
template <typename T>
|
||||
T* zone::allocate()
|
||||
@@ -632,8 +659,11 @@ T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9,
|
||||
}
|
||||
}
|
||||
|
||||
/// @endcond
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -31,12 +31,14 @@
|
||||
#endif
|
||||
|
||||
#ifndef MSGPACK_ZONE_ALIGN
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(int)
|
||||
#define MSGPACK_ZONE_ALIGN sizeof(void*)
|
||||
#endif
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
class zone {
|
||||
private:
|
||||
@@ -96,14 +98,14 @@ private:
|
||||
++m_tail;
|
||||
}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
finalizer_array(finalizer_array&& other)
|
||||
finalizer_array(finalizer_array&& other) noexcept
|
||||
:m_tail(other.m_tail), m_end(other.m_end), m_array(other.m_array)
|
||||
{
|
||||
other.m_tail = nullptr;
|
||||
other.m_end = nullptr;
|
||||
other.m_array = nullptr;
|
||||
}
|
||||
finalizer_array& operator=(finalizer_array&& other)
|
||||
finalizer_array& operator=(finalizer_array&& other) noexcept
|
||||
{
|
||||
this->~finalizer_array();
|
||||
new (this) finalizer_array(std::move(other));
|
||||
@@ -161,12 +163,12 @@ private:
|
||||
m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
|
||||
}
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
chunk_list(chunk_list&& other)
|
||||
chunk_list(chunk_list&& other) noexcept
|
||||
:m_free(other.m_free), m_ptr(other.m_ptr), m_head(other.m_head)
|
||||
{
|
||||
other.m_head = nullptr;
|
||||
}
|
||||
chunk_list& operator=(chunk_list&& other)
|
||||
chunk_list& operator=(chunk_list&& other) noexcept
|
||||
{
|
||||
this->~chunk_list();
|
||||
new (this) chunk_list(std::move(other));
|
||||
@@ -188,7 +190,7 @@ public:
|
||||
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) noexcept;
|
||||
|
||||
public:
|
||||
void* allocate_align(size_t size);
|
||||
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);
|
||||
@@ -224,11 +226,11 @@ public:
|
||||
|
||||
zone(zone&&) = default;
|
||||
zone& operator=(zone&&) = default;
|
||||
zone(const zone&) = delete;
|
||||
zone& operator=(const zone&) = delete;
|
||||
|
||||
private:
|
||||
void undo_allocate(size_t size);
|
||||
zone(const zone&);
|
||||
zone& operator=(const zone&);
|
||||
|
||||
template <typename T>
|
||||
static void object_destruct(void* obj);
|
||||
@@ -243,10 +245,21 @@ inline zone::zone(size_t chunk_size) noexcept:m_chunk_size(chunk_size), m_chunk_
|
||||
{
|
||||
}
|
||||
|
||||
inline void* zone::allocate_align(size_t size)
|
||||
inline void* zone::allocate_align(size_t size, size_t align)
|
||||
{
|
||||
return allocate_no_align(
|
||||
((size)+((MSGPACK_ZONE_ALIGN)-1)) & ~((MSGPACK_ZONE_ALIGN)-1));
|
||||
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)
|
||||
@@ -269,7 +282,12 @@ inline void* zone::allocate_expand(size_t size)
|
||||
size_t sz = m_chunk_size;
|
||||
|
||||
while(sz < size) {
|
||||
sz *= 2;
|
||||
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));
|
||||
@@ -345,7 +363,9 @@ T* zone::allocate(Args... args)
|
||||
}
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -15,8 +15,8 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
#ifndef MSGPACK_FBUFFER_H__
|
||||
#define MSGPACK_FBUFFER_H__
|
||||
#ifndef MSGPACK_FBUFFER_H
|
||||
#define MSGPACK_FBUFFER_H
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
@@ -44,4 +44,3 @@ static inline int msgpack_fbuffer_write(void* data, const char* buf, unsigned in
|
||||
#endif
|
||||
|
||||
#endif /* msgpack/fbuffer.h */
|
||||
|
||||
|
@@ -25,7 +25,9 @@
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
class fbuffer {
|
||||
public:
|
||||
@@ -44,15 +46,22 @@ public:
|
||||
return m_file;
|
||||
}
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
private:
|
||||
fbuffer(const fbuffer&);
|
||||
fbuffer& operator= (const fbuffer&);
|
||||
fbuffer& operator=(const fbuffer&);
|
||||
#else // defined(MSGPACK_USE_CPP03)
|
||||
fbuffer(const fbuffer&) = delete;
|
||||
fbuffer& operator=(const fbuffer&) = delete;
|
||||
#endif // defined(MSGPACK_USE_CPP03)
|
||||
|
||||
private:
|
||||
FILE* m_file;
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
46
include/msgpack/iterator.hpp
Normal file
46
include/msgpack/iterator.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution routine
|
||||
//
|
||||
// Copyright (C) 2015 MIZUKI Hirata
|
||||
//
|
||||
// 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_ITERATOR_HPP
|
||||
#define MSGPACK_ITERATOR_HPP
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
#include <msgpack/object_fwd.hpp>
|
||||
|
||||
namespace msgpack
|
||||
{
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
{
|
||||
/// @endcond
|
||||
inline object_kv* begin(object_map &map) { return map.ptr; }
|
||||
inline const object_kv* begin(const object_map &map) { return map.ptr; }
|
||||
inline object_kv* end(object_map &map) { return map.ptr + map.size; }
|
||||
inline const object_kv* end(const object_map &map) { return map.ptr + map.size; }
|
||||
|
||||
inline object* begin(object_array &array) { return array.ptr; }
|
||||
inline const object* begin(const object_array &array) { return array.ptr; }
|
||||
inline object* end(object_array &array) { return array.ptr + array.size; }
|
||||
inline const object* end(const object_array &array) { return array.ptr + array.size; }
|
||||
/// @cond
|
||||
}
|
||||
/// @endcond
|
||||
}
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
#endif // MSGPACK_ITERATOR_HPP
|
@@ -37,7 +37,10 @@ typedef enum {
|
||||
MSGPACK_OBJECT_BOOLEAN = 0x01,
|
||||
MSGPACK_OBJECT_POSITIVE_INTEGER = 0x02,
|
||||
MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x03,
|
||||
MSGPACK_OBJECT_DOUBLE = 0x04,
|
||||
MSGPACK_OBJECT_FLOAT = 0x04,
|
||||
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
|
||||
MSGPACK_OBJECT_DOUBLE = MSGPACK_OBJECT_FLOAT, /* obsolete */
|
||||
#endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */
|
||||
MSGPACK_OBJECT_STR = 0x05,
|
||||
MSGPACK_OBJECT_ARRAY = 0x06,
|
||||
MSGPACK_OBJECT_MAP = 0x07,
|
||||
@@ -79,7 +82,10 @@ typedef union {
|
||||
bool boolean;
|
||||
uint64_t u64;
|
||||
int64_t i64;
|
||||
double dec;
|
||||
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
|
||||
double dec; /* obsolete*/
|
||||
#endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */
|
||||
double f64;
|
||||
msgpack_object_array array;
|
||||
msgpack_object_map map;
|
||||
msgpack_object_str str;
|
||||
@@ -97,9 +103,10 @@ typedef struct msgpack_object_kv {
|
||||
msgpack_object val;
|
||||
} msgpack_object_kv;
|
||||
|
||||
|
||||
MSGPACK_DLLEXPORT
|
||||
void msgpack_object_print(FILE* out, msgpack_object o);
|
||||
|
||||
MSGPACK_DLLEXPORT
|
||||
bool msgpack_object_equal(const msgpack_object x, const msgpack_object y);
|
||||
|
||||
/** @} */
|
||||
@@ -110,4 +117,3 @@ bool msgpack_object_equal(const msgpack_object x, const msgpack_object y);
|
||||
#endif
|
||||
|
||||
#endif /* msgpack/object.h */
|
||||
|
||||
|
@@ -19,52 +19,22 @@
|
||||
#define MSGPACK_OBJECT_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/object_fwd.hpp"
|
||||
#include "msgpack/pack.hpp"
|
||||
#include "msgpack/zone.hpp"
|
||||
#include "msgpack/adaptor/int_fwd.hpp"
|
||||
#include "msgpack/adaptor/bool_fwd.hpp"
|
||||
#include "msgpack/adaptor/char_ptr_fwd.hpp"
|
||||
#include "msgpack/adaptor/deque_fwd.hpp"
|
||||
#include "msgpack/adaptor/fixint_fwd.hpp"
|
||||
#include "msgpack/adaptor/float_fwd.hpp"
|
||||
#include "msgpack/adaptor/int_fwd.hpp"
|
||||
#include "msgpack/adaptor/list_fwd.hpp"
|
||||
#include "msgpack/adaptor/map_fwd.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple_fwd.hpp"
|
||||
#include "msgpack/adaptor/nil_fwd.hpp"
|
||||
#include "msgpack/adaptor/pair_fwd.hpp"
|
||||
#include "msgpack/adaptor/raw_fwd.hpp"
|
||||
#include "msgpack/adaptor/set_fwd.hpp"
|
||||
#include "msgpack/adaptor/string_fwd.hpp"
|
||||
#include "msgpack/adaptor/vector_fwd.hpp"
|
||||
#include "msgpack/adaptor/vector_char_fwd.hpp"
|
||||
#include "msgpack/adaptor/tr1/unordered_map_fwd.hpp"
|
||||
#include "msgpack/adaptor/tr1/unordered_set_fwd.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
#include "adaptor/cpp11/array_fwd.hpp"
|
||||
#include "adaptor/cpp11/array_char_fwd.hpp"
|
||||
#include "adaptor/cpp11/forward_list_fwd.hpp"
|
||||
#include "adaptor/cpp11/tuple_fwd.hpp"
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
#include <string.h>
|
||||
#include <cstring>
|
||||
#include <stdexcept>
|
||||
#include <typeinfo>
|
||||
#include <limits>
|
||||
#include <ostream>
|
||||
#include <typeinfo>
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
|
||||
struct object::with_zone : object {
|
||||
with_zone(msgpack::zone& zone) : zone(zone) { }
|
||||
msgpack::zone& zone;
|
||||
private:
|
||||
with_zone();
|
||||
};
|
||||
/// @endcond
|
||||
|
||||
struct object::implicit_type {
|
||||
implicit_type(object const& o) : obj(o) { }
|
||||
@@ -74,52 +44,211 @@ struct object::implicit_type {
|
||||
operator T() { return obj.as<T>(); }
|
||||
|
||||
private:
|
||||
object const& obj;
|
||||
msgpack::object const& obj;
|
||||
};
|
||||
|
||||
inline object const& operator>> (object const& o, object& v)
|
||||
{
|
||||
v = o;
|
||||
namespace detail {
|
||||
template <typename Stream, typename T>
|
||||
struct packer_serializer {
|
||||
static msgpack::packer<Stream>& pack(msgpack::packer<Stream>& o, const T& v) {
|
||||
v.msgpack_pack(o);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
} // namespace detail
|
||||
|
||||
// Adaptor functors' member functions definitions.
|
||||
template <typename T>
|
||||
inline
|
||||
msgpack::object const&
|
||||
msgpack::adaptor::convert<T>::operator()(msgpack::object const& o, T& v) const {
|
||||
v.msgpack_unpack(o.convert());
|
||||
return o;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline object const& operator>> (object const& o, T& v)
|
||||
{
|
||||
// If you get a error 'class your_class has no member named 'msgpack_unpack',
|
||||
// check the following:
|
||||
// 1. The class your_class should have MSGPACK_DEFINE macro or
|
||||
//
|
||||
// 2. The class your_class should have the following operator declaration and
|
||||
// definition:
|
||||
// inline object const& operator>> (object const& o, std::string& v)
|
||||
//
|
||||
// See 3.
|
||||
//
|
||||
// 3. #include "msgpack.hpp" too early.
|
||||
// Replace msgpack.hpp with msgpack_fwd.hpp, then,
|
||||
// place operator declarations as follows:
|
||||
//
|
||||
// namespace msgpack {
|
||||
// MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||
// object const& operator>> (object const& o, std::string& v);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// then, #include "msgpack.hpp", finally place the operator definitions as follows:
|
||||
//
|
||||
// namespace msgpack {
|
||||
// MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||
// object const& operator>> (object const& o, std::string& v) {
|
||||
// // converting operations here
|
||||
// }
|
||||
// } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
// } // namespace msgpack
|
||||
//
|
||||
v.msgpack_unpack(o.convert());
|
||||
return o;
|
||||
template <typename Stream>
|
||||
inline
|
||||
msgpack::packer<Stream>&
|
||||
msgpack::adaptor::pack<T>::operator()(msgpack::packer<Stream>& o, T const& v) const {
|
||||
return detail::packer_serializer<Stream, T>::pack(o, v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline
|
||||
void
|
||||
msgpack::adaptor::object_with_zone<T>::operator()(msgpack::object::with_zone& o, T const& v) const {
|
||||
v.msgpack_object(static_cast<msgpack::object*>(&o), o.zone);
|
||||
}
|
||||
|
||||
// Adaptor functor specialization to object
|
||||
namespace adaptor {
|
||||
|
||||
template <>
|
||||
struct convert<msgpack::object> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, msgpack::object& v) const {
|
||||
v = o;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct pack<msgpack::object> {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, msgpack::object const& v) const {
|
||||
switch(v.type) {
|
||||
case msgpack::type::NIL:
|
||||
o.pack_nil();
|
||||
return o;
|
||||
|
||||
case msgpack::type::BOOLEAN:
|
||||
if(v.via.boolean) {
|
||||
o.pack_true();
|
||||
} else {
|
||||
o.pack_false();
|
||||
}
|
||||
return o;
|
||||
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
o.pack_uint64(v.via.u64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
o.pack_int64(v.via.i64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::FLOAT:
|
||||
o.pack_double(v.via.f64);
|
||||
return o;
|
||||
|
||||
case msgpack::type::STR:
|
||||
o.pack_str(v.via.str.size);
|
||||
o.pack_str_body(v.via.str.ptr, v.via.str.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::BIN:
|
||||
o.pack_bin(v.via.bin.size);
|
||||
o.pack_bin_body(v.via.bin.ptr, v.via.bin.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::EXT:
|
||||
o.pack_ext(v.via.ext.size, v.via.ext.type());
|
||||
o.pack_ext_body(v.via.ext.data(), v.via.ext.size);
|
||||
return o;
|
||||
|
||||
case msgpack::type::ARRAY:
|
||||
o.pack_array(v.via.array.size);
|
||||
for(msgpack::object* p(v.via.array.ptr),
|
||||
* const pend(v.via.array.ptr + v.via.array.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, *p);
|
||||
}
|
||||
return o;
|
||||
|
||||
case msgpack::type::MAP:
|
||||
o.pack_map(v.via.map.size);
|
||||
for(msgpack::object_kv* p(v.via.map.ptr),
|
||||
* const pend(v.via.map.ptr + v.via.map.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, p->key);
|
||||
msgpack::operator<<(o, p->val);
|
||||
}
|
||||
return o;
|
||||
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::object> {
|
||||
void operator()(msgpack::object::with_zone& o, msgpack::object const& v) const {
|
||||
o.type = v.type;
|
||||
|
||||
switch(v.type) {
|
||||
case msgpack::type::NIL:
|
||||
case msgpack::type::BOOLEAN:
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
case msgpack::type::FLOAT:
|
||||
std::memcpy(&o.via, &v.via, sizeof(v.via));
|
||||
return;
|
||||
|
||||
case msgpack::type::STR: {
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.via.str.size));
|
||||
o.via.str.ptr = ptr;
|
||||
o.via.str.size = v.via.str.size;
|
||||
std::memcpy(ptr, v.via.str.ptr, v.via.str.size);
|
||||
return;
|
||||
}
|
||||
|
||||
case msgpack::type::BIN: {
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.via.bin.size));
|
||||
o.via.bin.ptr = ptr;
|
||||
o.via.bin.size = v.via.bin.size;
|
||||
std::memcpy(ptr, v.via.bin.ptr, v.via.bin.size);
|
||||
return;
|
||||
}
|
||||
|
||||
case msgpack::type::EXT: {
|
||||
char* ptr = static_cast<char*>(o.zone.allocate_align(v.via.ext.size + 1));
|
||||
o.via.ext.ptr = ptr;
|
||||
o.via.ext.size = v.via.ext.size;
|
||||
std::memcpy(ptr, v.via.ext.ptr, v.via.ext.size + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
case msgpack::type::ARRAY:
|
||||
o.via.array.ptr = static_cast<msgpack::object*>(o.zone.allocate_align(sizeof(msgpack::object) * v.via.array.size));
|
||||
o.via.array.size = v.via.array.size;
|
||||
for (msgpack::object
|
||||
* po(o.via.array.ptr),
|
||||
* pv(v.via.array.ptr),
|
||||
* const pvend(v.via.array.ptr + v.via.array.size);
|
||||
pv < pvend;
|
||||
++po, ++pv) {
|
||||
new (po) msgpack::object(*pv, o.zone);
|
||||
}
|
||||
return;
|
||||
|
||||
case msgpack::type::MAP:
|
||||
o.via.map.ptr = (msgpack::object_kv*)o.zone.allocate_align(sizeof(msgpack::object_kv) * v.via.map.size);
|
||||
o.via.map.size = v.via.map.size;
|
||||
for(msgpack::object_kv
|
||||
* po(o.via.map.ptr),
|
||||
* pv(v.via.map.ptr),
|
||||
* const pvend(v.via.map.ptr + v.via.map.size);
|
||||
pv < pvend;
|
||||
++po, ++pv) {
|
||||
msgpack::object_kv* kv = new (po) msgpack::object_kv;
|
||||
new (&kv->key) msgpack::object(pv->key, o.zone);
|
||||
new (&kv->val) msgpack::object(pv->val, o.zone);
|
||||
}
|
||||
return;
|
||||
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Adaptor functor specialization to object::with_zone
|
||||
|
||||
template <>
|
||||
struct object_with_zone<msgpack::object::with_zone> {
|
||||
void operator()(
|
||||
msgpack::object::with_zone& o,
|
||||
msgpack::object::with_zone const& v) const {
|
||||
o << static_cast<msgpack::object const&>(v);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
|
||||
// obsolete
|
||||
template <typename Type>
|
||||
class define : public Type {
|
||||
@@ -142,115 +271,57 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template <typename Stream, typename T>
|
||||
struct packer_serializer {
|
||||
static packer<Stream>& pack(packer<Stream>& o, const T& v) {
|
||||
// If you get a error 'const class your_class has no member named 'msgpack_pack',
|
||||
// check the following:
|
||||
// 1. The class your_class should have MSGPACK_DEFINE macro or
|
||||
//
|
||||
// 2. The class your_class should have the following operator declaration and
|
||||
// definition:
|
||||
//
|
||||
// namespace msgpack {
|
||||
// MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||
// template <typename Stream>
|
||||
// inline packer<Stream>& operator<< (packer<Stream>& o, const your_class& v)
|
||||
// } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
// } // namespace msgpack
|
||||
//
|
||||
// See 3.
|
||||
//
|
||||
// 3. #include "msgpack.hpp" too early.
|
||||
// Replace msgpack.hpp with msgpack_fwd.hpp, then,
|
||||
// place operator declarations as follows:
|
||||
//
|
||||
// namespace msgpack {
|
||||
// MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) {
|
||||
// template <typename Stream>
|
||||
// packer<Stream>& operator<< (packer<Stream>& o, const your_class& v);
|
||||
// } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
// } // namespace msgpack
|
||||
//
|
||||
// then, #include "msgpack.hpp", finally place the operator definitions as follows:
|
||||
//
|
||||
// template <typename Stream>
|
||||
// inline packer<Stream>& operator<< (packer<Stream>& o, const your_class& v) {
|
||||
// // packing operation
|
||||
// }
|
||||
// } // MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS)
|
||||
// } // namespace msgpack
|
||||
//
|
||||
v.msgpack_pack(o);
|
||||
return o;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// serialize operator
|
||||
template <typename Stream, typename T>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const T& v)
|
||||
{
|
||||
return detail::packer_serializer<Stream, T>::pack(o, v);
|
||||
}
|
||||
|
||||
// deconvert operator
|
||||
template <typename T>
|
||||
inline void operator<< (object::with_zone& o, const T& v)
|
||||
{
|
||||
v.msgpack_object(static_cast<object*>(&o), o.zone);
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
template <typename T>
|
||||
inline packer<Stream>& packer<Stream>::pack(const T& v)
|
||||
inline msgpack::packer<Stream>& packer<Stream>::pack(const T& v)
|
||||
{
|
||||
msgpack::operator<<(*this, v);
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline bool operator==(const object& x, const object& y)
|
||||
inline bool operator==(const msgpack::object& x, const msgpack::object& y)
|
||||
{
|
||||
if(x.type != y.type) { return false; }
|
||||
|
||||
switch(x.type) {
|
||||
case type::NIL:
|
||||
case msgpack::type::NIL:
|
||||
return true;
|
||||
|
||||
case type::BOOLEAN:
|
||||
case msgpack::type::BOOLEAN:
|
||||
return x.via.boolean == y.via.boolean;
|
||||
|
||||
case type::POSITIVE_INTEGER:
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
return x.via.u64 == y.via.u64;
|
||||
|
||||
case type::NEGATIVE_INTEGER:
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
return x.via.i64 == y.via.i64;
|
||||
|
||||
case type::DOUBLE:
|
||||
return x.via.dec == y.via.dec;
|
||||
case msgpack::type::FLOAT:
|
||||
return x.via.f64 == y.via.f64;
|
||||
|
||||
case type::STR:
|
||||
case msgpack::type::STR:
|
||||
return x.via.str.size == y.via.str.size &&
|
||||
memcmp(x.via.str.ptr, y.via.str.ptr, x.via.str.size) == 0;
|
||||
std::memcmp(x.via.str.ptr, y.via.str.ptr, x.via.str.size) == 0;
|
||||
|
||||
case type::BIN:
|
||||
case msgpack::type::BIN:
|
||||
return x.via.bin.size == y.via.bin.size &&
|
||||
memcmp(x.via.bin.ptr, y.via.bin.ptr, x.via.bin.size) == 0;
|
||||
std::memcmp(x.via.bin.ptr, y.via.bin.ptr, x.via.bin.size) == 0;
|
||||
|
||||
case type::EXT:
|
||||
case msgpack::type::EXT:
|
||||
return x.via.ext.size == y.via.ext.size &&
|
||||
memcmp(x.via.ext.ptr, y.via.ext.ptr, x.via.ext.size) == 0;
|
||||
std::memcmp(x.via.ext.ptr, y.via.ext.ptr, x.via.ext.size) == 0;
|
||||
|
||||
case type::ARRAY:
|
||||
case msgpack::type::ARRAY:
|
||||
if(x.via.array.size != y.via.array.size) {
|
||||
return false;
|
||||
} else if(x.via.array.size == 0) {
|
||||
return true;
|
||||
} else {
|
||||
object* px = x.via.array.ptr;
|
||||
object* const pxend = x.via.array.ptr + x.via.array.size;
|
||||
object* py = y.via.array.ptr;
|
||||
msgpack::object* px = x.via.array.ptr;
|
||||
msgpack::object* const pxend = x.via.array.ptr + x.via.array.size;
|
||||
msgpack::object* py = y.via.array.ptr;
|
||||
do {
|
||||
if(!(*px == *py)) {
|
||||
return false;
|
||||
@@ -261,15 +332,15 @@ inline bool operator==(const object& x, const object& y)
|
||||
return true;
|
||||
}
|
||||
|
||||
case type::MAP:
|
||||
case msgpack::type::MAP:
|
||||
if(x.via.map.size != y.via.map.size) {
|
||||
return false;
|
||||
} else if(x.via.map.size == 0) {
|
||||
return true;
|
||||
} else {
|
||||
object_kv* px = x.via.map.ptr;
|
||||
object_kv* const pxend = x.via.map.ptr + x.via.map.size;
|
||||
object_kv* py = y.via.map.ptr;
|
||||
msgpack::object_kv* px = x.via.map.ptr;
|
||||
msgpack::object_kv* const pxend = x.via.map.ptr + x.via.map.size;
|
||||
msgpack::object_kv* py = y.via.map.ptr;
|
||||
do {
|
||||
if(!(px->key == py->key) || !(px->val == py->val)) {
|
||||
return false;
|
||||
@@ -286,32 +357,32 @@ inline bool operator==(const object& x, const object& y)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const object& x, const T& y)
|
||||
inline bool operator==(const msgpack::object& x, const T& y)
|
||||
try {
|
||||
return x == object(y);
|
||||
return x == msgpack::object(y);
|
||||
} catch (msgpack::type_error&) {
|
||||
return false;
|
||||
}
|
||||
|
||||
inline bool operator!=(const object& x, const object& y)
|
||||
inline bool operator!=(const msgpack::object& x, const msgpack::object& y)
|
||||
{ return !(x == y); }
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(const T& y, const object x)
|
||||
inline bool operator==(const T& y, const msgpack::object x)
|
||||
{ return x == y; }
|
||||
|
||||
template <typename T>
|
||||
inline bool operator!=(const object& x, const T& y)
|
||||
inline bool operator!=(const msgpack::object& x, const T& y)
|
||||
{ return !(x == y); }
|
||||
|
||||
template <typename T>
|
||||
inline bool operator!=(const T& y, const object& x)
|
||||
inline bool operator!=(const T& y, const msgpack::object& x)
|
||||
{ return x != y; }
|
||||
|
||||
|
||||
inline object::implicit_type object::convert() const
|
||||
inline msgpack::object::implicit_type object::convert() const
|
||||
{
|
||||
return implicit_type(*this);
|
||||
return msgpack::object::implicit_type(*this);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -337,7 +408,7 @@ inline T object::as() const
|
||||
|
||||
inline object::object()
|
||||
{
|
||||
type = type::NIL;
|
||||
type = msgpack::type::NIL;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
@@ -354,7 +425,7 @@ inline object& object::operator=(const T& v)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
object::object(const T& v, zone& z)
|
||||
object::object(const T& v, msgpack::zone& z)
|
||||
{
|
||||
with_zone oz(z);
|
||||
msgpack::operator<<(oz, v);
|
||||
@@ -363,7 +434,7 @@ object::object(const T& v, zone& z)
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
object::object(const T& v, zone* z)
|
||||
object::object(const T& v, msgpack::zone* z)
|
||||
{
|
||||
with_zone oz(*z);
|
||||
msgpack::operator<<(oz, v);
|
||||
@@ -372,58 +443,58 @@ object::object(const T& v, zone* z)
|
||||
}
|
||||
|
||||
|
||||
inline object::object(msgpack_object o)
|
||||
inline object::object(const msgpack_object& o)
|
||||
{
|
||||
// FIXME beter way?
|
||||
::memcpy(this, &o, sizeof(o));
|
||||
std::memcpy(this, &o, sizeof(o));
|
||||
}
|
||||
|
||||
inline void operator<< (object& o, msgpack_object v)
|
||||
inline void operator<< (msgpack::object& o, const msgpack_object& v)
|
||||
{
|
||||
// FIXME beter way?
|
||||
::memcpy(&o, &v, sizeof(v));
|
||||
std::memcpy(&o, &v, sizeof(v));
|
||||
}
|
||||
|
||||
inline object::operator msgpack_object() const
|
||||
{
|
||||
// FIXME beter way?
|
||||
msgpack_object obj;
|
||||
::memcpy(&obj, this, sizeof(obj));
|
||||
std::memcpy(&obj, this, sizeof(obj));
|
||||
return obj;
|
||||
}
|
||||
|
||||
|
||||
// obsolete
|
||||
template <typename T>
|
||||
inline void convert(T& v, object const& o)
|
||||
inline void convert(T& v, msgpack::object const& o)
|
||||
{
|
||||
o.convert(v);
|
||||
}
|
||||
|
||||
// obsolete
|
||||
template <typename Stream, typename T>
|
||||
inline void pack(packer<Stream>& o, const T& v)
|
||||
inline void pack(msgpack::packer<Stream>& o, const T& v)
|
||||
{
|
||||
o.pack(v);
|
||||
}
|
||||
|
||||
// obsolete
|
||||
template <typename Stream, typename T>
|
||||
inline void pack_copy(packer<Stream>& o, T v)
|
||||
inline void pack_copy(msgpack::packer<Stream>& o, T v)
|
||||
{
|
||||
pack(o, v);
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
||||
inline msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const msgpack::object& v)
|
||||
{
|
||||
switch(v.type) {
|
||||
case type::NIL:
|
||||
case msgpack::type::NIL:
|
||||
o.pack_nil();
|
||||
return o;
|
||||
|
||||
case type::BOOLEAN:
|
||||
case msgpack::type::BOOLEAN:
|
||||
if(v.via.boolean) {
|
||||
o.pack_true();
|
||||
} else {
|
||||
@@ -431,45 +502,45 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
||||
}
|
||||
return o;
|
||||
|
||||
case type::POSITIVE_INTEGER:
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
o.pack_uint64(v.via.u64);
|
||||
return o;
|
||||
|
||||
case type::NEGATIVE_INTEGER:
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
o.pack_int64(v.via.i64);
|
||||
return o;
|
||||
|
||||
case type::DOUBLE:
|
||||
o.pack_double(v.via.dec);
|
||||
case msgpack::type::FLOAT:
|
||||
o.pack_double(v.via.f64);
|
||||
return o;
|
||||
|
||||
case type::STR:
|
||||
case msgpack::type::STR:
|
||||
o.pack_str(v.via.str.size);
|
||||
o.pack_str_body(v.via.str.ptr, v.via.str.size);
|
||||
return o;
|
||||
|
||||
case type::BIN:
|
||||
case msgpack::type::BIN:
|
||||
o.pack_bin(v.via.bin.size);
|
||||
o.pack_bin_body(v.via.bin.ptr, v.via.bin.size);
|
||||
return o;
|
||||
|
||||
case type::EXT:
|
||||
case msgpack::type::EXT:
|
||||
o.pack_ext(v.via.ext.size, v.via.ext.type());
|
||||
o.pack_ext_body(v.via.ext.data(), v.via.ext.size);
|
||||
return o;
|
||||
|
||||
case type::ARRAY:
|
||||
case msgpack::type::ARRAY:
|
||||
o.pack_array(v.via.array.size);
|
||||
for(object* p(v.via.array.ptr),
|
||||
for(msgpack::object* p(v.via.array.ptr),
|
||||
* const pend(v.via.array.ptr + v.via.array.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, *p);
|
||||
}
|
||||
return o;
|
||||
|
||||
case type::MAP:
|
||||
case msgpack::type::MAP:
|
||||
o.pack_map(v.via.map.size);
|
||||
for(object_kv* p(v.via.map.ptr),
|
||||
for(msgpack::object_kv* p(v.via.map.ptr),
|
||||
* const pend(v.via.map.ptr + v.via.map.size);
|
||||
p < pend; ++p) {
|
||||
msgpack::operator<<(o, p->key);
|
||||
@@ -478,51 +549,58 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const object& v)
|
||||
return o;
|
||||
|
||||
default:
|
||||
throw type_error();
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
}
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& s, const object& o)
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator<< (msgpack::packer<Stream>& o, const msgpack::object::with_zone& v)
|
||||
{
|
||||
return o << static_cast<msgpack::object>(v);
|
||||
}
|
||||
|
||||
inline std::ostream& operator<< (std::ostream& s, const msgpack::object& o)
|
||||
{
|
||||
switch(o.type) {
|
||||
case type::NIL:
|
||||
case msgpack::type::NIL:
|
||||
s << "nil";
|
||||
break;
|
||||
|
||||
case type::BOOLEAN:
|
||||
case msgpack::type::BOOLEAN:
|
||||
s << (o.via.boolean ? "true" : "false");
|
||||
break;
|
||||
|
||||
case type::POSITIVE_INTEGER:
|
||||
case msgpack::type::POSITIVE_INTEGER:
|
||||
s << o.via.u64;
|
||||
break;
|
||||
|
||||
case type::NEGATIVE_INTEGER:
|
||||
case msgpack::type::NEGATIVE_INTEGER:
|
||||
s << o.via.i64;
|
||||
break;
|
||||
|
||||
case type::DOUBLE:
|
||||
s << o.via.dec;
|
||||
case msgpack::type::FLOAT:
|
||||
s << o.via.f64;
|
||||
break;
|
||||
|
||||
case type::STR:
|
||||
case msgpack::type::STR:
|
||||
(s << '"').write(o.via.str.ptr, o.via.str.size) << '"';
|
||||
break;
|
||||
|
||||
case type::BIN:
|
||||
case msgpack::type::BIN:
|
||||
(s << '"').write(o.via.bin.ptr, o.via.bin.size) << '"';
|
||||
break;
|
||||
|
||||
case type::EXT:
|
||||
case msgpack::type::EXT:
|
||||
s << "EXT";
|
||||
break;
|
||||
|
||||
case type::ARRAY:
|
||||
case msgpack::type::ARRAY:
|
||||
s << "[";
|
||||
if(o.via.array.size != 0) {
|
||||
object* p(o.via.array.ptr);
|
||||
msgpack::object* p(o.via.array.ptr);
|
||||
s << *p;
|
||||
++p;
|
||||
for(object* const pend(o.via.array.ptr + o.via.array.size);
|
||||
for(msgpack::object* const pend(o.via.array.ptr + o.via.array.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << *p;
|
||||
}
|
||||
@@ -530,13 +608,13 @@ inline std::ostream& operator<< (std::ostream& s, const object& o)
|
||||
s << "]";
|
||||
break;
|
||||
|
||||
case type::MAP:
|
||||
case msgpack::type::MAP:
|
||||
s << "{";
|
||||
if(o.via.map.size != 0) {
|
||||
object_kv* p(o.via.map.ptr);
|
||||
msgpack::object_kv* p(o.via.map.ptr);
|
||||
s << p->key << "=>" << p->val;
|
||||
++p;
|
||||
for(object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
for(msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size);
|
||||
p < pend; ++p) {
|
||||
s << ", " << p->key << "=>" << p->val;
|
||||
}
|
||||
@@ -551,7 +629,9 @@ inline std::ostream& operator<< (std::ostream& s, const object& o)
|
||||
return s;
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -27,7 +27,9 @@
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
|
||||
namespace type {
|
||||
@@ -36,7 +38,10 @@ namespace type {
|
||||
BOOLEAN = MSGPACK_OBJECT_BOOLEAN,
|
||||
POSITIVE_INTEGER = MSGPACK_OBJECT_POSITIVE_INTEGER,
|
||||
NEGATIVE_INTEGER = MSGPACK_OBJECT_NEGATIVE_INTEGER,
|
||||
DOUBLE = MSGPACK_OBJECT_DOUBLE,
|
||||
FLOAT = MSGPACK_OBJECT_FLOAT,
|
||||
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
|
||||
DOUBLE = MSGPACK_OBJECT_DOUBLE, // obsolete
|
||||
#endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT
|
||||
STR = MSGPACK_OBJECT_STR,
|
||||
BIN = MSGPACK_OBJECT_BIN,
|
||||
ARRAY = MSGPACK_OBJECT_ARRAY,
|
||||
@@ -51,12 +56,12 @@ struct object_kv;
|
||||
|
||||
struct object_array {
|
||||
uint32_t size;
|
||||
object* ptr;
|
||||
msgpack::object* ptr;
|
||||
};
|
||||
|
||||
struct object_map {
|
||||
uint32_t size;
|
||||
object_kv* ptr;
|
||||
msgpack::object_kv* ptr;
|
||||
};
|
||||
|
||||
struct object_str {
|
||||
@@ -81,18 +86,21 @@ struct object {
|
||||
bool boolean;
|
||||
uint64_t u64;
|
||||
int64_t i64;
|
||||
double dec;
|
||||
object_array array;
|
||||
object_map map;
|
||||
object_str str;
|
||||
object_bin bin;
|
||||
object_ext ext;
|
||||
#if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT)
|
||||
double dec; // obsolete
|
||||
#endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT
|
||||
double f64;
|
||||
msgpack::object_array array;
|
||||
msgpack::object_map map;
|
||||
msgpack::object_str str;
|
||||
msgpack::object_bin bin;
|
||||
msgpack::object_ext ext;
|
||||
};
|
||||
|
||||
type::object_type type;
|
||||
msgpack::type::object_type type;
|
||||
union_type via;
|
||||
|
||||
bool is_nil() const { return type == type::NIL; }
|
||||
bool is_nil() const { return type == msgpack::type::NIL; }
|
||||
|
||||
template <typename T>
|
||||
T as() const;
|
||||
@@ -104,17 +112,17 @@ struct object {
|
||||
|
||||
object();
|
||||
|
||||
object(msgpack_object o);
|
||||
object(const msgpack_object& o);
|
||||
|
||||
template <typename T>
|
||||
explicit object(const T& v);
|
||||
|
||||
template <typename T>
|
||||
object(const T& v, zone& z);
|
||||
object(const T& v, msgpack::zone& z);
|
||||
|
||||
// obsolete
|
||||
template <typename T>
|
||||
object(const T& v, zone* z);
|
||||
object(const T& v, msgpack::zone* z);
|
||||
|
||||
template <typename T>
|
||||
object& operator=(const T& v);
|
||||
@@ -133,37 +141,20 @@ public:
|
||||
class type_error : public std::bad_cast { };
|
||||
|
||||
struct object_kv {
|
||||
object key;
|
||||
object val;
|
||||
msgpack::object key;
|
||||
msgpack::object val;
|
||||
};
|
||||
|
||||
namespace detail {
|
||||
template <typename Stream, typename T>
|
||||
struct packer_serializer;
|
||||
} // namespace detail
|
||||
|
||||
object const& operator>> (object const& o, object& v);
|
||||
|
||||
template <typename T>
|
||||
object const& operator>> (object const& o, T& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const T& v);
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
class packer;
|
||||
|
||||
template <typename Stream>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const object& v);
|
||||
|
||||
template <typename Stream, typename T>
|
||||
packer<Stream>& operator<< (packer<Stream>& o, const T& v);
|
||||
|
||||
template <typename T>
|
||||
void operator<< (object::with_zone& o, const T& v);
|
||||
struct object::with_zone : object {
|
||||
with_zone(msgpack::zone& zone) : zone(zone) { }
|
||||
msgpack::zone& zone;
|
||||
private:
|
||||
with_zone();
|
||||
};
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -19,16 +19,20 @@
|
||||
#define MSGPACK_PACK_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/cpp_config.hpp"
|
||||
|
||||
#include <stdexcept>
|
||||
#include <limits>
|
||||
#include <cstring>
|
||||
#include <climits>
|
||||
|
||||
#include "sysdep.h"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
template <typename Stream>
|
||||
class packer {
|
||||
@@ -77,18 +81,18 @@ public:
|
||||
packer<Stream>& pack_true();
|
||||
packer<Stream>& pack_false();
|
||||
|
||||
packer<Stream>& pack_array(size_t n);
|
||||
packer<Stream>& pack_array(uint32_t n);
|
||||
|
||||
packer<Stream>& pack_map(size_t n);
|
||||
packer<Stream>& pack_map(uint32_t n);
|
||||
|
||||
packer<Stream>& pack_str(size_t l);
|
||||
packer<Stream>& pack_str_body(const char* b, size_t l);
|
||||
packer<Stream>& pack_str(uint32_t l);
|
||||
packer<Stream>& pack_str_body(const char* b, uint32_t l);
|
||||
|
||||
packer<Stream>& pack_bin(size_t l);
|
||||
packer<Stream>& pack_bin_body(const char* b, size_t l);
|
||||
packer<Stream>& pack_bin(uint32_t l);
|
||||
packer<Stream>& pack_bin_body(const char* b, uint32_t l);
|
||||
|
||||
packer<Stream>& pack_ext(size_t l, int8_t type);
|
||||
packer<Stream>& pack_ext_body(const char* b, size_t l);
|
||||
packer<Stream>& pack_ext_body(const char* b, uint32_t l);
|
||||
|
||||
private:
|
||||
template <typename T>
|
||||
@@ -114,8 +118,17 @@ private:
|
||||
private:
|
||||
Stream& m_stream;
|
||||
|
||||
#if defined(MSGPACK_USE_CPP03)
|
||||
private:
|
||||
packer(const packer&);
|
||||
packer& operator=(const packer&);
|
||||
packer();
|
||||
#else // defined(MSGPACK_USE_CPP03)
|
||||
public:
|
||||
packer(const packer&) = delete;
|
||||
packer& operator=(const packer&) = delete;
|
||||
packer() = delete;
|
||||
#endif // defined(MSGPACK_USE_CPP03)
|
||||
};
|
||||
|
||||
|
||||
@@ -131,6 +144,7 @@ inline void pack(Stream& s, const T& v)
|
||||
packer<Stream>(s).pack(v);
|
||||
}
|
||||
|
||||
|
||||
#if defined(__LITTLE_ENDIAN__)
|
||||
template <typename T>
|
||||
inline char take8_8(T d) {
|
||||
@@ -213,7 +227,7 @@ inline packer<Stream>& packer<Stream>::pack_int64(int64_t d)
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint8(uint8_t d)
|
||||
{
|
||||
char buf[2] = {static_cast<char>(0xcc), take8_8(d)};
|
||||
char buf[2] = {static_cast<char>(0xccu), take8_8(d)};
|
||||
append_buffer(buf, 2);
|
||||
return *this;
|
||||
}
|
||||
@@ -222,7 +236,7 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint16(uint16_t d)
|
||||
{
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xcdu); _msgpack_store16(&buf[1], d);
|
||||
append_buffer(buf, 3);
|
||||
return *this;
|
||||
}
|
||||
@@ -231,7 +245,7 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint32(uint32_t d)
|
||||
{
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xceu); _msgpack_store32(&buf[1], d);
|
||||
append_buffer(buf, 5);
|
||||
return *this;
|
||||
}
|
||||
@@ -240,7 +254,7 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_uint64(uint64_t d)
|
||||
{
|
||||
char buf[9];
|
||||
buf[0] = static_cast<char>(0xcf); _msgpack_store64(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xcfu); _msgpack_store64(&buf[1], d);
|
||||
append_buffer(buf, 9);
|
||||
return *this;
|
||||
}
|
||||
@@ -248,7 +262,7 @@ inline packer<Stream>& packer<Stream>::pack_fix_uint64(uint64_t d)
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int8(int8_t d)
|
||||
{
|
||||
char buf[2] = {static_cast<char>(0xd0), take8_8(d)};
|
||||
char buf[2] = {static_cast<char>(0xd0u), take8_8(d)};
|
||||
append_buffer(buf, 2);
|
||||
return *this;
|
||||
}
|
||||
@@ -257,7 +271,7 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int16(int16_t d)
|
||||
{
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xd1u); _msgpack_store16(&buf[1], d);
|
||||
append_buffer(buf, 3);
|
||||
return *this;
|
||||
}
|
||||
@@ -266,7 +280,7 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int32(int32_t d)
|
||||
{
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xd2); _msgpack_store32(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xd2u); _msgpack_store32(&buf[1], d);
|
||||
append_buffer(buf, 5);
|
||||
return *this;
|
||||
}
|
||||
@@ -275,7 +289,7 @@ template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_fix_int64(int64_t d)
|
||||
{
|
||||
char buf[9];
|
||||
buf[0] = static_cast<char>(0xd3); _msgpack_store64(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xd3u); _msgpack_store64(&buf[1], d);
|
||||
append_buffer(buf, 9);
|
||||
return *this;
|
||||
}
|
||||
@@ -283,11 +297,25 @@ inline packer<Stream>& packer<Stream>::pack_fix_int64(int64_t d)
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_char(char d)
|
||||
{ _pack_char(m_stream, d); return *this; }
|
||||
{
|
||||
#if defined(CHAR_MIN)
|
||||
#if CHAR_MIN < 0
|
||||
pack_imp_int8(d);
|
||||
#else
|
||||
pack_imp_uint8(d);
|
||||
#endif
|
||||
#else
|
||||
#error CHAR_MIN is not defined
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_signed_char(signed char d)
|
||||
{ _pack_signed_char(m_stream, d); return *this; }
|
||||
{
|
||||
pack_imp_int8(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_short(short d)
|
||||
@@ -424,7 +452,10 @@ inline packer<Stream>& packer<Stream>::pack_long_long(long long d)
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_unsigned_char(unsigned char d)
|
||||
{ _pack_unsigned_char(m_stream, d); return *this; }
|
||||
{
|
||||
pack_imp_uint8(d);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_unsigned_short(unsigned short d)
|
||||
@@ -565,7 +596,7 @@ inline packer<Stream>& packer<Stream>::pack_float(float d)
|
||||
union { float f; uint32_t i; } mem;
|
||||
mem.f = d;
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xca); _msgpack_store32(&buf[1], mem.i);
|
||||
buf[0] = static_cast<char>(0xcau); _msgpack_store32(&buf[1], mem.i);
|
||||
append_buffer(buf, 5);
|
||||
return *this;
|
||||
}
|
||||
@@ -576,7 +607,7 @@ inline packer<Stream>& packer<Stream>::pack_double(double d)
|
||||
union { double f; uint64_t i; } mem;
|
||||
mem.f = d;
|
||||
char buf[9];
|
||||
buf[0] = static_cast<char>(0xcb);
|
||||
buf[0] = static_cast<char>(0xcbu);
|
||||
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
|
||||
// https://github.com/msgpack/msgpack-perl/pull/1
|
||||
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
|
||||
@@ -590,7 +621,7 @@ inline packer<Stream>& packer<Stream>::pack_double(double d)
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_nil()
|
||||
{
|
||||
const char d = static_cast<char>(0xc0);
|
||||
const char d = static_cast<char>(0xc0u);
|
||||
append_buffer(&d, 1);
|
||||
return *this;
|
||||
}
|
||||
@@ -598,7 +629,7 @@ inline packer<Stream>& packer<Stream>::pack_nil()
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_true()
|
||||
{
|
||||
const char d = static_cast<char>(0xc3);
|
||||
const char d = static_cast<char>(0xc3u);
|
||||
append_buffer(&d, 1);
|
||||
return *this;
|
||||
}
|
||||
@@ -606,100 +637,100 @@ inline packer<Stream>& packer<Stream>::pack_true()
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_false()
|
||||
{
|
||||
const char d = static_cast<char>(0xc2);
|
||||
const char d = static_cast<char>(0xc2u);
|
||||
append_buffer(&d, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_array(size_t n)
|
||||
inline packer<Stream>& packer<Stream>::pack_array(uint32_t n)
|
||||
{
|
||||
if(n < 16) {
|
||||
char d = static_cast<char>(0x90 | n);
|
||||
char d = static_cast<char>(0x90u | n);
|
||||
append_buffer(&d, 1);
|
||||
} else if(n < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xdc); _msgpack_store16(&buf[1], static_cast<uint16_t>(n));
|
||||
buf[0] = static_cast<char>(0xdcu); _msgpack_store16(&buf[1], static_cast<uint16_t>(n));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xdd); _msgpack_store32(&buf[1], static_cast<uint32_t>(n));
|
||||
buf[0] = static_cast<char>(0xddu); _msgpack_store32(&buf[1], static_cast<uint32_t>(n));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_map(size_t n)
|
||||
inline packer<Stream>& packer<Stream>::pack_map(uint32_t n)
|
||||
{
|
||||
if(n < 16) {
|
||||
unsigned char d = 0x80 | n;
|
||||
unsigned char d = static_cast<unsigned char>(0x80u | n);
|
||||
char buf = take8_8(d);
|
||||
append_buffer(&buf, 1);
|
||||
} else if(n < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xde); _msgpack_store16(&buf[1], static_cast<uint16_t>(n));
|
||||
buf[0] = static_cast<char>(0xdeu); _msgpack_store16(&buf[1], static_cast<uint16_t>(n));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xdf); _msgpack_store32(&buf[1], static_cast<uint32_t>(n));
|
||||
buf[0] = static_cast<char>(0xdfu); _msgpack_store32(&buf[1], static_cast<uint32_t>(n));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_str(size_t l)
|
||||
inline packer<Stream>& packer<Stream>::pack_str(uint32_t l)
|
||||
{
|
||||
if(l < 32) {
|
||||
unsigned char d = 0xa0 | static_cast<uint8_t>(l);
|
||||
unsigned char d = 0xa0u | static_cast<uint8_t>(l);
|
||||
char buf = take8_8(d);
|
||||
append_buffer(&buf, 1);
|
||||
} else if(l < 256) {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xd9); buf[1] = static_cast<uint8_t>(l);
|
||||
buf[0] = static_cast<char>(0xd9u); buf[1] = static_cast<uint8_t>(l);
|
||||
append_buffer(buf, 2);
|
||||
} else if(l < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xda); _msgpack_store16(&buf[1], static_cast<uint16_t>(l));
|
||||
buf[0] = static_cast<char>(0xdau); _msgpack_store16(&buf[1], static_cast<uint16_t>(l));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xdb); _msgpack_store32(&buf[1], static_cast<uint32_t>(l));
|
||||
buf[0] = static_cast<char>(0xdbu); _msgpack_store32(&buf[1], static_cast<uint32_t>(l));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_str_body(const char* b, size_t l)
|
||||
inline packer<Stream>& packer<Stream>::pack_str_body(const char* b, uint32_t l)
|
||||
{
|
||||
append_buffer(b, l);
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_bin(size_t l)
|
||||
inline packer<Stream>& packer<Stream>::pack_bin(uint32_t l)
|
||||
{
|
||||
if(l < 256) {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xc4); buf[1] = static_cast<uint8_t>(l);
|
||||
buf[0] = static_cast<char>(0xc4u); buf[1] = static_cast<uint8_t>(l);
|
||||
append_buffer(buf, 2);
|
||||
} else if(l < 65536) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xc5); _msgpack_store16(&buf[1], static_cast<uint16_t>(l));
|
||||
buf[0] = static_cast<char>(0xc5u); _msgpack_store16(&buf[1], static_cast<uint16_t>(l));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xc6); _msgpack_store32(&buf[1], static_cast<uint32_t>(l));
|
||||
buf[0] = static_cast<char>(0xc6u); _msgpack_store32(&buf[1], static_cast<uint32_t>(l));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_bin_body(const char* b, size_t l)
|
||||
inline packer<Stream>& packer<Stream>::pack_bin_body(const char* b, uint32_t l)
|
||||
{
|
||||
append_buffer(b, l);
|
||||
return *this;
|
||||
@@ -711,50 +742,50 @@ inline packer<Stream>& packer<Stream>::pack_ext(size_t l, int8_t type)
|
||||
switch(l) {
|
||||
case 1: {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xd4);
|
||||
buf[0] = static_cast<char>(0xd4u);
|
||||
buf[1] = static_cast<char>(type);
|
||||
append_buffer(buf, 2);
|
||||
} break;
|
||||
case 2: {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xd5);
|
||||
buf[0] = static_cast<char>(0xd5u);
|
||||
buf[1] = static_cast<char>(type);
|
||||
append_buffer(buf, 2);
|
||||
} break;
|
||||
case 4: {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xd6);
|
||||
buf[0] = static_cast<char>(0xd6u);
|
||||
buf[1] = static_cast<char>(type);
|
||||
append_buffer(buf, 2);
|
||||
} break;
|
||||
case 8: {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xd7);
|
||||
buf[0] = static_cast<char>(0xd7u);
|
||||
buf[1] = static_cast<char>(type);
|
||||
append_buffer(buf, 2);
|
||||
} break;
|
||||
case 16: {
|
||||
char buf[2];
|
||||
buf[0] = static_cast<char>(0xd8);
|
||||
buf[0] = static_cast<char>(0xd8u);
|
||||
buf[1] = static_cast<char>(type);
|
||||
append_buffer(buf, 2);
|
||||
} break;
|
||||
default:
|
||||
if(l < 256) {
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xc7);
|
||||
buf[0] = static_cast<char>(0xc7u);
|
||||
buf[1] = static_cast<char>(l);
|
||||
buf[2] = static_cast<char>(type);
|
||||
append_buffer(buf, 3);
|
||||
} else if(l < 65536) {
|
||||
char buf[4];
|
||||
buf[0] = static_cast<char>(0xc8);
|
||||
buf[0] = static_cast<char>(0xc8u);
|
||||
_msgpack_store16(&buf[1], static_cast<uint16_t>(l));
|
||||
buf[3] = static_cast<char>(type);
|
||||
append_buffer(buf, 4);
|
||||
} else {
|
||||
char buf[6];
|
||||
buf[0] = static_cast<char>(0xc9);
|
||||
buf[0] = static_cast<char>(0xc9u);
|
||||
_msgpack_store32(&buf[1], static_cast<uint32_t>(l));
|
||||
buf[5] = static_cast<char>(type);
|
||||
append_buffer(buf, 6);
|
||||
@@ -765,7 +796,7 @@ inline packer<Stream>& packer<Stream>::pack_ext(size_t l, int8_t type)
|
||||
}
|
||||
|
||||
template <typename Stream>
|
||||
inline packer<Stream>& packer<Stream>::pack_ext_body(const char* b, size_t l)
|
||||
inline packer<Stream>& packer<Stream>::pack_ext_body(const char* b, uint32_t l)
|
||||
{
|
||||
append_buffer(b, l);
|
||||
return *this;
|
||||
@@ -781,7 +812,7 @@ inline void packer<Stream>::pack_imp_uint8(T d)
|
||||
append_buffer(&buf, 1);
|
||||
} else {
|
||||
/* unsigned 8 */
|
||||
char buf[2] = {static_cast<char>(0xcc), take8_8(d)};
|
||||
char buf[2] = {static_cast<char>(0xccu), take8_8(d)};
|
||||
append_buffer(buf, 2);
|
||||
}
|
||||
}
|
||||
@@ -796,12 +827,12 @@ inline void packer<Stream>::pack_imp_uint16(T d)
|
||||
append_buffer(&buf, 1);
|
||||
} else if(d < (1<<8)) {
|
||||
/* unsigned 8 */
|
||||
char buf[2] = {static_cast<char>(0xcc), take8_16(d)};
|
||||
char buf[2] = {static_cast<char>(0xccu), take8_16(d)};
|
||||
append_buffer(buf, 2);
|
||||
} else {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
buf[0] = static_cast<char>(0xcdu); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
}
|
||||
}
|
||||
@@ -817,19 +848,19 @@ inline void packer<Stream>::pack_imp_uint32(T d)
|
||||
append_buffer(&buf, 1);
|
||||
} else {
|
||||
/* unsigned 8 */
|
||||
char buf[2] = {static_cast<char>(0xcc), take8_32(d)};
|
||||
char buf[2] = {static_cast<char>(0xccu), take8_32(d)};
|
||||
append_buffer(buf, 2);
|
||||
}
|
||||
} else {
|
||||
if(d < (1<<16)) {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
buf[0] = static_cast<char>(0xcdu); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
buf[0] = static_cast<char>(0xceu); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -846,24 +877,24 @@ inline void packer<Stream>::pack_imp_uint64(T d)
|
||||
append_buffer(&buf, 1);
|
||||
} else {
|
||||
/* unsigned 8 */
|
||||
char buf[2] = {static_cast<char>(0xcc), take8_64(d)};
|
||||
char buf[2] = {static_cast<char>(0xccu), take8_64(d)};
|
||||
append_buffer(buf, 2);
|
||||
}
|
||||
} else {
|
||||
if(d < (1ULL<<16)) {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
buf[0] = static_cast<char>(0xcdu); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else if(d < (1ULL<<32)) {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
buf[0] = static_cast<char>(0xceu); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
} else {
|
||||
/* unsigned 64 */
|
||||
char buf[9];
|
||||
buf[0] = static_cast<char>(0xcf); _msgpack_store64(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xcfu); _msgpack_store64(&buf[1], d);
|
||||
append_buffer(buf, 9);
|
||||
}
|
||||
}
|
||||
@@ -875,7 +906,7 @@ inline void packer<Stream>::pack_imp_int8(T d)
|
||||
{
|
||||
if(d < -(1<<5)) {
|
||||
/* signed 8 */
|
||||
char buf[2] = {static_cast<char>(0xd0), take8_8(d)};
|
||||
char buf[2] = {static_cast<char>(0xd0u), take8_8(d)};
|
||||
append_buffer(buf, 2);
|
||||
} else {
|
||||
/* fixnum */
|
||||
@@ -892,11 +923,11 @@ inline void packer<Stream>::pack_imp_int16(T d)
|
||||
if(d < -(1<<7)) {
|
||||
/* signed 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
buf[0] = static_cast<char>(0xd1u); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* signed 8 */
|
||||
char buf[2] = {static_cast<char>(0xd0), take8_16(d)};
|
||||
char buf[2] = {static_cast<char>(0xd0u), take8_16(d)};
|
||||
append_buffer(buf, 2);
|
||||
}
|
||||
} else if(d < (1<<7)) {
|
||||
@@ -906,12 +937,12 @@ inline void packer<Stream>::pack_imp_int16(T d)
|
||||
} else {
|
||||
if(d < (1<<8)) {
|
||||
/* unsigned 8 */
|
||||
char buf[2] = {static_cast<char>(0xcc), take8_16(d)};
|
||||
char buf[2] = {static_cast<char>(0xccu), take8_16(d)};
|
||||
append_buffer(buf, 2);
|
||||
} else {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
buf[0] = static_cast<char>(0xcdu); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
}
|
||||
}
|
||||
@@ -925,16 +956,16 @@ inline void packer<Stream>::pack_imp_int32(T d)
|
||||
if(d < -(1<<15)) {
|
||||
/* signed 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xd2); _msgpack_store32(&buf[1], static_cast<int32_t>(d));
|
||||
buf[0] = static_cast<char>(0xd2u); _msgpack_store32(&buf[1], static_cast<int32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
} else if(d < -(1<<7)) {
|
||||
/* signed 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
buf[0] = static_cast<char>(0xd1u); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* signed 8 */
|
||||
char buf[2] = { static_cast<char>(0xd0), take8_32(d)};
|
||||
char buf[2] = { static_cast<char>(0xd0u), take8_32(d)};
|
||||
append_buffer(buf, 2);
|
||||
}
|
||||
} else if(d < (1<<7)) {
|
||||
@@ -944,17 +975,17 @@ inline void packer<Stream>::pack_imp_int32(T d)
|
||||
} else {
|
||||
if(d < (1<<8)) {
|
||||
/* unsigned 8 */
|
||||
char buf[2] = { static_cast<char>(0xcc), take8_32(d)};
|
||||
char buf[2] = { static_cast<char>(0xccu), take8_32(d)};
|
||||
append_buffer(buf, 2);
|
||||
} else if(d < (1<<16)) {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
buf[0] = static_cast<char>(0xcdu); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
buf[0] = static_cast<char>(0xceu); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
}
|
||||
@@ -969,23 +1000,23 @@ inline void packer<Stream>::pack_imp_int64(T d)
|
||||
if(d < -(1LL<<31)) {
|
||||
/* signed 64 */
|
||||
char buf[9];
|
||||
buf[0] = static_cast<char>(0xd3); _msgpack_store64(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xd3u); _msgpack_store64(&buf[1], d);
|
||||
append_buffer(buf, 9);
|
||||
} else {
|
||||
/* signed 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xd2); _msgpack_store32(&buf[1], static_cast<int32_t>(d));
|
||||
buf[0] = static_cast<char>(0xd2u); _msgpack_store32(&buf[1], static_cast<int32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
}
|
||||
} else {
|
||||
if(d < -(1<<7)) {
|
||||
/* signed 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xd1); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
buf[0] = static_cast<char>(0xd1u); _msgpack_store16(&buf[1], static_cast<int16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
} else {
|
||||
/* signed 8 */
|
||||
char buf[2] = {static_cast<char>(0xd0), take8_64(d)};
|
||||
char buf[2] = {static_cast<char>(0xd0u), take8_64(d)};
|
||||
append_buffer(buf, 2);
|
||||
}
|
||||
}
|
||||
@@ -997,31 +1028,33 @@ inline void packer<Stream>::pack_imp_int64(T d)
|
||||
if(d < (1LL<<16)) {
|
||||
if(d < (1<<8)) {
|
||||
/* unsigned 8 */
|
||||
char buf[2] = {static_cast<char>(0xcc), take8_64(d)};
|
||||
char buf[2] = {static_cast<char>(0xccu), take8_64(d)};
|
||||
append_buffer(buf, 2);
|
||||
} else {
|
||||
/* unsigned 16 */
|
||||
char buf[3];
|
||||
buf[0] = static_cast<char>(0xcd); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
buf[0] = static_cast<char>(0xcdu); _msgpack_store16(&buf[1], static_cast<uint16_t>(d));
|
||||
append_buffer(buf, 3);
|
||||
}
|
||||
} else {
|
||||
if(d < (1LL<<32)) {
|
||||
/* unsigned 32 */
|
||||
char buf[5];
|
||||
buf[0] = static_cast<char>(0xce); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
buf[0] = static_cast<char>(0xceu); _msgpack_store32(&buf[1], static_cast<uint32_t>(d));
|
||||
append_buffer(buf, 5);
|
||||
} else {
|
||||
/* unsigned 64 */
|
||||
char buf[9];
|
||||
buf[0] = static_cast<char>(0xcf); _msgpack_store64(&buf[1], d);
|
||||
buf[0] = static_cast<char>(0xcfu); _msgpack_store64(&buf[1], d);
|
||||
append_buffer(buf, 9);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
|
@@ -811,50 +811,50 @@ msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type)
|
||||
{
|
||||
switch(l) {
|
||||
case 1: {
|
||||
char buf[2];
|
||||
unsigned char buf[2];
|
||||
buf[0] = 0xd4;
|
||||
buf[1] = type;
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
} break;
|
||||
case 2: {
|
||||
char buf[2];
|
||||
unsigned char buf[2];
|
||||
buf[0] = 0xd5;
|
||||
buf[1] = type;
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
} break;
|
||||
case 4: {
|
||||
char buf[2];
|
||||
unsigned char buf[2];
|
||||
buf[0] = 0xd6;
|
||||
buf[1] = type;
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
} break;
|
||||
case 8: {
|
||||
char buf[2];
|
||||
unsigned char buf[2];
|
||||
buf[0] = 0xd7;
|
||||
buf[1] = type;
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
} break;
|
||||
case 16: {
|
||||
char buf[2];
|
||||
unsigned char buf[2];
|
||||
buf[0] = 0xd8;
|
||||
buf[1] = type;
|
||||
msgpack_pack_append_buffer(x, buf, 2);
|
||||
} break;
|
||||
default:
|
||||
if(l < 256) {
|
||||
char buf[3];
|
||||
unsigned char buf[3];
|
||||
buf[0] = 0xc7;
|
||||
buf[1] = l;
|
||||
buf[1] = (unsigned char)l;
|
||||
buf[2] = type;
|
||||
msgpack_pack_append_buffer(x, buf, 3);
|
||||
} else if(l < 65536) {
|
||||
char buf[4];
|
||||
unsigned char buf[4];
|
||||
buf[0] = 0xc8;
|
||||
_msgpack_store16(&buf[1], l);
|
||||
buf[3] = type;
|
||||
msgpack_pack_append_buffer(x, buf, 4);
|
||||
} else {
|
||||
char buf[6];
|
||||
unsigned char buf[6];
|
||||
buf[0] = 0xc9;
|
||||
_msgpack_store32(&buf[1], l);
|
||||
buf[5] = type;
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user