Merge branch 'redboltz-poc/0.6'

This commit is contained in:
Takatoshi Kondo 2014-10-26 15:40:41 +09:00
commit 8455a2eb70
181 changed files with 40086 additions and 26672 deletions

1
.gitignore vendored
View File

@ -19,6 +19,7 @@ Makefile.in
/libtool
/msgpack.pc
/src/msgpack/version.h
/src/msgpack/version.hpp
/stamp-h1
Makefile
.deps

View File

@ -5,21 +5,30 @@ compiler:
- clang
- gcc
before_install:
# We need this line to have g++4.8 available in apt
- sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test
- sudo add-apt-repository -y ppa:h-rayflood/llvm
- sudo apt-get update -qq
- sudo apt-get update
- sudo apt-get install valgrind
- sudo apt-get install libgtest-dev
- "cd /usr/src/gtest && sudo cmake . && sudo cmake --build . && sudo mv libg* /usr/local/lib/ ; cd -"
install:
- sudo apt-get install -qq gcc-4.8 g++-4.8
# We want to compile with g++ 4.8 when rather than the default g++
- sudo apt-get install -qq gcc-4.8-multilib g++-4.8-multilib
- sudo apt-get install --allow-unauthenticated -qq clang-3.4
- sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90
- sudo apt-get install -y lib32gcc1
- sudo apt-get install -y libc6-i386
- sudo apt-get install -y lib32z1-dev
- sudo apt-get install -y lib32stdc++6
- wget https://googletest.googlecode.com/files/gtest-1.7.0.zip
- unzip gtest-1.7.0.zip && cd gtest-1.7.0 && sudo cp -r include/gtest /usr/local/include && g++ src/gtest-all.cc -I. -Iinclude -c && g++ src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mv *.a /usr/local/lib && g++ -m32 src/gtest-all.cc -I. -Iinclude -c && g++ -m32 src/gtest_main.cc -I. -Iinclude -c && ar -rv libgtest.a gtest-all.o && ar -rv libgtest_main.a gtest_main.o && sudo mkdir /usr/local/lib32 && sudo mv *.a /usr/local/lib32 && cd ..
env:
- ACTION="ci/build_autotools.sh" PARAM="cpp03"
- ACTION="ci/build_cmake.sh" PARAM="cpp03"
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib"
- ACTION="ci/build_autotools.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32"
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib"
- ACTION="ci/build_autotools.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32"
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="64" LIBPATH="/usr/local/lib"
- ACTION="ci/build_cmake.sh" VERSION="cpp11" ARCH="32" LIBPATH="/usr/local/lib32"
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="64" LIBPATH="/usr/local/lib"
- ACTION="ci/build_cmake.sh" VERSION="cpp03" ARCH="32" LIBPATH="/usr/local/lib32"
script:
- git clean -xdf && ${ACTION} ${PARAM}
- git clean -xdf && CMAKE_LIBRARY_PATH=${LIBPATH} ${ACTION} ${VERSION} ${ARCH}

View File

@ -1,15 +1,45 @@
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.6)
PROJECT (msgpack)
SET (VERSION 0.5.9)
SET (VERSION_MAJOR 0)
SET (VERSION_MINOR 5)
FILE (READ ${CMAKE_SOURCE_DIR}/include/msgpack/version_master.h contents)
STRING (REGEX MATCH "#define MSGPACK_VERSION_MAJOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents})
SET (VERSION_MAJOR ${CMAKE_MATCH_1})
STRING (REGEX MATCH "#define MSGPACK_VERSION_MINOR *([0-9a-zA-Z_]*)" NULL_OUT ${contents})
SET (VERSION_MINOR ${CMAKE_MATCH_1})
STRING (REGEX MATCH "#define MSGPACK_VERSION_REVISION *([0-9a-zA-Z_]*)" NULL_OUT ${contents})
SET (VERSION_REVISION ${CMAKE_MATCH_1})
SET (VERSION ${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_REVISION})
SET (prefix ${CMAKE_INSTALL_PREFIX})
SET (exec_prefix "\${prefix}")
SET (libdir "\${exec_prefix}/lib")
SET (includedir "\${prefix}/include")
OPTION (MSGPACK_CXX11 "Using c++11 compiler" OFF)
OPTION (MSGPACK_32BIT "32bit compile" OFF)
IF (MSGPACK_CXX11)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
MESSAGE ( FATAL_ERROR "MSVC doesn't support C++11 yet.")
ENDIF ()
ENDIF ()
IF (MSGPACK_32BIT)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET (CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
SET (CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}")
ELSEIF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang")
SET (CMAKE_CXX_FLAGS "-m32 ${CMAKE_CXX_FLAGS}")
SET (CMAKE_C_FLAGS "-m32 ${CMAKE_C_FLAGS}")
SET (CMAKE_EXE_LINKER_FLAGS "-m32 ${CMAKE_EXE_LINKER_FLAGS}")
ENDIF ()
ENDIF ()
FIND_PACKAGE (GTest)
FIND_PACKAGE (ZLIB)
FIND_PACKAGE (Threads)
@ -31,12 +61,6 @@ int main(int argc, char * argv[])
}
" MSGPACK_ENABLE_GCC_CXX_ATOMIC)
IF (MSGPACK_ENABLE_CXX)
LIST (APPEND msgpack_SOURCES
src/object.cpp
)
ENDIF ()
IF (MSGPACK_ENABLE_GCC_CXX_ATOMIC)
LIST (APPEND msgpack_SOURCES
src/gcc_atomic.cpp
@ -53,51 +77,93 @@ LIST (APPEND msgpack_SOURCES
)
LIST (APPEND msgpack_HEADERS
src/msgpack/pack_define.h
src/msgpack/pack_template.h
src/msgpack/unpack_define.h
src/msgpack/unpack_template.h
src/msgpack/sysdep.h
src/msgpack/sbuffer.h
src/msgpack/version.h
src/msgpack/vrefbuffer.h
src/msgpack/zbuffer.h
src/msgpack/fbuffer.h
src/msgpack/pack.h
src/msgpack/unpack.h
src/msgpack/object.h
src/msgpack/zone.h
include/msgpack/pack_define.h
include/msgpack/pack_template.h
include/msgpack/unpack_define.h
include/msgpack/unpack_template.h
include/msgpack/util.h
include/msgpack/sysdep.h
include/msgpack/sbuffer.h
include/msgpack/version.h
include/msgpack/vrefbuffer.h
include/msgpack/zbuffer.h
include/msgpack/fbuffer.h
include/msgpack/pack.h
include/msgpack/unpack.h
include/msgpack/object.h
include/msgpack/zone.h
)
IF (MSGPACK_ENABLE_CXX)
LIST (APPEND msgpack_HEADERS
src/msgpack.hpp
src/msgpack/sbuffer.hpp
src/msgpack/vrefbuffer.hpp
src/msgpack/zbuffer.hpp
src/msgpack/fbuffer.hpp
src/msgpack/pack.hpp
src/msgpack/unpack.hpp
src/msgpack/object.hpp
src/msgpack/zone.hpp
src/msgpack/type.hpp
src/msgpack/type/bool.hpp
src/msgpack/type/deque.hpp
src/msgpack/type/float.hpp
src/msgpack/type/fixint.hpp
src/msgpack/type/int.hpp
src/msgpack/type/list.hpp
src/msgpack/type/map.hpp
src/msgpack/type/nil.hpp
src/msgpack/type/pair.hpp
src/msgpack/type/raw.hpp
src/msgpack/type/set.hpp
src/msgpack/type/string.hpp
src/msgpack/type/vector.hpp
src/msgpack/type/tuple.hpp
src/msgpack/type/define.hpp
src/msgpack/type/tr1/unordered_map.hpp
src/msgpack/type/tr1/unordered_set.hpp
include/msgpack.hpp
include/msgpack_fwd.hpp
include/msgpack/adaptor/bool.hpp
include/msgpack/adaptor/bool_fwd.hpp
include/msgpack/adaptor/char_ptr.hpp
include/msgpack/adaptor/char_ptr_fwd.hpp
include/msgpack/adaptor/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/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_char.hpp
include/msgpack/adaptor/vector_char_fwd.hpp
include/msgpack/cpp_config.hpp
include/msgpack/detail/cpp03_zone.hpp
include/msgpack/detail/cpp11_zone.hpp
include/msgpack/fbuffer.hpp
include/msgpack/object.hpp
include/msgpack/object_fwd.hpp
include/msgpack/pack.hpp
include/msgpack/sbuffer.hpp
include/msgpack/type.hpp
include/msgpack/unpack.hpp
include/msgpack/version.hpp
include/msgpack/versioning.hpp
include/msgpack/vrefbuffer.hpp
include/msgpack/zbuffer.hpp
include/msgpack/zone.hpp
)
ENDIF ()
@ -105,11 +171,6 @@ EXECUTE_PROCESS (
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/src/msgpack
)
CONFIGURE_FILE (
src/msgpack/version.h.in
${CMAKE_CURRENT_BINARY_DIR}/src/msgpack/version.h
)
CONFIGURE_FILE (
msgpack.pc.in
msgpack.pc
@ -118,10 +179,8 @@ CONFIGURE_FILE (
INCLUDE_DIRECTORIES (
./
src/
src/msgpack/
${CMAKE_CURRENT_BINARY_DIR}/src/
${CMAKE_CURRENT_BINARY_DIR}/src/msgpack/
include/
${CMAKE_CURRENT_BINARY_DIR}/include/
)
ADD_LIBRARY (msgpack SHARED
@ -136,10 +195,13 @@ ADD_LIBRARY (msgpack-static STATIC
SET_TARGET_PROPERTIES (msgpack-static PROPERTIES OUTPUT_NAME "msgpack")
SET_TARGET_PROPERTIES (msgpack PROPERTIES IMPORT_SUFFIX "_import.lib")
SET_TARGET_PROPERTIES (msgpack PROPERTIES SOVERSION 3 VERSION 3.0.0)
SET_TARGET_PROPERTIES (msgpack PROPERTIES SOVERSION 3 VERSION 4.0.0)
IF (MSGPACK_BUILD_TESTS)
ENABLE_TESTING ()
SET(CTEST_MEMORYCHECK_COMMAND "/usr/bin/valgrind")
INCLUDE(Dart)
SET(MEMORYCHECK_COMMAND_OPTIONS "--leak-check=full --error-exitcode=1")
ADD_SUBDIRECTORY (test)
ENDIF ()
@ -160,9 +222,7 @@ IF (NOT DEFINED CMAKE_INSTALL_LIBDIR)
ENDIF ()
INSTALL (TARGETS msgpack msgpack-static DESTINATION ${CMAKE_INSTALL_LIBDIR})
INSTALL (DIRECTORY src/msgpack DESTINATION include)
INSTALL (DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/src/msgpack DESTINATION include)
INSTALL (FILES src/msgpack.h src/msgpack.hpp DESTINATION include)
INSTALL (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX})
INSTALL (FILES ${CMAKE_CURRENT_BINARY_DIR}/msgpack.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig)
# Doxygen

121
README.md
View File

@ -10,7 +10,7 @@ MessagePack is an efficient binary serialization format. It lets you exchange da
## License
Msgpack is Copyright (C) 2008-2010 FURUHASHI Sadayuki and licensed under the Apache License, Version 2.0 (the "License"). For details see the `COPYING` file in this directory.
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.
## Contributing
@ -20,10 +20,23 @@ The source for msgpack-c is held at [msgpack-c](https://github.com/msgpack/msgpa
To report an issue, use the [msgpack-c issue tracker](https://github.com/msgpack/msgpack-c/issues) at github.com.
## Version
<<<<<<< HEAD
0.5.9 [![Build Status](https://travis-ci.org/msgpack/msgpack-c.svg?branch=master)](https://travis-ci.org/msgpack/msgpack-c)
=======
0.6.0 [![Build Status](https://travis-ci.org/msgpack/msgpack-c.svg?branch=poc/0.6)](https://travis-ci.org/msgpack/msgpack-c)
>>>>>>> 466986b5190ae8e03065e7b614702ec2f43dce1c
## Using Msgpack
### 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.
e.g.)
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.
### Building and Installing
#### Install from git repository
@ -31,100 +44,83 @@ To report an issue, use the [msgpack-c issue tracker](https://github.com/msgpack
##### Using autotools
You will need gcc (4.1.0 or higher), autotools.
```
$ git clone https://github.com/msgpack/msgpack-c.git
For C:
C++03 and C:
$ git clone https://github.com/redboltz/msgpack-c/tree/cxx_separate
$ cd msgpack-c
$ ./bootstrap
$ ./configure
$ make
$ sudo make install
```
For C++11:
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ ./bootstrap
$ ./configure CXXFLAGS="-std=c++11"
$ make
$ sudo make install
You need the compiler that fully supports C++11.
##### Using cmake
###### CUI
You will need gcc (4.1.0 or higher), cmake.
```
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ cmake .
$ make
```
#### Install from package
##### UNIX-like platform with ./configure
On typical UNIX-like platforms, download source package from [Releases](https://github.com/msgpack/msgpack-c/releases) and run `./configure && make && make install`. Example:
```
$ wget https://github.com/msgpack/msgpack-c/releases/download/cpp-0.5.9/msgpack-0.5.9.tar.gz
$ tar zxvf msgpack-0.5.9.tar.gz
$ cd msgpack-0.5.9
$ ./configure
$ make
$ sudo make install
```
##### FreeBSD with Ports Collection
If you want to setup C++11 version of msgpack, execute the following command:
On FreeBSD, you can use Ports Collection. Install [net/msgpack](http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/msgpack/) package.
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ cmake -DMSGPACK_CXX11=ON .
$ sudo make install
##### Gentoo Linux with Portage
You need the compiler that fully supports C++11.
On Gentoo Linux, you can use emerge. Install [dev-libs/msgpack](http://gentoo-portage.com/dev-libs/msgpack) package.
##### Mac OS X with MacPorts
On Mac OS X, you can install MessagePack for C using MacPorts.
```
$ sudo port install msgpack
```
You might need to run `sudo port selfupdate` before installing to update the package repository.
You can also install via Homebrew.
```
$ sudo brew install msgpack
```
##### Windows
##### GUI on Windows
Clone msgpack-c git repository.
```
$ git clone https://github.com/msgpack/msgpack-c.git
```
or using GUI git client.
e.g.) tortoise git https://code.google.com/p/tortoisegit/
Launch cmake GUI client. http://www.cmake.org/cmake/resources/software.html
1. Launch cmake GUI client. http://www.cmake.org/cmake/resources/software.html
Set 'Where is the source code:' text box and 'Where to build the binaries:' text box.
1. Set 'Where is the source code:' text box and 'Where to build the binaries:' text box.
Click 'Configure' button.
1. Click 'Configure' button.
Choose your Visual Studio version.
1. Choose your Visual Studio version.
Click 'Generate' button.
1. Click 'Generate' button.
Open the created msgpack.sln on Visual Studio.
1. Open the created msgpack.sln on Visual Studio.
Build all.
1. Build all.
### Linking with an Application
Include `msgpack.hpp` (or `msgpack.h` for C) in your application and link with libmsgpack. Here is a typical gcc link command:
g++ myapp.cpp -lmsgpack -o myapp
<<<<<<< HEAD
or using GUI git client.
=======
#### Install from package
>>>>>>> 466986b5190ae8e03065e7b614702ec2f43dce1c
Install from package for this branch (poc/0.6) is not supported yet.
### Code Example
```CPP
#include <msgpack.hpp>
#include <vector>
#include <string>
@ -142,7 +138,7 @@ int main() {
// Deserialize the serialized data.
msgpack::unpacked msg; // includes memory pool and deserialized object
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
msgpack::unpack(msg, sbuf.data(), sbuf.size());
msgpack::object obj = msg.get();
// Print the deserialized object to stdout.
@ -155,7 +151,10 @@ int main() {
// If the type is mismatched, it throws msgpack::type_error.
obj.as<int>(); // type is mismatched, msgpack::type_error is thrown
}
```
### Quickstart Guides
For more detailed examples see [QuickStart for C](QUICKSTART-C.md) and [QuickStart for C++](QUICKSTART-CPP.md).
### Documents
You can get addtional information on the wiki:
https://github.com/msgpack/msgpack-c/wiki/cpp_overview

View File

@ -9,10 +9,20 @@ fi
if [ $1 = "cpp11" ]
then
if [ $2 = "32" ]
then
./configure CFLAGS="-m32" CXXFLAGS="-std=c++11 -m32"
else
./configure CXXFLAGS="-std=c++11"
fi
else
if [ $2 = "32" ]
then
./configure CFLAGS="-m32" CXXFLAGS="-m32"
else
./configure
fi
fi
ret=$?
if [ $ret -ne 0 ]

View File

@ -1,4 +1,4 @@
#!/bin/sh
#!/bin/bash
mkdir build
@ -18,10 +18,20 @@ fi
if [ $1 = "cpp11" ]
then
if [ $2 = "32" ]
then
cmake -DMSGPACK_CXX11=ON -DMSGPACK_32BIT=ON ..
else
cmake -DMSGPACK_CXX11=ON ..
fi
else
if [ $2 = "32" ]
then
cmake -DMSGPACK_32BIT=ON ..
else
cmake ..
fi
fi
ret=$?
if [ $ret -ne 0 ]
@ -53,4 +63,21 @@ then
exit $ret
fi
if [ $2 != "32" ]
then
ctest -T memcheck | tee memcheck.log
ret=${PIPESTATUS[0]}
if [ $ret -ne 0 ]
then
exit $ret
fi
cat memcheck.log | grep "Memory Leak" > /dev/null
ret=$?
if [ $ret -eq 0 ]
then
exit 1
fi
fi
exit 0

View File

@ -1,8 +1,7 @@
AC_INIT(src/object.cpp)
AC_INIT(msgpack, m4_esyscmd([cat include/msgpack/version_master.h | tr -d "\n" | sed -e 's/#define MSGPACK_VERSION_MAJOR\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_CONFIG_AUX_DIR(ac)
AM_INIT_AUTOMAKE(msgpack, 0.5.9)
AM_INIT_AUTOMAKE
AC_CONFIG_HEADER(config.h)
AC_SUBST(CFLAGS)
CFLAGS="-O3 -Wall $CFLAGS"
@ -85,16 +84,15 @@ fi
AM_CONDITIONAL(ENABLE_GCC_CXX_ATOMIC, test "$enable_gcc_cxx_atomic" = "yes")
major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\1/'`
minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).*/\2/'`
major=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).\([[0-9]]*\).*/\1/'`
minor=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).\([[0-9]]*\).*/\2/'`
revision=`echo $VERSION | sed 's/\([[0-9]]*\)\.\([[0-9]]*\).\([[0-9]]*\).*/\3/'`
AC_SUBST(VERSION_MAJOR, $major)
AC_SUBST(VERSION_MINOR, $minor)
AC_SUBST(VERSION_REVISION, $revision)
AC_OUTPUT([Makefile
msgpack.pc
src/Makefile
src/msgpack/version.h
test/Makefile])

155
erb/cpp03_define.hpp.erb Normal file
View File

@ -0,0 +1,155 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP03_DEFINE_HPP
#define MSGPACK_CPP03_DEFINE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/adaptor/msgpack_tuple_fwd.hpp"
#include "msgpack/object_fwd.hpp"
#define MSGPACK_DEFINE(...) \
template <typename Packer> \
void msgpack_pack(Packer& pk) const \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
} \
void msgpack_unpack(msgpack::object const& o) \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
}\
template <typename MSGPACK_OBJECT> \
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
}
// MSGPACK_ADD_ENUM must be used in the global namespace.
#define MSGPACK_ADD_ENUM(enum) \
namespace msgpack { \
MSGPACK_API_VERSION_NAMESPACE(v1) { \
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 { \
template <typename Stream> \
struct packer_serializer<Stream, enum> { \
static packer<Stream>& pack(packer<Stream>& o, const enum& v) { \
return o << static_cast<int>(v); \
} \
}; \
} \
} \
}
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
<% GENERATION_LIMIT = 31 %>
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
struct define;
template <>
struct define<> {
typedef define<> value_type;
typedef tuple<> tuple_type;
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(0);
}
void msgpack_unpack(msgpack::object const& o)
{
if(o.type != type::ARRAY) { throw type_error(); }
}
void msgpack_object(msgpack::object* o, msgpack::zone&) const
{
o->type = type::ARRAY;
o->via.array.ptr = nullptr;
o->via.array.size = 0;
}
};
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
typedef define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> tuple_type;
define(A0& _a0<%1.upto(i) {|j|%>, A<%=j%>& _a<%=j%><%}%>) :
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(<%=i+1%>);
<%0.upto(i) {|j|%>
pk.pack(a<%=j%>);<%}%>
}
void msgpack_unpack(msgpack::object const& o)
{
if(o.type != type::ARRAY) { throw type_error(); }
const size_t size = o.via.array.size;
if(size > 0) {
msgpack::object *ptr = o.via.array.ptr;
switch(size) {
default:<%(i).downto(0) {|j|%>
case <%=j+1%>: ptr[<%=j%>].convert(a<%=j%>);<%}%>
}
}
}
void msgpack_object(msgpack::object* o, msgpack::zone& z) const
{
o->type = type::ARRAY;
o->via.array.ptr = static_cast<object*>(z.allocate_align(sizeof(object)*<%=i+1%>));
o->via.array.size = <%=i+1%>;
<%0.upto(i) {|j|%>
o->via.array.ptr[<%=j%>] = object(a<%=j%>, z);<%}%>
}
<%0.upto(i) {|j|%>
A<%=j%>& a<%=j%>;<%}%>
};
<%}%>
inline define<> make_define()
{
return define<>();
}
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_define(A0& a0<%1.upto(i) {|j|%>, A<%=j%>& a<%=j%><%}%>)
{
return define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
}
<%}%>
} // namespace type
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP03_DEFINE_HPP

View File

@ -0,0 +1,216 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP03_MSGPACK_TUPLE_HPP
#define MSGPACK_CPP03_MSGPACK_TUPLE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
// FIXME operator==
// FIXME operator!=
<% GENERATION_LIMIT = 31 %>
template <typename A0<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%><%}%>>
struct tuple;
template <typename Tuple, int N>
struct tuple_element;
template <typename Tuple, int N>
struct const_tuple_element;
template <typename T>
struct tuple_type {
typedef T type;
typedef T value_type;
typedef T& reference;
typedef const T& const_reference;
typedef const T& transparent_reference;
};
template <typename T>
struct tuple_type<T&> {
typedef T type;
typedef T& value_type;
typedef T& reference;
typedef const T& const_reference;
typedef T& transparent_reference;
};
template <typename T>
struct tuple_type<const T&> {
typedef T type;
typedef T& value_type;
typedef T& reference;
typedef const T& const_reference;
typedef const T& transparent_reference;
};
<%0.upto(GENERATION_LIMIT) {|i|%>
<%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
struct tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> {
tuple_element(tuple<A0<%1.upto(i) {|k|%>, A<%=k%> <%}%>>& x) : m_x(x.a<%=j%>) {}
typename tuple_type<A<%=j%>>::reference get() { return m_x; }
typename tuple_type<A<%=j%>>::const_reference get() const { return m_x; }
private:
typename tuple_type<A<%=j%>>::reference m_x;
};
<%}%>
<%}%>
<%0.upto(GENERATION_LIMIT) {|i|%>
<%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
struct const_tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>> : tuple_type<A<%=j%>> {
const_tuple_element(const tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>& x) : m_x(x.a<%=j%>) {}
typename tuple_type<A<%=j%>>::const_reference get() const { return m_x; }
private:
typename tuple_type<A<%=j%>>::const_reference m_x;
};
<%}%>
<%}%>
template <>
struct tuple<> {
tuple() {}
tuple(object const& o) { o.convert(*this); }
typedef tuple<> value_type;
};
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
tuple() {}
tuple(typename tuple_type<A0>::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference _a<%=j%><%}%>) :
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
tuple(object const& o) { o.convert(*this); }
template <int N> typename tuple_element<value_type, N>::reference get()
{ return tuple_element<value_type, N>(*this).get(); }
template <int N> typename const_tuple_element<value_type, N>::const_reference get() const
{ return const_tuple_element<value_type, N>(*this).get(); }
<%0.upto(i) {|j|%>
A<%=j%> a<%=j%>;<%}%>
};
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
inline typename type::tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& t)
{ return t.template get<N>(); }
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
inline typename type::const_tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::const_reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> const& t)
{ return t.template get<N>(); }
<%}%>
inline tuple<> make_tuple()
{
return tuple<>();
}
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
inline tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference a<%=j%><%}%>)
{
return tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>(a0<%1.upto(i) {|j|%>, a<%=j%><%}%>);
}
<%}%>
} // namespace type
inline object const& operator>> (
object const& o,
type::tuple<>&) {
if(o.type != type::ARRAY) { throw type_error(); }
return o;
}
<%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;
}
<%}%>
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;
}
<%}%>
inline void operator<< (
object::with_zone& o,
const type::tuple<>&) {
o.type = type::ARRAY;
o.via.array.ptr = nullptr;
o.via.array.size = 0;
}
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
inline void operator<< (
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);<%}%>
}
<%}%>
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
//inline std::ostream& operator<< (std::ostream& o, const msgpack::type::tuple<>& v) {
// return o << "[]";
//}
//<%0.upto(GENERATION_LIMIT) {|i|%>
//template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
//inline std::ostream& operator<< (std::ostream& o,
// const msgpack::type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) {
// return o << "["
// <%0.upto(i) {|j|%>
// <<<%if j != 0 then%> ", " <<<%end%> v.template get<<%=j%>>()<%}%>
// << "]";
//}
//<%}%>
#endif // MSGPACK_CPP03_MSGPACK_TUPLE_HPP

View File

@ -0,0 +1,125 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP03_MSGPACK_TUPLE_FWD_HPP
#define MSGPACK_CPP03_MSGPACK_TUPLE_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
// FIXME operator==
// FIXME operator!=
<% GENERATION_LIMIT = 31 %>
template <typename A0 = void<%1.upto(GENERATION_LIMIT+1) {|i|%>, typename A<%=i%> = void<%}%>>
struct tuple;
template <typename Tuple, int N>
struct tuple_element;
template <typename Tuple, int N>
struct const_tuple_element;
template <typename T>
struct tuple_type;
<%0.upto(GENERATION_LIMIT) {|i|%>
<%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
struct tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>>;
<%}%>
<%}%>
<%0.upto(GENERATION_LIMIT) {|i|%>
<%0.upto(i) {|j|%>
template <typename A0<%1.upto(i) {|k|%>, typename A<%=k%><%}%>>
struct const_tuple_element<tuple<A0<%1.upto(i) {|k|%>, A<%=k%><%}%>>, <%=j%>>;
<%}%>
<%}%>
template <>
struct tuple<>;
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>;
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
typename type::tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& t);
template <int N, typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
typename type::const_tuple_element<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>, N>::const_reference get(type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> const& t);
<%}%>
tuple<> make_tuple();
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> make_tuple(typename tuple_type<A0>::transparent_reference a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference a<%=j%><%}%>);
<%}%>
} // namespace type
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

310
erb/cpp03_zone.hpp.erb Normal file
View File

@ -0,0 +1,310 @@
//
// MessagePack for C++ memory pool
//
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP03_ZONE_HPP
#define MSGPACK_CPP03_ZONE_HPP
#include <cstdlib>
#include <memory>
#include <vector>
#include "msgpack/versioning.hpp"
#ifndef MSGPACK_ZONE_CHUNK_SIZE
#define MSGPACK_ZONE_CHUNK_SIZE 8192
#endif
#ifndef MSGPACK_ZONE_ALIGN
#define MSGPACK_ZONE_ALIGN sizeof(int)
#endif
<% GENERATION_LIMIT = 15 %>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
class zone {
struct finalizer {
finalizer(void (*func)(void*), void* data):m_func(func), m_data(data) {}
void operator()() { m_func(m_data); }
void (*m_func)(void*);
void* m_data;
};
struct finalizer_array {
finalizer_array():m_tail(nullptr), m_end(nullptr), m_array(nullptr) {}
void call() {
finalizer* fin = m_tail;
for(; fin != m_array; --fin) (*(fin-1))();
}
~finalizer_array() {
call();
::free(m_array);
}
void clear() {
call();
m_tail = m_array;
}
void push(void (*func)(void* data), void* data)
{
finalizer* fin = m_tail;
if(fin == m_end) {
push_expand(func, data);
return;
}
fin->m_func = func;
fin->m_data = data;
++m_tail;
}
void push_expand(void (*func)(void*), void* data) {
const size_t nused = m_end - m_array;
size_t nnext;
if(nused == 0) {
nnext = (sizeof(finalizer) < 72/2) ?
72 / sizeof(finalizer) : 8;
} else {
nnext = nused * 2;
}
finalizer* tmp =
static_cast<finalizer*>(::realloc(m_array, sizeof(finalizer) * nnext));
if(!tmp) {
throw std::bad_alloc();
}
m_array = tmp;
m_end = tmp + nnext;
m_tail = tmp + nused;
new (m_tail) finalizer(func, data);
++m_tail;
}
finalizer* m_tail;
finalizer* m_end;
finalizer* m_array;
};
struct chunk {
chunk* m_next;
};
struct chunk_list {
chunk_list(size_t chunk_size)
{
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
if(!c) {
throw std::bad_alloc();
}
m_head = c;
m_free = chunk_size;
m_ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->m_next = nullptr;
}
~chunk_list()
{
chunk* c = m_head;
while(c) {
chunk* n = c->m_next;
::free(c);
c = n;
}
}
void clear(size_t chunk_size)
{
chunk* c = m_head;
while(true) {
chunk* n = c->m_next;
if(n) {
::free(c);
c = n;
} else {
break;
}
}
m_head->m_next = nullptr;
m_free = chunk_size;
m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
}
size_t m_free;
char* m_ptr;
chunk* m_head;
};
size_t m_chunk_size;
chunk_list m_chunk_list;
finalizer_array m_finalizer_array;
public:
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
public:
void* allocate_align(size_t size);
void* allocate_no_align(size_t size);
void push_finalizer(void (*func)(void*), void* data);
template <typename T>
void push_finalizer(msgpack::unique_ptr<T> obj);
void clear();
void swap(zone& o);
static void* operator new(std::size_t size) throw(std::bad_alloc)
{
void* p = ::malloc(size);
if (!p) throw std::bad_alloc();
return p;
}
static void operator delete(void *p) throw()
{
::free(p);
}
static void* operator new(std::size_t size, void* place) throw()
{
return ::operator new(size, place);
}
static void operator delete(void* p, void* place) throw()
{
::operator delete(p, place);
}
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename T<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
T* allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>);
<%}%>
private:
void undo_allocate(size_t size);
template <typename T>
static void object_destruct(void* obj);
template <typename T>
static void object_delete(void* obj);
void* allocate_expand(size_t size);
};
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)
{
return allocate_no_align(
((size)+((MSGPACK_ZONE_ALIGN)-1)) & ~((MSGPACK_ZONE_ALIGN)-1));
}
inline void* zone::allocate_no_align(size_t size)
{
if(m_chunk_list.m_free < size) {
return allocate_expand(size);
}
char* ptr = m_chunk_list.m_ptr;
m_chunk_list.m_free -= size;
m_chunk_list.m_ptr += size;
return ptr;
}
inline void* zone::allocate_expand(size_t size)
{
chunk_list* const cl = &m_chunk_list;
size_t sz = m_chunk_size;
while(sz < size) {
sz *= 2;
}
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
if (!c) throw std::bad_alloc();
char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->m_next = cl->m_head;
cl->m_head = c;
cl->m_free = sz - size;
cl->m_ptr = ptr + size;
return ptr;
}
inline void zone::push_finalizer(void (*func)(void*), void* data)
{
m_finalizer_array.push(func, data);
}
template <typename T>
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
{
m_finalizer_array.push(&zone::object_delete<T>, obj.release());
}
inline void zone::clear()
{
m_finalizer_array.clear();
m_chunk_list.clear(m_chunk_size);
}
inline void zone::swap(zone& o)
{
std::swap(*this, o);
}
template <typename T>
void zone::object_destruct(void* obj)
{
static_cast<T*>(obj)->~T();
}
template <typename T>
void zone::object_delete(void* obj)
{
delete static_cast<T*>(obj);
}
inline void zone::undo_allocate(size_t size)
{
m_chunk_list.m_ptr -= size;
m_chunk_list.m_free += size;
}
<%0.upto(GENERATION_LIMIT) {|i|%>
template <typename T<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
T* zone::allocate(<%=(1..i).map{|j|"A#{j} a#{j}"}.join(', ')%>)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(<%=(1..i).map{|j|"a#{j}"}.join(', ')%>);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
<%}%>
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP03_ZONE_HPP

View File

@ -30,9 +30,9 @@ int main(void)
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, oc);
msgpack::zone zone;
msgpack::object obj;
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.data(), sbuf.size());
msgpack::object obj = result.get();
obj.convert(&nc);
@ -46,9 +46,9 @@ int main(void)
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, nc);
msgpack::zone zone;
msgpack::object obj;
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &zone, &obj);
msgpack::unpacked result;
msgpack::unpack(result, sbuf.data(), sbuf.size());
msgpack::object obj = result.get();
obj.convert(&oc);

119
example/lib_buffer_unpack.c Normal file
View File

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

View File

@ -11,17 +11,17 @@ namespace myprotocol {
Get() { }
Get(uint32_t f, const std::string& k) :
define_type(msgpack_type(f, k)) { }
uint32_t& flags() { return get<0>(); }
std::string& key() { return get<1>(); }
uint32_t& flags() { return msgpack::type::get<0>(*this); }
std::string& key() { return msgpack::type::get<1>(*this); }
};
struct Put : define< tuple<uint32_t, std::string, raw_ref> > {
Put() { }
Put(uint32_t f, const std::string& k, const char* valref, uint32_t vallen) :
define_type(msgpack_type( f, k, raw_ref(valref,vallen) )) { }
uint32_t& flags() { return get<0>(); }
std::string& key() { return get<1>(); }
raw_ref& value() { return get<2>(); }
uint32_t& flags() { return msgpack::type::get<0>(*this); }
std::string& key() { return msgpack::type::get<1>(*this); }
raw_ref& value() { return msgpack::type::get<2>(*this); }
};
struct MultiGet : define< std::vector<Get> > {
@ -46,12 +46,12 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::zone mempool;
msgpack::object o =
msgpack::unpack(buffer.data(), buffer.size(), mempool);
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
myprotocol::Get req;
msgpack::convert(req, o);
o.convert(req);
std::cout << "received: " << o << std::endl;
}
@ -74,12 +74,13 @@ int main(void)
{
std::string buffer(stream.str());
msgpack::zone mempool;
msgpack::object o =
msgpack::unpack(buffer.data(), buffer.size(), mempool);
msgpack::unpacked result;
msgpack::unpack(result, buffer.data(), buffer.size());
msgpack::object o = result.get();
myprotocol::MultiGet req;
msgpack::convert(req, o);
o.convert(req);
std::cout << "received: " << o << std::endl;
}
}

View File

@ -14,8 +14,8 @@ int main(void)
msgpack_pack_array(&pk, 3);
msgpack_pack_int(&pk, 1);
msgpack_pack_true(&pk);
msgpack_pack_raw(&pk, 7);
msgpack_pack_raw_body(&pk, "example", 7);
msgpack_pack_str(&pk, 7);
msgpack_pack_str_body(&pk, "example", 7);
/* deserialize the buffer into msgpack_object instance. */
/* deserialized object is valid during the msgpack_zone instance alive. */

View File

@ -18,11 +18,12 @@ int main(void)
// deserialize the buffer into msgpack::object instance.
std::string str(buffer.str());
// deserialized object is valid during the msgpack::zone instance alive.
msgpack::zone mempool;
msgpack::unpacked result;
msgpack::object deserialized;
msgpack::unpack(str.data(), str.size(), NULL, &mempool, &deserialized);
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;

55
example/speed_test.cc Normal file
View File

@ -0,0 +1,55 @@
// g++ -std=c++11 -O3 -g -Ipath_to_msgpack_src -Ipath_to_boost speed_test.cc -Lpath_to_boost_lib -lboost_timer -lboost_system
// export LD_LIBRARY_PATH=path_to_boost_lib
#include <msgpack.hpp>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <boost/timer/timer.hpp>
void test_map_pack_unpack() {
std::cout << "[TEST][map_pack_unpack]" << std::endl;
// setup
std::cout << "Setting up map data..." << std::endl;
std::map<int, int> m1;
int const num = 30000000L;
for (int i = 0; i < num; ++i) m1[i] = i;
std::cout << "Start packing..." << std::endl;
std::stringstream buffer;
{
boost::timer::cpu_timer timer;
msgpack::pack(buffer, m1);
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Pack finished..." << std::endl;
buffer.seekg(0);
std::string str(buffer.str());
msgpack::unpacked unpacked;
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(unpacked, str.data(), str.size());
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Unpack finished..." << std::endl;
std::map<int, int> m2;
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
unpacked.get().convert(&m2);
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Convert finished..." << std::endl;
}
int main(void)
{
test_map_pack_unpack();
}

View File

@ -0,0 +1,78 @@
// g++ -std=c++11 -O3 -g -Ipath_to_msgpack_src -Ipath_to_boost speed_test.cc -Lpath_to_boost_lib -lboost_timer -lboost_system
// export LD_LIBRARY_PATH=path_to_boost_lib
#include <msgpack.hpp>
#include <string>
#include <iostream>
#include <sstream>
#include <vector>
#include <boost/timer/timer.hpp>
template <typename T, std::size_t level>
struct vecvec {
typedef std::vector<typename vecvec<T, level - 1>::type> type;
static void fill(type& v, std::size_t num_of_elems, T const& val) {
for (int elem = 0; elem < num_of_elems; ++elem) {
typename vecvec<T, level - 1>::type child;
vecvec<T, level - 1>::fill(child, num_of_elems, val);
v.push_back(child);
}
}
};
template <typename T>
struct vecvec<T, 0> {
typedef std::vector<T> type;
static void fill(type& v, std::size_t num_of_elems, T const& val) {
for (int elem = 0; elem < num_of_elems; ++elem) {
v.push_back(val);
}
}
};
void test_array_of_array() {
std::cout << "[TEST][array_of_array]" << std::endl;
// setup
int const depth = 16;
std::cout << "Setting up array data..." << std::endl;
typename vecvec<int, depth>::type v1;
vecvec<int, depth>::fill(v1, 3, 42);
std::cout << "Start packing..." << std::endl;
std::stringstream buffer;
{
boost::timer::cpu_timer timer;
msgpack::pack(buffer, v1);
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Pack finished..." << std::endl;
buffer.seekg(0);
std::string str(buffer.str());
msgpack::unpacked unpacked;
std::cout << "Start unpacking...by void unpack(unpacked& result, const char* data, size_t len)" << std::endl;
{
boost::timer::cpu_timer timer;
msgpack::unpack(unpacked, str.data(), str.size());
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Unpack finished..." << std::endl;
typename vecvec<int, depth>::type v2;
std::cout << "Start converting..." << std::endl;
{
boost::timer::cpu_timer timer;
unpacked.get().convert(&v2);
std::string result = timer.format();
std::cout << result << std::endl;
}
std::cout << "Convert finished..." << std::endl;
}
int main(void)
{
test_array_of_array();
}

View File

@ -13,7 +13,7 @@ public:
~Server() { }
typedef std::auto_ptr<msgpack::zone> auto_zone;
typedef msgpack::unique_ptr<msgpack::zone> auto_zone;
void socket_readable()
{

View File

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

View File

@ -21,6 +21,7 @@
* @}
*/
#include "msgpack/util.h"
#include "msgpack/object.h"
#include "msgpack/zone.h"
#include "msgpack/pack.h"

View File

@ -21,4 +21,4 @@
#include "msgpack/unpack.hpp"
#include "msgpack/sbuffer.hpp"
#include "msgpack/vrefbuffer.hpp"
#include "msgpack.h"
#include "msgpack/version.hpp"

View File

@ -15,20 +15,22 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_BOOL_HPP__
#define MSGPACK_TYPE_BOOL_HPP__
#ifndef MSGPACK_TYPE_BOOL_HPP
#define MSGPACK_TYPE_BOOL_HPP
#include "msgpack/object.hpp"
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
inline bool& operator>> (object o, bool& v)
inline object const& operator>> (object const& o, bool& v)
{
if(o.type != type::BOOLEAN) { throw type_error(); }
v = o.via.boolean;
return v;
return o;
}
template <typename Stream>
@ -49,7 +51,8 @@ inline void operator<< (object::with_zone& o, bool v)
{ static_cast<object&>(o) << v; }
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/type/bool.hpp */
#endif // MSGPACK_TYPE_BOOL_HPP

View File

@ -0,0 +1,39 @@
//
// 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

View File

@ -0,0 +1,60 @@
//
// 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_HPP
#define MSGPACK_TYPE_CHAR_PTR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <cstring>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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;
}
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);
}
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);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_CHAR_PTR_HPP

View File

@ -0,0 +1,38 @@
//
// 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

View File

@ -0,0 +1,73 @@
//
// 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_HPP
#define MSGPACK_CPP11_ARRAY_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>
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);
}
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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP11_ARRAY_HPP

View File

@ -0,0 +1,79 @@
//
// 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_HPP
#define MSGPACK_TYPE_ARRAY_CHAR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_fwd.hpp"
#include <array>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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;
}
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());
}
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());
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_ARRAY_CHAR_HPP

View File

@ -0,0 +1,45 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP
#define MSGPACK_TYPE_ARRAY_CHAR_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <array>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <std::size_t N>
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

View File

@ -0,0 +1,44 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP11_ARRAY_FWD_HPP
#define MSGPACK_CPP11_ARRAY_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <array>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename T, std::size_t N>
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

View File

@ -0,0 +1,73 @@
//
// 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_HPP
#define MSGPACK_CPP11_FORWARD_LIST_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <forward_list>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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;
}
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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP11_FORWARD_LIST_HPP

View File

@ -0,0 +1,44 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP11_FORWARD_LIST_FWD_HPP
#define MSGPACK_CPP11_FORWARD_LIST_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <forward_list>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename T>
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

View File

@ -0,0 +1,149 @@
//
// 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_HPP
#define MSGPACK_CPP11_TUPLE_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 {
static void pack(
packer<Stream>& o,
const Tuple& v) {
StdTuplePacker<Stream, Tuple, N-1>::pack(o, v);
o.pack(std::get<N-1>(v));
}
};
template <typename Stream, typename Tuple>
struct StdTuplePacker<Stream, Tuple, 1> {
static void pack (
packer<Stream>& o,
const Tuple& v) {
o.pack(std::get<0>(v));
}
};
template <typename Stream, typename Tuple>
struct StdTuplePacker<Stream, Tuple, 0> {
static void pack (
packer<Stream>&,
const Tuple&) {
}
};
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;
}
// --- Convert from tuple to object ---
template <typename Tuple, std::size_t N>
struct StdTupleConverter {
static void convert(
object const& o,
Tuple& v) {
StdTupleConverter<Tuple, N-1>::convert(o, v);
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(std::get<N-1>(v))>::type>(std::get<N-1>(v));
}
};
template <typename Tuple>
struct StdTupleConverter<Tuple, 1> {
static void convert (
object const& o,
Tuple& v) {
o.via.array.ptr[0].convert<typename std::remove_reference<decltype(std::get<0>(v))>::type>(std::get<0>(v));
}
};
template <typename Tuple>
struct StdTupleConverter<Tuple, 0> {
static void convert (
object const&,
Tuple&) {
}
};
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;
}
// --- Convert from tuple to object with zone ---
template <typename Tuple, std::size_t N>
struct StdTupleToObjectWithZone {
static void convert(
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);
}
};
template <typename Tuple>
struct StdTupleToObjectWithZone<Tuple, 1> {
static void convert (
object::with_zone& o,
const Tuple& v) {
o.via.array.ptr[0] = object(std::get<0>(v), o.zone);
}
};
template <typename Tuple>
struct StdTupleToObjectWithZone<Tuple, 0> {
static void convert (
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);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP11_TUPLE_HPP

View File

@ -0,0 +1,62 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP11_TUPLE_FWD_HPP
#define MSGPACK_CPP11_TUPLE_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <tuple>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
// --- Pack ( from tuple to packer stream ---
template <typename Stream, typename Tuple, std::size_t N>
struct StdTuplePacker;
template <typename Stream, typename... Args>
const 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

View File

@ -0,0 +1,29 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_DEFINE_HPP
#define MSGPACK_DEFINE_HPP
#include "msgpack/cpp_config.hpp"
#if defined(MSGPACK_USE_CPP03)
#include "detail/cpp03_define.hpp"
#else // MSGPACK_USE_CPP03
#include "detail/cpp11_define.hpp"
#endif // MSGPACK_USE_CPP03
#endif // MSGPACK_DEFINE_HPP

View File

@ -0,0 +1,79 @@
//
// 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_DEQUE_HPP
#define MSGPACK_TYPE_DEQUE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <deque>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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);
}
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());
it != it_end; ++it) {
o.pack(*it);
}
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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/type/deque.hpp */

View File

@ -0,0 +1,40 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_DEQUE_FWD_HPP
#define MSGPACK_TYPE_DEQUE_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <deque>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename T>
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

View File

@ -0,0 +1,181 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP11_DEFINE_HPP
#define MSGPACK_CPP11_DEFINE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
// for MSGPACK_ADD_ENUM
#include "msgpack/adaptor/int_fwd.hpp"
#include <type_traits>
#include <tuple>
#define MSGPACK_DEFINE(...) \
template <typename Packer> \
void msgpack_pack(Packer& pk) const \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \
} \
void msgpack_unpack(msgpack::object const& o) \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \
}\
template <typename MSGPACK_OBJECT> \
void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \
{ \
msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \
}
// MSGPACK_ADD_ENUM must be used in the global namespace.
#define MSGPACK_ADD_ENUM(enum) \
namespace msgpack { \
MSGPACK_API_VERSION_NAMESPACE(v1) { \
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 { \
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); \
} \
}; \
} \
} \
}
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
template <typename Tuple, std::size_t N>
struct define_imp {
template <typename Packer>
static void pack(Packer& pk, Tuple const& t) {
define_imp<Tuple, N-1>::pack(pk, t);
pk.pack(std::get<N-1>(t));
}
static void unpack(msgpack::object const& o, Tuple& t) {
define_imp<Tuple, N-1>::unpack(o, t);
const size_t size = o.via.array.size;
if(size <= N-1) { return; }
o.via.array.ptr[N-1].convert(std::get<N-1>(t));
}
static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) {
define_imp<Tuple, N-1>::object(o, z, t);
o->via.array.ptr[N-1] = msgpack::object(std::get<N-1>(t), z);
}
};
template <typename Tuple>
struct define_imp<Tuple, 1> {
template <typename Packer>
static void pack(Packer& pk, Tuple const& t) {
pk.pack(std::get<0>(t));
}
static void unpack(msgpack::object const& o, Tuple& t) {
const size_t size = o.via.array.size;
if(size <= 0) { return; }
o.via.array.ptr[0].convert(std::get<0>(t));
}
static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) {
o->via.array.ptr[0] = msgpack::object(std::get<0>(t), z);
}
};
template <typename... Args>
struct define {
typedef define<Args...> value_type;
typedef std::tuple<Args...> tuple_type;
define(Args&... args) :
a(args...) {}
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(sizeof...(Args));
define_imp<std::tuple<Args&...>, sizeof...(Args)>::pack(pk, a);
}
void msgpack_unpack(msgpack::object const& o)
{
if(o.type != type::ARRAY) { throw 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->via.array.size = sizeof...(Args);
define_imp<std::tuple<Args&...>, sizeof...(Args)>::object(o, z, a);
}
std::tuple<Args&...> a;
};
template <>
struct define<> {
typedef define<> value_type;
typedef std::tuple<> tuple_type;
template <typename Packer>
void msgpack_pack(Packer& pk) const
{
pk.pack_array(0);
}
void msgpack_unpack(msgpack::object const& o)
{
if(o.type != type::ARRAY) { throw type_error(); }
}
void msgpack_object(msgpack::object* o, msgpack::zone&) const
{
o->type = type::ARRAY;
o->via.array.ptr = NULL;
o->via.array.size = 0;
}
};
inline define<> make_define()
{
return define<>();
}
template <typename... Args>
define<Args...> make_define(Args&... args)
{
return define<Args...>(args...);
}
} // namespace type
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP11_DEFINE_HPP

View File

@ -0,0 +1,212 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP11_MSGPACK_TUPLE_HPP
#define MSGPACK_CPP11_MSGPACK_TUPLE_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <tuple>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
// tuple
using std::get;
using std::tuple_size;
using std::tuple_element;
using std::uses_allocator;
using std::ignore;
using std::make_tuple;
using std::tie;
using std::forward_as_tuple;
using std::swap;
template< class... Types >
class tuple : public std::tuple<Types...> {
public:
using base = std::tuple<Types...>;
using base::tuple;
tuple() = default;
tuple(tuple const&) = default;
tuple(tuple&&) = default;
template<typename... OtherTypes>
tuple(tuple<OtherTypes...> const& other):base(static_cast<std::tuple<OtherTypes...> const&>(other)) {}
template<typename... OtherTypes>
tuple(tuple<OtherTypes...> && other):base(static_cast<std::tuple<OtherTypes...> &&>(other)) {}
tuple& operator=(tuple const&) = default;
tuple& operator=(tuple&&) = default;
template<typename... OtherTypes>
tuple& operator=(tuple<OtherTypes...> const& other) {
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> const&>(other);
return *this;
}
template<typename... OtherTypes>
tuple& operator=(tuple<OtherTypes...> && other) {
*static_cast<base*>(this) = static_cast<std::tuple<OtherTypes...> &&>(other);
return *this;
}
template< std::size_t I>
typename tuple_element<I, base >::type&
get() { return std::get<I>(*this); }
template< std::size_t I>
typename tuple_element<I, base >::type const&
get() const { return std::get<I>(*this); }
template< std::size_t I>
typename tuple_element<I, base >::type&&
get() && { return std::get<I>(*this); }
};
template< class... Tuples >
auto tuple_cat(Tuples&&... args) ->
decltype(
std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...)
) {
return std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...);
}
} // namespace type
// --- Pack ( from tuple to packer stream ---
template <typename Stream, typename Tuple, std::size_t N>
struct MsgpackTuplePacker {
static void pack(
packer<Stream>& o,
const Tuple& v) {
MsgpackTuplePacker<Stream, Tuple, N-1>::pack(o, v);
o.pack(type::get<N-1>(v));
}
};
template <typename Stream, typename Tuple>
struct MsgpackTuplePacker<Stream, Tuple, 1> {
static void pack (
packer<Stream>& o,
const Tuple& v) {
o.pack(type::get<0>(v));
}
};
template <typename Stream, typename Tuple>
struct MsgpackTuplePacker<Stream, Tuple, 0> {
static void pack (
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;
}
// --- Convert from tuple to object ---
template <typename Tuple, std::size_t N>
struct MsgpackTupleConverter {
static void convert(
object const& o,
Tuple& v) {
MsgpackTupleConverter<Tuple, N-1>::convert(o, v);
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(type::get<N-1>(v))>::type>(type::get<N-1>(v));
}
};
template <typename Tuple>
struct MsgpackTupleConverter<Tuple, 1> {
static void convert (
object const& o,
Tuple& v) {
o.via.array.ptr[0].convert<typename std::remove_reference<decltype(type::get<0>(v))>::type>(type::get<0>(v));
}
};
template <typename Tuple>
struct MsgpackTupleConverter<Tuple, 0> {
static void convert (
object const&,
Tuple&) {
}
};
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;
}
// --- Convert from tuple to object with zone ---
template <typename Tuple, std::size_t N>
struct MsgpackTupleToObjectWithZone {
static void convert(
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);
}
};
template <typename Tuple>
struct MsgpackTupleToObjectWithZone<Tuple, 1> {
static void convert (
object::with_zone& o,
const Tuple& v) {
o.via.array.ptr[0] = object(type::get<0>(v), o.zone);
}
};
template <typename Tuple>
struct MsgpackTupleToObjectWithZone<Tuple, 0> {
static void convert (
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);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP11_MSGPACK_TUPLE_HPP

View File

@ -0,0 +1,84 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP11_MSGPACK_TUPLE_FWD_HPP
#define MSGPACK_CPP11_MSGPACK_TUPLE_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <tuple>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
// tuple
using std::get;
using std::tuple_size;
using std::tuple_element;
using std::uses_allocator;
using std::ignore;
using std::make_tuple;
using std::tie;
using std::forward_as_tuple;
using std::swap;
template< class... Types >
class tuple;
template< class... Tuples >
auto tuple_cat(Tuples&&... args) ->
decltype(
std::tuple_cat(std::forward<typename std::remove_reference<Tuples>::type::base>(args)...)
);
} // namespace type
// --- Pack ( from tuple to packer stream ---
template <typename Stream, typename Tuple, std::size_t N>
struct MsgpackTuplePacker;
template <typename Stream, typename... Args>
const 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

View File

@ -0,0 +1,212 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2020 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_FIXINT_HPP
#define MSGPACK_TYPE_FIXINT_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include "msgpack/adaptor/int.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
template <typename T>
struct fix_int {
fix_int() : value(0) { }
fix_int(T value) : value(value) { }
operator T() const { return value; }
T get() const { return value; }
private:
T value;
};
typedef fix_int<uint8_t> fix_uint8;
typedef fix_int<uint16_t> fix_uint16;
typedef fix_int<uint32_t> fix_uint32;
typedef fix_int<uint64_t> fix_uint64;
typedef fix_int<int8_t> fix_int8;
typedef fix_int<int16_t> fix_int16;
typedef fix_int<int32_t> fix_int32;
typedef fix_int<int64_t> fix_int64;
} // namespace type
inline object const& operator>> (object const& o, type::fix_int8& v)
{ v = type::detail::convert_integer<int8_t>(o); return o; }
inline object const& operator>> (object const& o, type::fix_int16& v)
{ v = type::detail::convert_integer<int16_t>(o); return o; }
inline object const& operator>> (object const& o, type::fix_int32& v)
{ v = type::detail::convert_integer<int32_t>(o); return o; }
inline object const& operator>> (object const& o, type::fix_int64& v)
{ v = type::detail::convert_integer<int64_t>(o); return o; }
inline object const& operator>> (object const& o, type::fix_uint8& v)
{ v = type::detail::convert_integer<uint8_t>(o); return o; }
inline object const& operator>> (object const& o, type::fix_uint16& v)
{ v = type::detail::convert_integer<uint16_t>(o); return o; }
inline object const& operator>> (object const& o, type::fix_uint32& v)
{ v = type::detail::convert_integer<uint32_t>(o); return o; }
inline object const& operator>> (object const& o, type::fix_uint64& v)
{ 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)
{ o.pack_fix_int8(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int16& v)
{ o.pack_fix_int16(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int32& v)
{ o.pack_fix_int32(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_int64& v)
{ o.pack_fix_int64(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint8& v)
{ o.pack_fix_uint8(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint16& v)
{ o.pack_fix_uint16(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint32& v)
{ o.pack_fix_uint32(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::fix_uint64& v)
{ 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();
}
else {
o.type = 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();
}
else {
o.type = 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();
}
}
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();
}
}
inline void operator<< (object& o, type::fix_uint8 v)
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
inline void operator<< (object& o, type::fix_uint16 v)
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
inline void operator<< (object& o, type::fix_uint32 v)
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v.get(); }
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; }
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/type/fixint.hpp */

View File

@ -0,0 +1,100 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_FIXINT_FWD_HPP
#define MSGPACK_TYPE_FIXINT_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
template <typename T>
struct fix_int;
typedef fix_int<uint8_t> fix_uint8;
typedef fix_int<uint16_t> fix_uint16;
typedef fix_int<uint32_t> fix_uint32;
typedef fix_int<uint64_t> fix_uint64;
typedef fix_int<int8_t> fix_int8;
typedef fix_int<int16_t> fix_int16;
typedef fix_int<int32_t> fix_int32;
typedef fix_int<int64_t> fix_int64;
} // namespace type
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

View File

@ -0,0 +1,105 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_FLOAT_HPP
#define MSGPACK_TYPE_FLOAT_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
// FIXME check overflow, underflow
inline object const& operator>> (object const& o, float& v)
{
if(o.type == type::DOUBLE) {
v = static_cast<float>(o.via.dec);
}
else if (o.type == type::POSITIVE_INTEGER) {
v = static_cast<float>(o.via.u64);
}
else if (o.type == type::NEGATIVE_INTEGER) {
v = static_cast<float>(o.via.i64);
}
else {
throw type_error();
}
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;
}
else if (o.type == type::POSITIVE_INTEGER) {
v = static_cast<double>(o.via.u64);
}
else if (o.type == type::NEGATIVE_INTEGER) {
v = static_cast<double>(o.via.i64);
}
else {
throw type_error();
}
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; }
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_FLOAT_HPP

View File

@ -0,0 +1,44 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_FLOAT_FWD_HPP
#define MSGPACK_TYPE_FLOAT_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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

View File

@ -0,0 +1,332 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_INT_HPP
#define MSGPACK_TYPE_INT_HPP
#include "msgpack/versioning.hpp"
#include "msgpack_fwd.hpp"
#include <limits>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1){
namespace type {
namespace detail {
template <typename T, bool Signed>
struct convert_integer_sign;
template <typename T>
struct convert_integer_sign<T, true> {
static inline T convert(object const& o) {
if(o.type == type::POSITIVE_INTEGER) {
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
{ throw type_error(); }
return static_cast<T>(o.via.u64);
} else if(o.type == type::NEGATIVE_INTEGER) {
if(o.via.i64 < static_cast<int64_t>(std::numeric_limits<T>::min()))
{ throw type_error(); }
return static_cast<T>(o.via.i64);
}
throw type_error();
}
};
template <typename T>
struct convert_integer_sign<T, false> {
static inline T convert(object const& o) {
if(o.type == type::POSITIVE_INTEGER) {
if(o.via.u64 > static_cast<uint64_t>(std::numeric_limits<T>::max()))
{ throw type_error(); }
return static_cast<T>(o.via.u64);
}
throw type_error();
}
};
template <typename T>
struct is_signed {
static const bool value = std::numeric_limits<T>::is_signed;
};
template <typename T>
static inline T convert_integer(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) {
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_char_sign<false> {
static inline void make(object& o, char v) {
o.type = type::POSITIVE_INTEGER, o.via.u64 = v;
}
};
static inline void object_char(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)
{ v = type::detail::convert_integer<char>(o); return o; }
inline object const& operator>> (object const& o, signed char& v)
{ v = type::detail::convert_integer<signed char>(o); return o; }
inline object const& operator>> (object const& o, signed short& v)
{ v = type::detail::convert_integer<signed short>(o); return o; }
inline object const& operator>> (object const& o, signed int& v)
{ v = type::detail::convert_integer<signed int>(o); return o; }
inline object const& operator>> (object const& o, signed long& v)
{ v = type::detail::convert_integer<signed long>(o); return o; }
inline object const& operator>> (object const& o, signed long long& v)
{ v = type::detail::convert_integer<signed long long>(o); return o; }
inline object const& operator>> (object const& o, unsigned char& v)
{ v = type::detail::convert_integer<unsigned char>(o); return o; }
inline object const& operator>> (object const& o, unsigned short& v)
{ v = type::detail::convert_integer<unsigned short>(o); return o; }
inline object const& operator>> (object const& o, unsigned int& v)
{ v = type::detail::convert_integer<unsigned int>(o); return o; }
inline object const& operator>> (object const& o, unsigned long& v)
{ v = type::detail::convert_integer<unsigned long>(o); return o; }
inline object const& operator>> (object const& o, unsigned long long& v)
{ 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 <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)
{ o.pack_short(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, signed int v)
{ o.pack_int(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, signed long v)
{ o.pack_long(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, signed long long v)
{ 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 <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned short v)
{ o.pack_unsigned_short(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned int v)
{ o.pack_unsigned_int(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long v)
{ o.pack_unsigned_long(v); return o; }
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, unsigned long long v)
{ o.pack_unsigned_long_long(v); return o; }
inline void operator<< (object& o, char v)
{ 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;
}
else {
o.type = 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;
}
else {
o.type = 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;
}
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;
}
}
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;
}
}
inline void operator<< (object& o, unsigned char v)
{ o.type = type::POSITIVE_INTEGER, o.via.u64 = v; }
inline void operator<< (object& o, unsigned short v)
{ o.type = 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; }
inline void operator<< (object::with_zone& o, char v)
{ static_cast<object&>(o) << v; }
inline void operator<< (object::with_zone& o, signed char v)
{ static_cast<object&>(o) << v; }
inline void operator<< (object::with_zone& o, signed short v)
{ static_cast<object&>(o) << v; }
inline void operator<< (object::with_zone& o, signed int v)
{ static_cast<object&>(o) << v; }
inline void operator<< (object::with_zone& o, signed long v)
{ static_cast<object&>(o) << v; }
inline void operator<< (object::with_zone& o, const signed long long& v)
{ static_cast<object&>(o) << v; }
inline void operator<< (object::with_zone& o, unsigned char v)
{ static_cast<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; }
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/type/int.hpp */

View File

@ -0,0 +1,100 @@
//
// MessagePack for C++ forward declaration
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_INT_FWD_HPP
#define MSGPACK_TYPE_INT_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1){
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

View File

@ -0,0 +1,79 @@
//
// 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_HPP
#define MSGPACK_TYPE_LIST_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <list>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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);
}
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());
it != it_end; ++it) {
o.pack(*it);
}
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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_LIST_HPP

View File

@ -0,0 +1,40 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_LIST_FWD_HPP
#define MSGPACK_TYPE_LIST_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <list>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename T>
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

View File

@ -0,0 +1,211 @@
//
// 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_MAP_HPP
#define MSGPACK_TYPE_MAP_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 : public std::vector< std::pair<K, V> > {};
namespace detail {
template <typename K, typename V>
struct pair_first_less {
bool operator() (const std::pair<K, V>& x, const std::pair<K, V>& y) const
{ return x.first < y.first; }
};
}
} //namespace type
template <typename K, typename V>
inline 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)) {
p->val.convert(it->second);
} else {
V val;
p->val.convert(val);
tmp.insert(it, std::pair<K,V>(key, val));
}
}
tmp.swap(v);
return o;
}
template <typename Stream, typename K, typename V>
inline 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());
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 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);
}
}
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);
}
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());
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 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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_MAP_HPP

View File

@ -0,0 +1,69 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_MAP_FWD_HPP
#define MSGPACK_TYPE_MAP_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <map>
#include <vector>
#include <algorithm>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
template <typename K, typename V>
class assoc_vector;
namespace detail {
template <typename K, typename V>
struct pair_first_less;
} // namespace detail
} // namespace type
template <typename K, typename V>
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

View File

@ -0,0 +1,29 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_MSGPACK_TUPLE_HPP
#define MSGPACK_MSGPACK_TUPLE_HPP
#include "msgpack/cpp_config.hpp"
#if defined(MSGPACK_USE_CPP03)
#include "detail/cpp03_msgpack_tuple.hpp"
#else // MSGPACK_USE_CPP03
#include "detail/cpp11_msgpack_tuple.hpp"
#endif // MSGPACK_USE_CPP03
#endif // MSGPACK_MSGPACK_TUPLE_HPP

View File

@ -0,0 +1,29 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_MSGPACK_TUPLE_FWD_HPP
#define MSGPACK_MSGPACK_TUPLE_FWD_HPP
#include "msgpack/cpp_config.hpp"
#if defined(MSGPACK_USE_CPP03)
#include "detail/cpp03_msgpack_tuple_fwd.hpp"
#else // MSGPACK_USE_CPP03
#include "detail/cpp11_msgpack_tuple_fwd.hpp"
#endif // MSGPACK_USE_CPP03
#endif // MSGPACK_MSGPACK_TUPLE_FWD_HPP

View File

@ -15,13 +15,16 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_NIL_HPP__
#define MSGPACK_TYPE_NIL_HPP__
#ifndef MSGPACK_TYPE_NIL_HPP
#define MSGPACK_TYPE_NIL_HPP
#include "msgpack/object.hpp"
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
struct nil { };
@ -29,20 +32,20 @@ struct nil { };
} // namespace type
inline type::nil& operator>> (object o, type::nil& v)
inline object const& operator>> (object const& o, type::nil&)
{
if(o.type != type::NIL) { throw type_error(); }
return v;
return o;
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const type::nil& v)
inline packer<Stream>& operator<< (packer<Stream>& o, const type::nil&)
{
o.pack_nil();
return o;
}
inline void operator<< (object& o, type::nil v)
inline void operator<< (object& o, type::nil)
{
o.type = type::NIL;
}
@ -55,11 +58,11 @@ template <>
inline void object::as<void>() const
{
msgpack::type::nil v;
convert(&v);
convert(v);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/type/nil.hpp */
#endif // MSGPACK_TYPE_NIL_HPP

View File

@ -0,0 +1,51 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_NIL_FWD_HPP
#define MSGPACK_TYPE_NIL_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
struct nil;
} // namespace type
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

View File

@ -15,23 +15,25 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_PAIR_HPP__
#define MSGPACK_TYPE_PAIR_HPP__
#ifndef MSGPACK_TYPE_PAIR_HPP
#define MSGPACK_TYPE_PAIR_HPP
#include "msgpack/object.hpp"
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <utility>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename T1, typename T2>
inline std::pair<T1, T2>& operator>> (object o, std::pair<T1, T2>& v)
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 v;
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>
@ -47,15 +49,15 @@ template <typename T1, typename T2>
inline void operator<< (object::with_zone& o, const std::pair<T1, T2>& v)
{
o.type = type::ARRAY;
object* p = (object*)o.zone->malloc(sizeof(object)*2);
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);
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/type/pair.hpp */
#endif // MSGPACK_TYPE_PAIR_HPP

View File

@ -0,0 +1,42 @@
//
// 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

View File

@ -0,0 +1,98 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_RAW_HPP
#define MSGPACK_TYPE_RAW_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <string.h>
#include <string>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
struct raw_ref {
raw_ref() : size(0), ptr(nullptr) {}
raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {}
uint32_t size;
const char* ptr;
std::string str() const { return std::string(ptr, size); }
bool operator== (const raw_ref& x) const
{
return size == x.size && memcmp(ptr, x.ptr, size) == 0;
}
bool operator!= (const raw_ref& x) const
{
return !(*this != x);
}
bool operator< (const raw_ref& x) const
{
if(size == x.size) { return 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; }
else { return size > x.size; }
}
};
} // namespace type
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 <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;
}
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;
}
inline void operator<< (object::with_zone& o, const type::raw_ref& v)
{ static_cast<object&>(o) << v; }
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_RAW_HPP

View File

@ -0,0 +1,50 @@
//
// 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

View File

@ -0,0 +1,129 @@
//
// 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_SET_HPP
#define MSGPACK_TYPE_SET_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <set>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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>());
}
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());
it != it_end; ++it) {
o.pack(*it);
}
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);
}
}
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>());
}
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());
it != it_end; ++it) {
o.pack(*it);
}
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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_SET_HPP

View File

@ -0,0 +1,52 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_SET_FWD_HPP
#define MSGPACK_TYPE_SET_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <set>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename T>
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

View File

@ -15,48 +15,59 @@
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_STRING_HPP__
#define MSGPACK_TYPE_STRING_HPP__
#ifndef MSGPACK_TYPE_STRING_HPP
#define MSGPACK_TYPE_STRING_HPP
#include "msgpack/object.hpp"
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <string>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
inline std::string& operator>> (object o, std::string& v)
inline object const& operator>> (object const& o, std::string& v)
{
if(o.type != type::RAW) { throw type_error(); }
v.assign(o.via.raw.ptr, o.via.raw.size);
return 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;
}
return o;
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::string& v)
{
o.pack_raw(v.size());
o.pack_raw_body(v.data(), v.size());
o.pack_str(v.size());
o.pack_str_body(v.data(), v.size());
return o;
}
inline void operator<< (object::with_zone& o, const std::string& v)
{
o.type = type::RAW;
char* ptr = (char*)o.zone->malloc(v.size());
o.via.raw.ptr = ptr;
o.via.raw.size = (uint32_t)v.size();
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());
}
inline void operator<< (object& o, const std::string& v)
{
o.type = type::RAW;
o.via.raw.ptr = v.data();
o.via.raw.size = (uint32_t)v.size();
o.type = type::STR;
o.via.str.ptr = v.data();
o.via.str.size = static_cast<uint32_t>(v.size());
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/type/string.hpp */
#endif // MSGPACK_TYPE_STRING_HPP

View File

@ -0,0 +1,42 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_STRING_FWD_HPP
#define MSGPACK_TYPE_STRING_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <string>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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

View File

@ -0,0 +1,156 @@
//
// 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_MAP_HPP
#define MSGPACK_TYPE_TR1_UNORDERED_MAP_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>
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]);
}
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());
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 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);
}
}
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);
}
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());
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 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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#undef MSGPACK_STD_TR1
#endif // MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP

View File

@ -0,0 +1,72 @@
//
// 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

View File

@ -0,0 +1,148 @@
//
// 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_HPP
#define MSGPACK_TYPE_TR1_UNORDERED_SET_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>
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>());
}
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());
it != it_end; ++it) {
o.pack(*it);
}
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);
}
}
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>());
}
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());
it != it_end; ++it) {
o.pack(*it);
}
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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#undef MSGPACK_STD_TR1
#endif // MSGPACK_TYPE_TR1_UNORDERED_SET_HPP

View File

@ -0,0 +1,71 @@
//
// 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

View File

@ -0,0 +1,83 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2008-2009 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_VECTOR_HPP
#define MSGPACK_TYPE_VECTOR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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);
}
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());
it != it_end; ++it) {
o.pack(*it);
}
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);
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_VECTOR_HPP

View File

@ -0,0 +1,76 @@
//
// 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_HPP
#define MSGPACK_TYPE_VECTOR_CHAR_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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;
}
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());
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());
}
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());
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_TYPE_VECTOR_CHAR_HPP

View File

@ -0,0 +1,42 @@
//
// MessagePack for C++ static resolution routine
//
// Copyright (C) 2014 KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP
#define MSGPACK_TYPE_VECTOR_CHAR_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/object_fwd.hpp"
#include <vector>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
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

View File

@ -0,0 +1,42 @@
//
// 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

View File

@ -0,0 +1,107 @@
//
// MessagePack for C++ C++03/C++11 Adaptation
//
// Copyright (C) 2013 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_CPP_CONFIG_HPP
#define MSGPACK_CPP_CONFIG_HPP
#include "msgpack/versioning.hpp"
#if !defined(MSGPACK_USE_CPP03)
// If MSVC would support C++11 completely,
// then 'defined(_MSC_VER)' would replace with
// '_MSC_VER < XXXX'
# if (__cplusplus < 201103) || defined(_MSC_VER)
# define MSGPACK_USE_CPP03
# endif
#endif // MSGPACK_USE_CPP03
#if defined __cplusplus
#if __cplusplus < 201103
#if !defined(nullptr)
#define nullptr (0)
#endif
#include <memory>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
template <typename T>
struct unique_ptr : std::auto_ptr<T> {
explicit unique_ptr(T* p = 0) throw() : std::auto_ptr<T>(p) {}
unique_ptr(unique_ptr& a) throw() : std::auto_ptr<T>(a) {}
template<class Y>
unique_ptr (unique_ptr<Y>& a) throw() : std::auto_ptr<T>(a) {}
};
template <typename T>
T& move(T& t)
{
return t;
}
template <typename T>
T const& move(T const& t)
{
return t;
}
template <bool P, typename T = void>
struct enable_if {
typedef T type;
};
template <typename T>
struct enable_if<false, T> {
};
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#else // __cplusplus < 201103
#include <memory>
#include <tuple>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
// unique_ptr
using std::unique_ptr;
// using std::make_unique; // since C++14
using std::hash;
// utility
using std::move;
using std::swap;
using std::enable_if;
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // __cplusplus < 201103
#endif // __cplusplus
#endif /* msgpack/cpp_config.hpp */

View File

@ -0,0 +1,640 @@
//
// MessagePack for C++ memory pool
//
// Copyright (C) 2008-2010 FURUHASHI Sadayuki
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP03_ZONE_HPP
#define MSGPACK_CPP03_ZONE_HPP
#include <cstdlib>
#include <memory>
#include <vector>
#include "msgpack/versioning.hpp"
#ifndef MSGPACK_ZONE_CHUNK_SIZE
#define MSGPACK_ZONE_CHUNK_SIZE 8192
#endif
#ifndef MSGPACK_ZONE_ALIGN
#define MSGPACK_ZONE_ALIGN sizeof(int)
#endif
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
class zone {
struct finalizer {
finalizer(void (*func)(void*), void* data):m_func(func), m_data(data) {}
void operator()() { m_func(m_data); }
void (*m_func)(void*);
void* m_data;
};
struct finalizer_array {
finalizer_array():m_tail(nullptr), m_end(nullptr), m_array(nullptr) {}
void call() {
finalizer* fin = m_tail;
for(; fin != m_array; --fin) (*(fin-1))();
}
~finalizer_array() {
call();
::free(m_array);
}
void clear() {
call();
m_tail = m_array;
}
void push(void (*func)(void* data), void* data)
{
finalizer* fin = m_tail;
if(fin == m_end) {
push_expand(func, data);
return;
}
fin->m_func = func;
fin->m_data = data;
++m_tail;
}
void push_expand(void (*func)(void*), void* data) {
const size_t nused = m_end - m_array;
size_t nnext;
if(nused == 0) {
nnext = (sizeof(finalizer) < 72/2) ?
72 / sizeof(finalizer) : 8;
} else {
nnext = nused * 2;
}
finalizer* tmp =
static_cast<finalizer*>(::realloc(m_array, sizeof(finalizer) * nnext));
if(!tmp) {
throw std::bad_alloc();
}
m_array = tmp;
m_end = tmp + nnext;
m_tail = tmp + nused;
new (m_tail) finalizer(func, data);
++m_tail;
}
finalizer* m_tail;
finalizer* m_end;
finalizer* m_array;
};
struct chunk {
chunk* m_next;
};
struct chunk_list {
chunk_list(size_t chunk_size)
{
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
if(!c) {
throw std::bad_alloc();
}
m_head = c;
m_free = chunk_size;
m_ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->m_next = nullptr;
}
~chunk_list()
{
chunk* c = m_head;
while(c) {
chunk* n = c->m_next;
::free(c);
c = n;
}
}
void clear(size_t chunk_size)
{
chunk* c = m_head;
while(true) {
chunk* n = c->m_next;
if(n) {
::free(c);
c = n;
} else {
break;
}
}
m_head->m_next = nullptr;
m_free = chunk_size;
m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
}
size_t m_free;
char* m_ptr;
chunk* m_head;
};
size_t m_chunk_size;
chunk_list m_chunk_list;
finalizer_array m_finalizer_array;
public:
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) /* throw() */;
public:
void* allocate_align(size_t size);
void* allocate_no_align(size_t size);
void push_finalizer(void (*func)(void*), void* data);
template <typename T>
void push_finalizer(msgpack::unique_ptr<T> obj);
void clear();
void swap(zone& o);
static void* operator new(std::size_t size) throw(std::bad_alloc)
{
void* p = ::malloc(size);
if (!p) throw std::bad_alloc();
return p;
}
static void operator delete(void *p) throw()
{
::free(p);
}
static void* operator new(std::size_t size, void* place) throw()
{
return ::operator new(size, place);
}
static void operator delete(void* p, void* place) throw()
{
::operator delete(p, place);
}
template <typename T>
T* allocate();
template <typename T, typename A1>
T* allocate(A1 a1);
template <typename T, typename A1, typename A2>
T* allocate(A1 a1, A2 a2);
template <typename T, typename A1, typename A2, typename A3>
T* allocate(A1 a1, A2 a2, A3 a3);
template <typename T, typename A1, typename A2, typename A3, typename A4>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4);
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5);
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6);
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7);
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8);
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9);
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10);
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>
T* allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11);
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>
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);
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>
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);
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>
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);
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);
private:
void undo_allocate(size_t size);
template <typename T>
static void object_destruct(void* obj);
template <typename T>
static void object_delete(void* obj);
void* allocate_expand(size_t size);
};
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)
{
return allocate_no_align(
((size)+((MSGPACK_ZONE_ALIGN)-1)) & ~((MSGPACK_ZONE_ALIGN)-1));
}
inline void* zone::allocate_no_align(size_t size)
{
if(m_chunk_list.m_free < size) {
return allocate_expand(size);
}
char* ptr = m_chunk_list.m_ptr;
m_chunk_list.m_free -= size;
m_chunk_list.m_ptr += size;
return ptr;
}
inline void* zone::allocate_expand(size_t size)
{
chunk_list* const cl = &m_chunk_list;
size_t sz = m_chunk_size;
while(sz < size) {
sz *= 2;
}
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
if (!c) throw std::bad_alloc();
char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->m_next = cl->m_head;
cl->m_head = c;
cl->m_free = sz - size;
cl->m_ptr = ptr + size;
return ptr;
}
inline void zone::push_finalizer(void (*func)(void*), void* data)
{
m_finalizer_array.push(func, data);
}
template <typename T>
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
{
m_finalizer_array.push(&zone::object_delete<T>, obj.release());
}
inline void zone::clear()
{
m_finalizer_array.clear();
m_chunk_list.clear(m_chunk_size);
}
inline void zone::swap(zone& o)
{
std::swap(*this, o);
}
template <typename T>
void zone::object_destruct(void* obj)
{
static_cast<T*>(obj)->~T();
}
template <typename T>
void zone::object_delete(void* obj)
{
delete static_cast<T*>(obj);
}
inline void zone::undo_allocate(size_t size)
{
m_chunk_list.m_ptr -= size;
m_chunk_list.m_free += size;
}
template <typename T>
T* zone::allocate()
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T();
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1>
T* zone::allocate(A1 a1)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2>
T* zone::allocate(A1 a1, A2 a2)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3>
T* zone::allocate(A1 a1, A2 a2, A3 a3)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3, typename A4>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3, typename A4, typename A5, typename A6, typename A7, typename A8, typename A9, typename A10>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
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>
T* zone::allocate(A1 a1, A2 a2, A3 a3, A4 a4, A5 a5, A6 a6, A7 a7, A8 a8, A9 a9, A10 a10, A11 a11)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
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>
T* zone::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)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
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>
T* zone::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)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
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>
T* zone::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)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
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* zone::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)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP03_ZONE_HPP

View File

@ -0,0 +1,352 @@
//
// MessagePack for C++ memory pool
//
// Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
#ifndef MSGPACK_CPP11_ZONE_HPP
#define MSGPACK_CPP11_ZONE_HPP
#include "msgpack/versioning.hpp"
#include <cstdlib>
#include <memory>
#include <vector>
#include "msgpack/cpp_config.hpp"
#ifndef MSGPACK_ZONE_CHUNK_SIZE
#define MSGPACK_ZONE_CHUNK_SIZE 8192
#endif
#ifndef MSGPACK_ZONE_ALIGN
#define MSGPACK_ZONE_ALIGN sizeof(int)
#endif
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
class zone {
private:
struct finalizer {
finalizer(void (*func)(void*), void* data):m_func(func), m_data(data) {}
void operator()() { m_func(m_data); }
void (*m_func)(void*);
void* m_data;
};
struct finalizer_array {
finalizer_array():m_tail(nullptr), m_end(nullptr), m_array(nullptr) {}
void call() {
finalizer* fin = m_tail;
for(; fin != m_array; --fin) (*(fin-1))();
}
~finalizer_array() {
call();
::free(m_array);
}
void clear() {
call();
m_tail = m_array;
}
void push(void (*func)(void* data), void* data)
{
finalizer* fin = m_tail;
if(fin == m_end) {
push_expand(func, data);
return;
}
fin->m_func = func;
fin->m_data = data;
++m_tail;
}
void push_expand(void (*func)(void*), void* data) {
const size_t nused = m_end - m_array;
size_t nnext;
if(nused == 0) {
nnext = (sizeof(finalizer) < 72/2) ?
72 / sizeof(finalizer) : 8;
} else {
nnext = nused * 2;
}
finalizer* tmp =
static_cast<finalizer*>(::realloc(m_array, sizeof(finalizer) * nnext));
if(!tmp) {
throw std::bad_alloc();
}
m_array = tmp;
m_end = tmp + nnext;
m_tail = tmp + nused;
new (m_tail) finalizer(func, data);
++m_tail;
}
#if !defined(MSGPACK_USE_CPP03)
finalizer_array(finalizer_array&& other)
: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)
{
this->~finalizer_array();
new (this) finalizer_array(std::move(other));
return *this;
}
#endif
finalizer* m_tail;
finalizer* m_end;
finalizer* m_array;
private:
finalizer_array(const finalizer_array&);
finalizer_array& operator=(const finalizer_array&);
};
struct chunk {
chunk* m_next;
};
struct chunk_list {
chunk_list(size_t chunk_size)
{
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + chunk_size));
if(!c) {
throw std::bad_alloc();
}
m_head = c;
m_free = chunk_size;
m_ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->m_next = nullptr;
}
~chunk_list()
{
chunk* c = m_head;
while(c) {
chunk* n = c->m_next;
::free(c);
c = n;
}
}
void clear(size_t chunk_size)
{
chunk* c = m_head;
while(true) {
chunk* n = c->m_next;
if(n) {
::free(c);
c = n;
} else {
m_head = c;
break;
}
}
m_head->m_next = nullptr;
m_free = chunk_size;
m_ptr = reinterpret_cast<char*>(m_head) + sizeof(chunk);
}
#if !defined(MSGPACK_USE_CPP03)
chunk_list(chunk_list&& other)
: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)
{
this->~chunk_list();
new (this) chunk_list(std::move(other));
return *this;
}
#endif
size_t m_free;
char* m_ptr;
chunk* m_head;
private:
chunk_list(const chunk_list&);
chunk_list& operator=(const chunk_list&);
};
size_t m_chunk_size;
chunk_list m_chunk_list;
finalizer_array m_finalizer_array;
public:
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE) noexcept;
public:
void* allocate_align(size_t size);
void* allocate_no_align(size_t size);
void push_finalizer(void (*func)(void*), void* data);
template <typename T>
void push_finalizer(msgpack::unique_ptr<T> obj);
void clear();
void swap(zone& o);
static void* operator new(std::size_t size) throw(std::bad_alloc)
{
void* p = ::malloc(size);
if (!p) throw std::bad_alloc();
return p;
}
static void operator delete(void *p) throw()
{
::free(p);
}
static void* operator new(std::size_t /*size*/, void* mem) throw()
{
return mem;
}
static void operator delete(void * /*p*/, void* /*mem*/) throw()
{
}
template <typename T, typename... Args>
T* allocate(Args... args);
zone(zone&&) = default;
zone& operator=(zone&&) = default;
private:
void undo_allocate(size_t size);
zone(const zone&);
zone& operator=(const zone&);
template <typename T>
static void object_destruct(void* obj);
template <typename T>
static void object_delete(void* obj);
void* allocate_expand(size_t size);
};
inline zone::zone(size_t chunk_size) noexcept:m_chunk_size(chunk_size), m_chunk_list(m_chunk_size)
{
}
inline void* zone::allocate_align(size_t size)
{
return allocate_no_align(
((size)+((MSGPACK_ZONE_ALIGN)-1)) & ~((MSGPACK_ZONE_ALIGN)-1));
}
inline void* zone::allocate_no_align(size_t size)
{
if(m_chunk_list.m_free < size) {
return allocate_expand(size);
}
char* ptr = m_chunk_list.m_ptr;
m_chunk_list.m_free -= size;
m_chunk_list.m_ptr += size;
return ptr;
}
inline void* zone::allocate_expand(size_t size)
{
chunk_list* const cl = &m_chunk_list;
size_t sz = m_chunk_size;
while(sz < size) {
sz *= 2;
}
chunk* c = static_cast<chunk*>(::malloc(sizeof(chunk) + sz));
if (!c) throw std::bad_alloc();
char* ptr = reinterpret_cast<char*>(c) + sizeof(chunk);
c->m_next = cl->m_head;
cl->m_head = c;
cl->m_free = sz - size;
cl->m_ptr = ptr + size;
return ptr;
}
inline void zone::push_finalizer(void (*func)(void*), void* data)
{
m_finalizer_array.push(func, data);
}
template <typename T>
inline void zone::push_finalizer(msgpack::unique_ptr<T> obj)
{
m_finalizer_array.push(&zone::object_delete<T>, obj.release());
}
inline void zone::clear()
{
m_finalizer_array.clear();
m_chunk_list.clear(m_chunk_size);
}
inline void zone::swap(zone& o)
{
std::swap(*this, o);
}
template <typename T>
void zone::object_delete(void* obj)
{
delete static_cast<T*>(obj);
}
template <typename T>
void zone::object_destruct(void* obj)
{
static_cast<T*>(obj)->~T();
}
inline void zone::undo_allocate(size_t size)
{
m_chunk_list.m_ptr -= size;
m_chunk_list.m_free += size;
}
template <typename T, typename... Args>
T* zone::allocate(Args... args)
{
void* x = allocate_align(sizeof(T));
try {
m_finalizer_array.push(&zone::object_destruct<T>, x);
} catch (...) {
undo_allocate(sizeof(T));
throw;
}
try {
return new (x) T(args...);
} catch (...) {
--m_finalizer_array.m_tail;
undo_allocate(sizeof(T));
throw;
}
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_CPP11_ZONE_HPP

View File

@ -18,11 +18,14 @@
#ifndef MSGPACK_FBUFFER_HPP__
#define MSGPACK_FBUFFER_HPP__
#include "msgpack/versioning.hpp"
#include <cstdio>
#include <stdexcept>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
class fbuffer {
public:
@ -49,8 +52,8 @@ private:
FILE* m_file;
};
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/fbuffer.hpp */

View File

@ -12,8 +12,8 @@
* limitations under the License.
*/
#ifndef MSGPACK_GCC_ATOMIC_H__
#define MSGPACK_GCC_ATOMIC_H__
#ifndef MSGPACK_GCC_ATOMIC_H
#define MSGPACK_GCC_ATOMIC_H
#if defined(__cplusplus)
extern "C" {
@ -30,4 +30,4 @@ int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr);
#endif
#endif // MSGPACK_GCC_ATOMIC_H__
#endif // MSGPACK_GCC_ATOMIC_H

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_OBJECT_H__
#define MSGPACK_OBJECT_H__
#ifndef MSGPACK_OBJECT_H
#define MSGPACK_OBJECT_H
#include "zone.h"
#include <stdio.h>
@ -38,9 +38,11 @@ typedef enum {
MSGPACK_OBJECT_POSITIVE_INTEGER = 0x02,
MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x03,
MSGPACK_OBJECT_DOUBLE = 0x04,
MSGPACK_OBJECT_RAW = 0x05,
MSGPACK_OBJECT_STR = 0x05,
MSGPACK_OBJECT_ARRAY = 0x06,
MSGPACK_OBJECT_MAP = 0x07,
MSGPACK_OBJECT_BIN = 0x08,
MSGPACK_OBJECT_EXT = 0x09
} msgpack_object_type;
@ -60,7 +62,18 @@ typedef struct {
typedef struct {
uint32_t size;
const char* ptr;
} msgpack_object_raw;
} msgpack_object_str;
typedef struct {
uint32_t size;
const char* ptr;
} msgpack_object_bin;
typedef struct {
int8_t type;
uint32_t size;
const char* ptr;
} msgpack_object_ext;
typedef union {
bool boolean;
@ -69,7 +82,9 @@ typedef union {
double dec;
msgpack_object_array array;
msgpack_object_map map;
msgpack_object_raw raw;
msgpack_object_str str;
msgpack_object_bin bin;
msgpack_object_ext ext;
} msgpack_object_union;
typedef struct msgpack_object {

560
include/msgpack/object.hpp Normal file
View File

@ -0,0 +1,560 @@
//
// 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_OBJECT_HPP
#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"
#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 <stdexcept>
#include <typeinfo>
#include <limits>
#include <ostream>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
struct object::with_zone : object {
with_zone(msgpack::zone& zone) : zone(zone) { }
msgpack::zone& zone;
private:
with_zone();
};
struct object::implicit_type {
implicit_type(object const& o) : obj(o) { }
~implicit_type() { }
template <typename T>
operator T() { return obj.as<T>(); }
private:
object const& obj;
};
inline object const& operator>> (object const& o, object& v)
{
v = o;
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;
}
// obsolete
template <typename Type>
class define : public Type {
public:
typedef Type msgpack_type;
typedef define<Type> define_type;
define() {}
define(const msgpack_type& v) : msgpack_type(v) {}
template <typename Packer>
void msgpack_pack(Packer& o) const
{
msgpack::operator<<(o, static_cast<const msgpack_type&>(*this));
}
void msgpack_unpack(object const& o)
{
msgpack::operator>>(o, static_cast<msgpack_type&>(*this));
}
};
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)
{
msgpack::operator<<(*this, v);
return *this;
}
inline bool operator==(const object& x, const object& y)
{
if(x.type != y.type) { return false; }
switch(x.type) {
case type::NIL:
return true;
case type::BOOLEAN:
return x.via.boolean == y.via.boolean;
case type::POSITIVE_INTEGER:
return x.via.u64 == y.via.u64;
case type::NEGATIVE_INTEGER:
return x.via.i64 == y.via.i64;
case type::DOUBLE:
return x.via.dec == y.via.dec;
case 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;
case 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;
case 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;
case 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;
do {
if(!(*px == *py)) {
return false;
}
++px;
++py;
} while(px < pxend);
return true;
}
case 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;
do {
if(!(px->key == py->key) || !(px->val == py->val)) {
return false;
}
++px;
++py;
} while(px < pxend);
return true;
}
default:
return false;
}
}
template <typename T>
inline bool operator==(const object& x, const T& y)
try {
return x == object(y);
} catch (msgpack::type_error&) {
return false;
}
inline bool operator!=(const object& x, const object& y)
{ return !(x == y); }
template <typename T>
inline bool operator==(const T& y, const object x)
{ return x == y; }
template <typename T>
inline bool operator!=(const object& x, const T& y)
{ return !(x == y); }
template <typename T>
inline bool operator!=(const T& y, const object& x)
{ return x != y; }
inline object::implicit_type object::convert() const
{
return implicit_type(*this);
}
template <typename T>
inline void object::convert(T& v) const
{
msgpack::operator>>(*this, v);
}
template <typename T>
inline void object::convert(T* v) const
{
convert(*v);
}
template <typename T>
inline T object::as() const
{
T v;
convert(v);
return v;
}
inline object::object()
{
type = type::NIL;
}
template <typename T>
inline object::object(const T& v)
{
msgpack::operator<<(*this, v);
}
template <typename T>
inline object& object::operator=(const T& v)
{
*this = object(v);
return *this;
}
template <typename T>
object::object(const T& v, zone& z)
{
with_zone oz(z);
msgpack::operator<<(oz, v);
type = oz.type;
via = oz.via;
}
template <typename T>
object::object(const T& v, zone* z)
{
with_zone oz(*z);
msgpack::operator<<(oz, v);
type = oz.type;
via = oz.via;
}
inline object::object(msgpack_object o)
{
// FIXME beter way?
::memcpy(this, &o, sizeof(o));
}
inline void operator<< (object& o, msgpack_object v)
{
// FIXME beter way?
::memcpy(&o, &v, sizeof(v));
}
inline object::operator msgpack_object() const
{
// FIXME beter way?
msgpack_object obj;
::memcpy(&obj, this, sizeof(obj));
return obj;
}
// obsolete
template <typename T>
inline void convert(T& v, object const& o)
{
o.convert(v);
}
// obsolete
template <typename Stream, typename T>
inline void pack(packer<Stream>& o, const T& v)
{
o.pack(v);
}
// obsolete
template <typename Stream, typename T>
inline void pack_copy(packer<Stream>& o, T v)
{
pack(o, v);
}
template <typename Stream>
inline packer<Stream>& operator<< (packer<Stream>& o, const object& v)
{
switch(v.type) {
case type::NIL:
o.pack_nil();
return o;
case type::BOOLEAN:
if(v.via.boolean) {
o.pack_true();
} else {
o.pack_false();
}
return o;
case type::POSITIVE_INTEGER:
o.pack_uint64(v.via.u64);
return o;
case type::NEGATIVE_INTEGER:
o.pack_int64(v.via.i64);
return o;
case type::DOUBLE:
o.pack_double(v.via.dec);
return o;
case 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:
o.pack_bin(v.via.bin.size);
o.pack_bin_body(v.via.bin.ptr, v.via.bin.size);
return o;
case 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:
o.pack_array(v.via.array.size);
for(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:
o.pack_map(v.via.map.size);
for(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 type_error();
}
}
inline std::ostream& operator<< (std::ostream& s, const object& o)
{
switch(o.type) {
case type::NIL:
s << "nil";
break;
case type::BOOLEAN:
s << (o.via.boolean ? "true" : "false");
break;
case type::POSITIVE_INTEGER:
s << o.via.u64;
break;
case type::NEGATIVE_INTEGER:
s << o.via.i64;
break;
case type::DOUBLE:
s << o.via.dec;
break;
case type::STR:
(s << '"').write(o.via.str.ptr, o.via.str.size) << '"';
break;
case type::BIN:
(s << '"').write(o.via.bin.ptr, o.via.bin.size) << '"';
break;
case type::EXT:
s << "EXT";
case type::ARRAY:
s << "[";
if(o.via.array.size != 0) {
object* p(o.via.array.ptr);
s << *p;
++p;
for(object* const pend(o.via.array.ptr + o.via.array.size);
p < pend; ++p) {
s << ", " << *p;
}
}
s << "]";
break;
case type::MAP:
s << "{";
if(o.via.map.size != 0) {
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);
p < pend; ++p) {
s << ", " << p->key << "=>" << p->val;
}
}
s << "}";
break;
default:
// FIXME
s << "#<UNKNOWN " << static_cast<uint16_t>(o.type) << ">";
}
return s;
}
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#include "msgpack/type.hpp"
#endif /* msgpack/object.hpp */

View File

@ -0,0 +1,170 @@
//
// 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_OBJECT_FWD_HPP
#define MSGPACK_OBJECT_FWD_HPP
#include "msgpack/versioning.hpp"
#include "msgpack/zone.hpp"
#include "msgpack/object.h"
#include <typeinfo>
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
namespace type {
enum object_type {
NIL = MSGPACK_OBJECT_NIL,
BOOLEAN = MSGPACK_OBJECT_BOOLEAN,
POSITIVE_INTEGER = MSGPACK_OBJECT_POSITIVE_INTEGER,
NEGATIVE_INTEGER = MSGPACK_OBJECT_NEGATIVE_INTEGER,
DOUBLE = MSGPACK_OBJECT_DOUBLE,
STR = MSGPACK_OBJECT_STR,
BIN = MSGPACK_OBJECT_BIN,
ARRAY = MSGPACK_OBJECT_ARRAY,
MAP = MSGPACK_OBJECT_MAP,
EXT = MSGPACK_OBJECT_EXT
};
}
struct object;
struct object_kv;
struct object_array {
uint32_t size;
object* ptr;
};
struct object_map {
uint32_t size;
object_kv* ptr;
};
struct object_str {
uint32_t size;
const char* ptr;
};
struct object_bin {
uint32_t size;
const char* ptr;
};
struct object_ext {
int8_t type() const { return ptr[0]; }
const char* data() const { return &ptr[1]; }
uint32_t size;
const char* ptr;
};
struct object {
union union_type {
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;
};
type::object_type type;
union_type via;
bool is_nil() const { return type == type::NIL; }
template <typename T>
T as() const;
template <typename T>
void convert(T& v) const;
template <typename T>
void convert(T* v) const;
object();
object(msgpack_object o);
template <typename T>
explicit object(const T& v);
template <typename T>
object(const T& v, zone& z);
// obsolete
template <typename T>
object(const T& v, zone* z);
template <typename T>
object& operator=(const T& v);
operator msgpack_object() const;
struct with_zone;
private:
struct implicit_type;
public:
implicit_type convert() const;
};
class type_error : public std::bad_cast { };
struct object_kv {
object key;
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);
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif // MSGPACK_OBJECT_FWD_HPP

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_PACK_H__
#define MSGPACK_PACK_H__
#ifndef MSGPACK_PACK_H
#define MSGPACK_PACK_H
#include "pack_define.h"
#include "object.h"
@ -94,8 +94,14 @@ static int msgpack_pack_array(msgpack_packer* pk, size_t n);
static int msgpack_pack_map(msgpack_packer* pk, size_t n);
static int msgpack_pack_raw(msgpack_packer* pk, size_t l);
static int msgpack_pack_raw_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_str(msgpack_packer* pk, size_t l);
static int msgpack_pack_str_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_bin(msgpack_packer* pk, size_t l);
static int msgpack_pack_bin_body(msgpack_packer* pk, const void* b, size_t l);
static int msgpack_pack_ext(msgpack_packer* pk, size_t l, int8_t type);
static int msgpack_pack_ext_body(msgpack_packer* pk, const void* b, size_t l);
int msgpack_pack_object(msgpack_packer* pk, msgpack_object d);

1028
include/msgpack/pack.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_PACK_DEFINE_H__
#define MSGPACK_PACK_DEFINE_H__
#ifndef MSGPACK_PACK_DEFINE_H
#define MSGPACK_PACK_DEFINE_H
#include "msgpack/sysdep.h"
#include <limits.h>

View File

@ -0,0 +1,889 @@
/*
* MessagePack packing routine template
*
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#if defined(__LITTLE_ENDIAN__)
#define TAKE8_8(d) ((uint8_t*)&d)[0]
#define TAKE8_16(d) ((uint8_t*)&d)[0]
#define TAKE8_32(d) ((uint8_t*)&d)[0]
#define TAKE8_64(d) ((uint8_t*)&d)[0]
#elif defined(__BIG_ENDIAN__)
#define TAKE8_8(d) ((uint8_t*)&d)[0]
#define TAKE8_16(d) ((uint8_t*)&d)[1]
#define TAKE8_32(d) ((uint8_t*)&d)[3]
#define TAKE8_64(d) ((uint8_t*)&d)[7]
#endif
#ifndef msgpack_pack_inline_func
#error msgpack_pack_inline_func template is not defined
#endif
#ifndef msgpack_pack_user
#error msgpack_pack_user type is not defined
#endif
#ifndef msgpack_pack_append_buffer
#error msgpack_pack_append_buffer callback is not defined
#endif
/*
* Integer
*/
#define msgpack_pack_real_uint8(x, d) \
do { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
} else { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_8(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} while(0)
#define msgpack_pack_real_uint16(x, d) \
do { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
} else if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} while(0)
#define msgpack_pack_real_uint32(x, d) \
do { \
if(d < (1<<8)) { \
if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
} else { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else { \
if(d < (1<<16)) { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} \
} while(0)
#define msgpack_pack_real_uint64(x, d) \
do { \
if(d < (1ULL<<8)) { \
if(d < (1ULL<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
} else { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else { \
if(d < (1ULL<<16)) { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else if(d < (1ULL<<32)) { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else { \
/* unsigned 64 */ \
unsigned char buf[9]; \
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} \
} \
} while(0)
#define msgpack_pack_real_int8(x, d) \
do { \
if(d < -(1<<5)) { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_8(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1); \
} \
} while(0)
#define msgpack_pack_real_int16(x, d) \
do { \
if(d < -(1<<5)) { \
if(d < -(1<<7)) { \
/* signed 16 */ \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_16(d), 1); \
} else { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_16(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} \
} while(0)
#define msgpack_pack_real_int32(x, d) \
do { \
if(d < -(1<<5)) { \
if(d < -(1<<15)) { \
/* signed 32 */ \
unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else if(d < -(1<<7)) { \
/* signed 16 */ \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_32(d), 1); \
} else { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_32(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else if(d < (1<<16)) { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} \
} while(0)
#define msgpack_pack_real_int64(x, d) \
do { \
if(d < -(1LL<<5)) { \
if(d < -(1LL<<15)) { \
if(d < -(1LL<<31)) { \
/* signed 64 */ \
unsigned char buf[9]; \
buf[0] = 0xd3; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} else { \
/* signed 32 */ \
unsigned char buf[5]; \
buf[0] = 0xd2; _msgpack_store32(&buf[1], (int32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} \
} else { \
if(d < -(1<<7)) { \
/* signed 16 */ \
unsigned char buf[3]; \
buf[0] = 0xd1; _msgpack_store16(&buf[1], (int16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} else { \
/* signed 8 */ \
unsigned char buf[2] = {0xd0, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} \
} \
} else if(d < (1<<7)) { \
/* fixnum */ \
msgpack_pack_append_buffer(x, &TAKE8_64(d), 1); \
} else { \
if(d < (1LL<<16)) { \
if(d < (1<<8)) { \
/* unsigned 8 */ \
unsigned char buf[2] = {0xcc, TAKE8_64(d)}; \
msgpack_pack_append_buffer(x, buf, 2); \
} else { \
/* unsigned 16 */ \
unsigned char buf[3]; \
buf[0] = 0xcd; _msgpack_store16(&buf[1], (uint16_t)d); \
msgpack_pack_append_buffer(x, buf, 3); \
} \
} else { \
if(d < (1LL<<32)) { \
/* unsigned 32 */ \
unsigned char buf[5]; \
buf[0] = 0xce; _msgpack_store32(&buf[1], (uint32_t)d); \
msgpack_pack_append_buffer(x, buf, 5); \
} else { \
/* unsigned 64 */ \
unsigned char buf[9]; \
buf[0] = 0xcf; _msgpack_store64(&buf[1], d); \
msgpack_pack_append_buffer(x, buf, 9); \
} \
} \
} \
} while(0)
#ifdef msgpack_pack_inline_func_fixint
msgpack_pack_inline_func_fixint(_uint8)(msgpack_pack_user x, uint8_t d)
{
unsigned char buf[2] = {0xcc, TAKE8_8(d)};
msgpack_pack_append_buffer(x, buf, 2);
}
msgpack_pack_inline_func_fixint(_uint16)(msgpack_pack_user x, uint16_t d)
{
unsigned char buf[3];
buf[0] = 0xcd; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3);
}
msgpack_pack_inline_func_fixint(_uint32)(msgpack_pack_user x, uint32_t d)
{
unsigned char buf[5];
buf[0] = 0xce; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func_fixint(_uint64)(msgpack_pack_user x, uint64_t d)
{
unsigned char buf[9];
buf[0] = 0xcf; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9);
}
msgpack_pack_inline_func_fixint(_int8)(msgpack_pack_user x, int8_t d)
{
unsigned char buf[2] = {0xd0, TAKE8_8(d)};
msgpack_pack_append_buffer(x, buf, 2);
}
msgpack_pack_inline_func_fixint(_int16)(msgpack_pack_user x, int16_t d)
{
unsigned char buf[3];
buf[0] = 0xd1; _msgpack_store16(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 3);
}
msgpack_pack_inline_func_fixint(_int32)(msgpack_pack_user x, int32_t d)
{
unsigned char buf[5];
buf[0] = 0xd2; _msgpack_store32(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func_fixint(_int64)(msgpack_pack_user x, int64_t d)
{
unsigned char buf[9];
buf[0] = 0xd3; _msgpack_store64(&buf[1], d);
msgpack_pack_append_buffer(x, buf, 9);
}
#undef msgpack_pack_inline_func_fixint
#endif
msgpack_pack_inline_func(_uint8)(msgpack_pack_user x, uint8_t d)
{
msgpack_pack_real_uint8(x, d);
}
msgpack_pack_inline_func(_uint16)(msgpack_pack_user x, uint16_t d)
{
msgpack_pack_real_uint16(x, d);
}
msgpack_pack_inline_func(_uint32)(msgpack_pack_user x, uint32_t d)
{
msgpack_pack_real_uint32(x, d);
}
msgpack_pack_inline_func(_uint64)(msgpack_pack_user x, uint64_t d)
{
msgpack_pack_real_uint64(x, d);
}
msgpack_pack_inline_func(_int8)(msgpack_pack_user x, int8_t d)
{
msgpack_pack_real_int8(x, d);
}
msgpack_pack_inline_func(_int16)(msgpack_pack_user x, int16_t d)
{
msgpack_pack_real_int16(x, d);
}
msgpack_pack_inline_func(_int32)(msgpack_pack_user x, int32_t d)
{
msgpack_pack_real_int32(x, d);
}
msgpack_pack_inline_func(_int64)(msgpack_pack_user x, int64_t d)
{
msgpack_pack_real_int64(x, d);
}
msgpack_pack_inline_func(_char)(msgpack_pack_user x, char d)
{
#if defined(CHAR_MIN)
#if CHAR_MIN < 0
msgpack_pack_real_int8(x, d);
#else
msgpack_pack_real_uint8(x, d);
#endif
#else
#error CHAR_MIN is not defined
#endif
}
msgpack_pack_inline_func(_signed_char)(msgpack_pack_user x, signed char d)
{
msgpack_pack_real_int8(x, d);
}
msgpack_pack_inline_func(_unsigned_char)(msgpack_pack_user x, unsigned char d)
{
msgpack_pack_real_uint8(x, d);
}
#ifdef msgpack_pack_inline_func_cint
msgpack_pack_inline_func_cint(_short)(msgpack_pack_user x, short d)
{
#if defined(SIZEOF_SHORT)
#if SIZEOF_SHORT == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_SHORT == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(SHRT_MAX)
#if SHRT_MAX == 0x7fff
msgpack_pack_real_int16(x, d);
#elif SHRT_MAX == 0x7fffffff
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(short) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(short) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_int)(msgpack_pack_user x, int d)
{
#if defined(SIZEOF_INT)
#if SIZEOF_INT == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_INT == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(INT_MAX)
#if INT_MAX == 0x7fff
msgpack_pack_real_int16(x, d);
#elif INT_MAX == 0x7fffffff
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(int) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(int) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_long)(msgpack_pack_user x, long d)
{
#if defined(SIZEOF_LONG)
#if SIZEOF_LONG == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_LONG == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(LONG_MAX)
#if LONG_MAX == 0x7fffL
msgpack_pack_real_int16(x, d);
#elif LONG_MAX == 0x7fffffffL
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(long) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(long) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_long_long)(msgpack_pack_user x, long long d)
{
#if defined(SIZEOF_LONG_LONG)
#if SIZEOF_LONG_LONG == 2
msgpack_pack_real_int16(x, d);
#elif SIZEOF_LONG_LONG == 4
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#elif defined(LLONG_MAX)
#if LLONG_MAX == 0x7fffL
msgpack_pack_real_int16(x, d);
#elif LLONG_MAX == 0x7fffffffL
msgpack_pack_real_int32(x, d);
#else
msgpack_pack_real_int64(x, d);
#endif
#else
if(sizeof(long long) == 2) {
msgpack_pack_real_int16(x, d);
} else if(sizeof(long long) == 4) {
msgpack_pack_real_int32(x, d);
} else {
msgpack_pack_real_int64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_short)(msgpack_pack_user x, unsigned short d)
{
#if defined(SIZEOF_SHORT)
#if SIZEOF_SHORT == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_SHORT == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(USHRT_MAX)
#if USHRT_MAX == 0xffffU
msgpack_pack_real_uint16(x, d);
#elif USHRT_MAX == 0xffffffffU
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned short) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned short) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_int)(msgpack_pack_user x, unsigned int d)
{
#if defined(SIZEOF_INT)
#if SIZEOF_INT == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_INT == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(UINT_MAX)
#if UINT_MAX == 0xffffU
msgpack_pack_real_uint16(x, d);
#elif UINT_MAX == 0xffffffffU
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned int) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned int) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_long)(msgpack_pack_user x, unsigned long d)
{
#if defined(SIZEOF_LONG)
#if SIZEOF_LONG == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_LONG == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(ULONG_MAX)
#if ULONG_MAX == 0xffffUL
msgpack_pack_real_uint16(x, d);
#elif ULONG_MAX == 0xffffffffUL
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned long) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned long) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
msgpack_pack_inline_func_cint(_unsigned_long_long)(msgpack_pack_user x, unsigned long long d)
{
#if defined(SIZEOF_LONG_LONG)
#if SIZEOF_LONG_LONG == 2
msgpack_pack_real_uint16(x, d);
#elif SIZEOF_LONG_LONG == 4
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#elif defined(ULLONG_MAX)
#if ULLONG_MAX == 0xffffUL
msgpack_pack_real_uint16(x, d);
#elif ULLONG_MAX == 0xffffffffUL
msgpack_pack_real_uint32(x, d);
#else
msgpack_pack_real_uint64(x, d);
#endif
#else
if(sizeof(unsigned long long) == 2) {
msgpack_pack_real_uint16(x, d);
} else if(sizeof(unsigned long long) == 4) {
msgpack_pack_real_uint32(x, d);
} else {
msgpack_pack_real_uint64(x, d);
}
#endif
}
#undef msgpack_pack_inline_func_cint
#endif
/*
* Float
*/
msgpack_pack_inline_func(_float)(msgpack_pack_user x, float d)
{
unsigned char buf[5];
union { float f; uint32_t i; } mem;
mem.f = d;
buf[0] = 0xca; _msgpack_store32(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 5);
}
msgpack_pack_inline_func(_double)(msgpack_pack_user x, double d)
{
unsigned char buf[9];
union { double f; uint64_t i; } mem;
mem.f = d;
buf[0] = 0xcb;
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
// https://github.com/msgpack/msgpack-perl/pull/1
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
#endif
_msgpack_store64(&buf[1], mem.i);
msgpack_pack_append_buffer(x, buf, 9);
}
/*
* Nil
*/
msgpack_pack_inline_func(_nil)(msgpack_pack_user x)
{
static const unsigned char d = 0xc0;
msgpack_pack_append_buffer(x, &d, 1);
}
/*
* Boolean
*/
msgpack_pack_inline_func(_true)(msgpack_pack_user x)
{
static const unsigned char d = 0xc3;
msgpack_pack_append_buffer(x, &d, 1);
}
msgpack_pack_inline_func(_false)(msgpack_pack_user x)
{
static const unsigned char d = 0xc2;
msgpack_pack_append_buffer(x, &d, 1);
}
/*
* Array
*/
msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x90 | (uint8_t)n;
msgpack_pack_append_buffer(x, &d, 1);
} else if(n < 65536) {
unsigned char buf[3];
buf[0] = 0xdc; _msgpack_store16(&buf[1], (uint16_t)n);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xdd; _msgpack_store32(&buf[1], (uint32_t)n);
msgpack_pack_append_buffer(x, buf, 5);
}
}
/*
* Map
*/
msgpack_pack_inline_func(_map)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x80 | (uint8_t)n;
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(n < 65536) {
unsigned char buf[3];
buf[0] = 0xde; _msgpack_store16(&buf[1], (uint16_t)n);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xdf; _msgpack_store32(&buf[1], (uint32_t)n);
msgpack_pack_append_buffer(x, buf, 5);
}
}
/*
* Str
*/
msgpack_pack_inline_func(_str)(msgpack_pack_user x, size_t l)
{
if(l < 32) {
unsigned char d = 0xa0 | (uint8_t)l;
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(l < 256) {
unsigned char buf[2];
buf[0] = 0xd9; buf[1] = (uint8_t)l;
msgpack_pack_append_buffer(x, buf, 2);
} else if(l < 65536) {
unsigned char buf[3];
buf[0] = 0xda; _msgpack_store16(&buf[1], (uint16_t)l);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xdb; _msgpack_store32(&buf[1], (uint32_t)l);
msgpack_pack_append_buffer(x, buf, 5);
}
}
msgpack_pack_inline_func(_str_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
/*
* Bin
*/
msgpack_pack_inline_func(_bin)(msgpack_pack_user x, size_t l)
{
if(l < 256) {
unsigned char buf[2];
buf[0] = 0xc4; buf[1] = (uint8_t)l;
msgpack_pack_append_buffer(x, buf, 2);
} else if(l < 65536) {
unsigned char buf[3];
buf[0] = 0xc5; _msgpack_store16(&buf[1], (uint16_t)l);
msgpack_pack_append_buffer(x, buf, 3);
} else {
unsigned char buf[5];
buf[0] = 0xc6; _msgpack_store32(&buf[1], (uint32_t)l);
msgpack_pack_append_buffer(x, buf, 5);
}
}
msgpack_pack_inline_func(_bin_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
/*
* Ext
*/
msgpack_pack_inline_func(_ext)(msgpack_pack_user x, size_t l, int8_t type)
{
switch(l) {
case 1: {
char buf[2];
buf[0] = 0xd4;
buf[1] = type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 2: {
char buf[2];
buf[0] = 0xd5;
buf[1] = type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 4: {
char buf[2];
buf[0] = 0xd6;
buf[1] = type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 8: {
char buf[2];
buf[0] = 0xd7;
buf[1] = type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
case 16: {
char buf[2];
buf[0] = 0xd8;
buf[1] = type;
msgpack_pack_append_buffer(x, buf, 2);
} break;
default:
if(l < 256) {
char buf[3];
buf[0] = 0xc7;
buf[1] = l;
buf[2] = type;
msgpack_pack_append_buffer(x, buf, 3);
} else if(l < 65536) {
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];
buf[0] = 0xc9;
_msgpack_store32(&buf[1], l);
buf[5] = type;
msgpack_pack_append_buffer(x, buf, 6);
}
break;
}
}
msgpack_pack_inline_func(_ext_body)(msgpack_pack_user x, const void* b, size_t l)
{
msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
}
#undef msgpack_pack_inline_func
#undef msgpack_pack_user
#undef msgpack_pack_append_buffer
#undef TAKE8_8
#undef TAKE8_16
#undef TAKE8_32
#undef TAKE8_64
#undef msgpack_pack_real_uint8
#undef msgpack_pack_real_uint16
#undef msgpack_pack_real_uint32
#undef msgpack_pack_real_uint64
#undef msgpack_pack_real_int8
#undef msgpack_pack_real_int16
#undef msgpack_pack_real_int32
#undef msgpack_pack_real_int64

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_SBUFFER_H__
#define MSGPACK_SBUFFER_H__
#ifndef MSGPACK_SBUFFER_H
#define MSGPACK_SBUFFER_H
#include <stdlib.h>
#include <string.h>

120
include/msgpack/sbuffer.hpp Normal file
View File

@ -0,0 +1,120 @@
//
// MessagePack for C++ simple buffer implementation
//
// 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_SBUFFER_HPP
#define MSGPACK_SBUFFER_HPP
#include "msgpack/versioning.hpp"
#include <stdexcept>
#ifndef MSGPACK_SBUFFER_INIT_SIZE
#define MSGPACK_SBUFFER_INIT_SIZE 8192
#endif
namespace msgpack {
MSGPACK_API_VERSION_NAMESPACE(v1) {
class sbuffer {
public:
sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE):m_size(0), m_alloc(initsz)
{
if(initsz == 0) {
m_data = nullptr;
} else {
m_data = (char*)::malloc(initsz);
if(!m_data) {
throw std::bad_alloc();
}
}
}
~sbuffer()
{
::free(m_data);
}
public:
void write(const char* buf, size_t len)
{
if(m_alloc - m_size < len) {
expand_buffer(len);
}
::memcpy(m_data + m_size, buf, len);
m_size += len;
}
char* data()
{
return m_data;
}
const char* data() const
{
return m_data;
}
size_t size() const
{
return m_size;
}
char* release()
{
char* tmp = m_data;
m_size = 0;
m_data = nullptr;
m_alloc = 0;
return tmp;
}
void clear()
{
m_size = 0;
}
private:
void expand_buffer(size_t len)
{
size_t nsize = (m_alloc > 0) ?
m_alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
while(nsize < m_size + len) { nsize *= 2; }
void* tmp = ::realloc(m_data, nsize);
if(!tmp) {
throw std::bad_alloc();
}
m_data = static_cast<char*>(tmp);
m_alloc = nsize;
}
private:
sbuffer(const sbuffer&);
private:
size_t m_size;
char* m_data;
size_t m_alloc;
};
} // MSGPACK_API_VERSION_NAMESPACE(v1)
} // namespace msgpack
#endif /* msgpack/sbuffer.hpp */

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_SYSDEP_H__
#define MSGPACK_SYSDEP_H__
#ifndef MSGPACK_SYSDEP_H
#define MSGPACK_SYSDEP_H
#include <stdlib.h>
#include <stddef.h>
@ -42,7 +42,13 @@ typedef long _msgpack_atomic_counter_t;
#define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr)
#define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr)
#elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41)
#if defined(__cplusplus)
#define _msgpack_atomic_counter_header "gcc_atomic.hpp"
#else
#define _msgpack_atomic_counter_header "gcc_atomic.h"
#endif
#else
typedef unsigned int _msgpack_atomic_counter_t;
#define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1)
@ -62,7 +68,12 @@ typedef unsigned int _msgpack_atomic_counter_t;
#endif
#else
#include <arpa/inet.h> /* __BYTE_ORDER */
# if !defined(__APPLE__)
# include <byteswap.h>
# endif
#endif
#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
@ -126,53 +137,27 @@ typedef unsigned int _msgpack_atomic_counter_t;
((((uint64_t)x) >> 56) ) )
#endif
#define _msgpack_load16(cast, from) ((cast)( \
(((uint16_t)((uint8_t*)(from))[0]) << 8) | \
(((uint16_t)((uint8_t*)(from))[1]) ) ))
#define _msgpack_load32(cast, from) ((cast)( \
(((uint32_t)((uint8_t*)(from))[0]) << 24) | \
(((uint32_t)((uint8_t*)(from))[1]) << 16) | \
(((uint32_t)((uint8_t*)(from))[2]) << 8) | \
(((uint32_t)((uint8_t*)(from))[3]) ) ))
#define _msgpack_load64(cast, from) ((cast)( \
(((uint64_t)((uint8_t*)(from))[0]) << 56) | \
(((uint64_t)((uint8_t*)(from))[1]) << 48) | \
(((uint64_t)((uint8_t*)(from))[2]) << 40) | \
(((uint64_t)((uint8_t*)(from))[3]) << 32) | \
(((uint64_t)((uint8_t*)(from))[4]) << 24) | \
(((uint64_t)((uint8_t*)(from))[5]) << 16) | \
(((uint64_t)((uint8_t*)(from))[6]) << 8) | \
(((uint64_t)((uint8_t*)(from))[7]) ) ))
#else
#else /* __LITTLE_ENDIAN__ */
#define _msgpack_be16(x) (x)
#define _msgpack_be32(x) (x)
#define _msgpack_be64(x) (x)
#define _msgpack_load16(cast, from) ((cast)( \
(((uint16_t)((uint8_t*)from)[0]) << 8) | \
(((uint16_t)((uint8_t*)from)[1]) ) ))
#define _msgpack_load32(cast, from) ((cast)( \
(((uint32_t)((uint8_t*)from)[0]) << 24) | \
(((uint32_t)((uint8_t*)from)[1]) << 16) | \
(((uint32_t)((uint8_t*)from)[2]) << 8) | \
(((uint32_t)((uint8_t*)from)[3]) ) ))
#define _msgpack_load64(cast, from) ((cast)( \
(((uint64_t)((uint8_t*)from)[0]) << 56) | \
(((uint64_t)((uint8_t*)from)[1]) << 48) | \
(((uint64_t)((uint8_t*)from)[2]) << 40) | \
(((uint64_t)((uint8_t*)from)[3]) << 32) | \
(((uint64_t)((uint8_t*)from)[4]) << 24) | \
(((uint64_t)((uint8_t*)from)[5]) << 16) | \
(((uint64_t)((uint8_t*)from)[6]) << 8) | \
(((uint64_t)((uint8_t*)from)[7]) ) ))
#endif
#define _msgpack_load16(cast, from, to) do { \
memcpy((cast*)(to), (from), sizeof(cast)); \
*(to) = _msgpack_be16(*(to)); \
} while (0);
#define _msgpack_load32(cast, from, to) do { \
memcpy((cast*)(to), (from), sizeof(cast)); \
*(to) = _msgpack_be32(*(to)); \
} while (0);
#define _msgpack_load64(cast, from, to) do { \
memcpy((cast*)(to), (from), sizeof(cast)); \
*(to) = _msgpack_be64(*(to)); \
} while (0);
#define _msgpack_store16(to, num) \
do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0)
@ -205,4 +190,3 @@ typedef unsigned int _msgpack_atomic_counter_t;
#endif
#endif /* msgpack/sysdep.h */

29
include/msgpack/type.hpp Normal file
View File

@ -0,0 +1,29 @@
#include "cpp_config.hpp"
#include "adaptor/bool.hpp"
#include "adaptor/char_ptr.hpp"
#include "adaptor/deque.hpp"
#include "adaptor/fixint.hpp"
#include "adaptor/float.hpp"
#include "adaptor/int.hpp"
#include "adaptor/list.hpp"
#include "adaptor/map.hpp"
#include "adaptor/nil.hpp"
#include "adaptor/pair.hpp"
#include "adaptor/raw.hpp"
#include "adaptor/set.hpp"
#include "adaptor/string.hpp"
#include "adaptor/vector.hpp"
#include "adaptor/vector_char.hpp"
#include "adaptor/msgpack_tuple.hpp"
#include "adaptor/define.hpp"
#include "adaptor/tr1/unordered_map.hpp"
#include "adaptor/tr1/unordered_set.hpp"
#if !defined(MSGPACK_USE_CPP03)
#include "adaptor/cpp11/array.hpp"
#include "adaptor/cpp11/array_char.hpp"
#include "adaptor/cpp11/forward_list.hpp"
#include "adaptor/cpp11/tuple.hpp"
#endif // !defined(MSGPACK_USE_CPP03)

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_UNPACKER_H__
#define MSGPACK_UNPACKER_H__
#ifndef MSGPACK_UNPACKER_H
#define MSGPACK_UNPACKER_H
#include "zone.h"
#include "object.h"
@ -38,7 +38,17 @@ typedef struct msgpack_unpacked {
msgpack_object data;
} msgpack_unpacked;
bool msgpack_unpack_next(msgpack_unpacked* result,
typedef enum {
MSGPACK_UNPACK_SUCCESS = 2,
MSGPACK_UNPACK_EXTRA_BYTES = 1,
MSGPACK_UNPACK_CONTINUE = 0,
MSGPACK_UNPACK_PARSE_ERROR = -1,
MSGPACK_UNPACK_NOMEM_ERROR = -2
} msgpack_unpack_return;
msgpack_unpack_return
msgpack_unpack_next(msgpack_unpacked* result,
const char* data, size_t len, size_t* off);
/** @} */
@ -136,7 +146,7 @@ static inline void msgpack_unpacker_buffer_consumed(msgpack_unpacker* mpac, si
* Returns true if it successes. Otherwise false is returned.
* @param pac pointer to an initialized msgpack_unpacked object.
*/
bool msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac);
msgpack_unpack_return msgpack_unpacker_next(msgpack_unpacker* mpac, msgpack_unpacked* pac);
/**
* Initializes a msgpack_unpacked object.
@ -174,20 +184,14 @@ static inline size_t msgpack_unpacker_message_size(const msgpack_unpacker* mpac)
/** @} */
// obsolete
typedef enum {
MSGPACK_UNPACK_SUCCESS = 2,
MSGPACK_UNPACK_EXTRA_BYTES = 1,
MSGPACK_UNPACK_CONTINUE = 0,
MSGPACK_UNPACK_PARSE_ERROR = -1,
} msgpack_unpack_return;
// obsolete
msgpack_unpack_return
msgpack_unpack(const char* data, size_t len, size_t* off,
msgpack_zone* result_zone, msgpack_object* result);
static inline size_t msgpack_unpacker_parsed_size(const msgpack_unpacker* mpac);
bool msgpack_unpacker_flush_zone(msgpack_unpacker* mpac);

1468
include/msgpack/unpack.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,97 @@
/*
* MessagePack unpacking routine template
*
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_UNPACK_DEFINE_H
#define MSGPACK_UNPACK_DEFINE_H
#include "msgpack/sysdep.h"
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#include <stdio.h>
#ifdef __cplusplus
extern "C" {
#endif
#ifndef MSGPACK_EMBED_STACK_SIZE
#define MSGPACK_EMBED_STACK_SIZE 32
#endif
typedef enum {
CS_HEADER = 0x00, // nil
//CS_ = 0x01,
//CS_ = 0x02, // false
//CS_ = 0x03, // true
CS_BIN_8 = 0x04,
CS_BIN_16 = 0x05,
CS_BIN_32 = 0x06,
CS_EXT_8 = 0x07,
CS_EXT_16 = 0x08,
CS_EXT_32 = 0x09,
CS_FLOAT = 0x0a,
CS_DOUBLE = 0x0b,
CS_UINT_8 = 0x0c,
CS_UINT_16 = 0x0d,
CS_UINT_32 = 0x0e,
CS_UINT_64 = 0x0f,
CS_INT_8 = 0x10,
CS_INT_16 = 0x11,
CS_INT_32 = 0x12,
CS_INT_64 = 0x13,
CS_FIXEXT_1 = 0x14,
CS_FIXEXT_2 = 0x15,
CS_FIXEXT_4 = 0x16,
CS_FIXEXT_8 = 0x17,
CS_FIXEXT_16 = 0x18,
CS_STR_8 = 0x19, // str8
CS_STR_16 = 0x1a, // str16
CS_STR_32 = 0x1b, // str32
CS_ARRAY_16 = 0x1c,
CS_ARRAY_32 = 0x1d,
CS_MAP_16 = 0x1e,
CS_MAP_32 = 0x1f,
//ACS_BIG_INT_VALUE,
//ACS_BIG_FLOAT_VALUE,
ACS_STR_VALUE,
ACS_BIN_VALUE,
ACS_EXT_VALUE
} msgpack_unpack_state;
typedef enum {
CT_ARRAY_ITEM,
CT_MAP_KEY,
CT_MAP_VALUE
} msgpack_container_type;
#ifdef __cplusplus
}
#endif
#endif /* msgpack/unpack_define.h */

View File

@ -0,0 +1,476 @@
/*
* MessagePack unpacking routine template
*
* Copyright (C) 2008-2010 FURUHASHI Sadayuki
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef msgpack_unpack_func
#error msgpack_unpack_func template is not defined
#endif
#ifndef msgpack_unpack_callback
#error msgpack_unpack_callback template is not defined
#endif
#ifndef msgpack_unpack_struct
#error msgpack_unpack_struct template is not defined
#endif
#ifndef msgpack_unpack_struct_decl
#define msgpack_unpack_struct_decl(name) msgpack_unpack_struct(name)
#endif
#ifndef msgpack_unpack_object
#error msgpack_unpack_object type is not defined
#endif
#ifndef msgpack_unpack_user
#error msgpack_unpack_user type is not defined
#endif
#ifndef USE_CASE_RANGE
#if !defined(_MSC_VER)
#define USE_CASE_RANGE
#endif
#endif
msgpack_unpack_struct_decl(_stack) {
msgpack_unpack_object obj;
size_t count;
unsigned int ct;
msgpack_unpack_object map_key;
};
msgpack_unpack_struct_decl(_context) {
msgpack_unpack_user user;
unsigned int cs;
unsigned int trail;
unsigned int top;
/*
msgpack_unpack_struct(_stack)* stack;
unsigned int stack_size;
msgpack_unpack_struct(_stack) embed_stack[MSGPACK_EMBED_STACK_SIZE];
*/
msgpack_unpack_struct(_stack) stack[MSGPACK_EMBED_STACK_SIZE];
};
msgpack_unpack_func(void, _init)(msgpack_unpack_struct(_context)* ctx)
{
ctx->cs = CS_HEADER;
ctx->trail = 0;
ctx->top = 0;
/*
ctx->stack = ctx->embed_stack;
ctx->stack_size = MSGPACK_EMBED_STACK_SIZE;
*/
ctx->stack[0].obj = msgpack_unpack_callback(_root)(&ctx->user);
}
/*
msgpack_unpack_func(void, _destroy)(msgpack_unpack_struct(_context)* ctx)
{
if(ctx->stack_size != MSGPACK_EMBED_STACK_SIZE) {
free(ctx->stack);
}
}
*/
msgpack_unpack_func(msgpack_unpack_object, _data)(msgpack_unpack_struct(_context)* ctx)
{
return (ctx)->stack[0].obj;
}
msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const char* data, size_t len, size_t* off)
{
assert(len >= *off);
const unsigned char* p = (unsigned char*)data + *off;
const unsigned char* const pe = (unsigned char*)data + len;
const void* n = NULL;
unsigned int trail = ctx->trail;
unsigned int cs = ctx->cs;
unsigned int top = ctx->top;
msgpack_unpack_struct(_stack)* stack = ctx->stack;
/*
unsigned int stack_size = ctx->stack_size;
*/
msgpack_unpack_user* user = &ctx->user;
msgpack_unpack_object obj;
msgpack_unpack_struct(_stack)* c = NULL;
int ret;
#define push_simple_value(func) \
if(msgpack_unpack_callback(func)(user, &obj) < 0) { goto _failed; } \
goto _push
#define push_fixed_value(func, arg) \
if(msgpack_unpack_callback(func)(user, arg, &obj) < 0) { goto _failed; } \
goto _push
#define push_variable_value(func, base, pos, len) \
if(msgpack_unpack_callback(func)(user, \
(const char*)base, (const char*)pos, len, &obj) < 0) { goto _failed; } \
goto _push
#define again_fixed_trail(_cs, trail_len) \
trail = trail_len; \
cs = _cs; \
goto _fixed_trail_again
#define again_fixed_trail_if_zero(_cs, trail_len, ifzero) \
trail = trail_len; \
if(trail == 0) { goto ifzero; } \
cs = _cs; \
goto _fixed_trail_again
#define start_container(func, count_, ct_) \
if(top >= MSGPACK_EMBED_STACK_SIZE) { goto _failed; } /* FIXME */ \
if(msgpack_unpack_callback(func)(user, count_, &stack[top].obj) < 0) { goto _failed; } \
if((count_) == 0) { obj = stack[top].obj; goto _push; } \
stack[top].ct = ct_; \
stack[top].count = count_; \
++top; \
/*printf("container %d count %d stack %d\n",stack[top].obj,count_,top);*/ \
/*printf("stack push %d\n", top);*/ \
/* FIXME \
if(top >= stack_size) { \
if(stack_size == MSGPACK_EMBED_STACK_SIZE) { \
size_t csize = sizeof(msgpack_unpack_struct(_stack)) * MSGPACK_EMBED_STACK_SIZE; \
size_t nsize = csize * 2; \
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)malloc(nsize); \
if(tmp == NULL) { goto _failed; } \
memcpy(tmp, ctx->stack, csize); \
ctx->stack = stack = tmp; \
ctx->stack_size = stack_size = MSGPACK_EMBED_STACK_SIZE * 2; \
} else { \
size_t nsize = sizeof(msgpack_unpack_struct(_stack)) * ctx->stack_size * 2; \
msgpack_unpack_struct(_stack)* tmp = (msgpack_unpack_struct(_stack)*)realloc(ctx->stack, nsize); \
if(tmp == NULL) { goto _failed; } \
ctx->stack = stack = tmp; \
ctx->stack_size = stack_size = stack_size * 2; \
} \
} \
*/ \
goto _header_again
#define NEXT_CS(p) \
((unsigned int)*p & 0x1f)
#ifdef USE_CASE_RANGE
#define SWITCH_RANGE_BEGIN switch(*p) {
#define SWITCH_RANGE(FROM, TO) case FROM ... TO:
#define SWITCH_RANGE_DEFAULT default:
#define SWITCH_RANGE_END }
#else
#define SWITCH_RANGE_BEGIN { if(0) {
#define SWITCH_RANGE(FROM, TO) } else if(FROM <= *p && *p <= TO) {
#define SWITCH_RANGE_DEFAULT } else {
#define SWITCH_RANGE_END } }
#endif
if(p == pe) { goto _out; }
do {
switch(cs) {
case CS_HEADER:
SWITCH_RANGE_BEGIN
SWITCH_RANGE(0x00, 0x7f) // Positive Fixnum
push_fixed_value(_uint8, *(uint8_t*)p);
SWITCH_RANGE(0xe0, 0xff) // Negative Fixnum
push_fixed_value(_int8, *(int8_t*)p);
SWITCH_RANGE(0xc0, 0xdf) // Variable
switch(*p) {
case 0xc0: // nil
push_simple_value(_nil);
//case 0xc1: // string
// again_terminal_trail(NEXT_CS(p), p+1);
case 0xc2: // false
push_simple_value(_false);
case 0xc3: // true
push_simple_value(_true);
case 0xc4: // bin 8
case 0xc5: // bin 16
case 0xc6: // bin 32
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
case 0xc7: // ext 8
case 0xc8: // ext 16
case 0xc9: // ext 32
again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) + 1) & 0x03));
case 0xca: // float
case 0xcb: // double
case 0xcc: // unsigned int 8
case 0xcd: // unsigned int 16
case 0xce: // unsigned int 32
case 0xcf: // unsigned int 64
case 0xd0: // signed int 8
case 0xd1: // signed int 16
case 0xd2: // signed int 32
case 0xd3: // signed int 64
again_fixed_trail(NEXT_CS(p), 1 << (((unsigned int)*p) & 0x03));
case 0xd4: // fixext 1
case 0xd5: // fixext 2
case 0xd6: // fixext 4
case 0xd7: // fixext 8
again_fixed_trail_if_zero(ACS_EXT_VALUE,
(1 << (((unsigned int)*p) & 0x03)) + 1, _ext_zero);
case 0xd8: // fixext 16
again_fixed_trail_if_zero(ACS_EXT_VALUE, 16+1, _ext_zero);
case 0xd9: // str 8
case 0xda: // str 16
case 0xdb: // str 32
again_fixed_trail(NEXT_CS(p), 1 << ((((unsigned int)*p) & 0x03) - 1));
case 0xdc: // array 16
case 0xdd: // array 32
case 0xde: // map 16
case 0xdf: // map 32
again_fixed_trail(NEXT_CS(p), 2u << (((unsigned int)*p) & 0x01));
default:
goto _failed;
}
SWITCH_RANGE(0xa0, 0xbf) // FixStr
again_fixed_trail_if_zero(ACS_STR_VALUE, ((unsigned int)*p & 0x1f), _str_zero);
SWITCH_RANGE(0x90, 0x9f) // FixArray
start_container(_array, ((unsigned int)*p) & 0x0f, CT_ARRAY_ITEM);
SWITCH_RANGE(0x80, 0x8f) // FixMap
start_container(_map, ((unsigned int)*p) & 0x0f, CT_MAP_KEY);
SWITCH_RANGE_DEFAULT
goto _failed;
SWITCH_RANGE_END
// end CS_HEADER
_fixed_trail_again:
++p;
default:
if((size_t)(pe - p) < trail) { goto _out; }
n = p; p += trail - 1;
switch(cs) {
//case CS_
//case CS_
case CS_FLOAT: {
union { uint32_t i; float f; } mem;
_msgpack_load32(uint32_t, n, &mem.i);
push_fixed_value(_float, mem.f); }
case CS_DOUBLE: {
union { uint64_t i; double f; } mem;
_msgpack_load64(uint64_t, n, &mem.i);
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
// https://github.com/msgpack/msgpack-perl/pull/1
mem.i = (mem.i & 0xFFFFFFFFUL) << 32UL | (mem.i >> 32UL);
#endif
push_fixed_value(_double, mem.f); }
case CS_UINT_8:
push_fixed_value(_uint8, *(uint8_t*)n);
case CS_UINT_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
push_fixed_value(_uint16, tmp);
}
case CS_UINT_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
push_fixed_value(_uint32, tmp);
}
case CS_UINT_64:{
uint64_t tmp;
_msgpack_load64(uint64_t,n,&tmp);
push_fixed_value(_uint64, tmp);
}
case CS_INT_8:
push_fixed_value(_int8, *(int8_t*)n);
case CS_INT_16:{
int16_t tmp;
_msgpack_load16(int16_t,n,&tmp);
push_fixed_value(_int16, tmp);
}
case CS_INT_32:{
int32_t tmp;
_msgpack_load32(int32_t,n,&tmp);
push_fixed_value(_int32, tmp);
}
case CS_INT_64:{
int64_t tmp;
_msgpack_load64(int64_t,n,&tmp);
push_fixed_value(_int64, tmp);
}
case CS_FIXEXT_1:
again_fixed_trail_if_zero(ACS_EXT_VALUE, 1+1, _ext_zero);
case CS_FIXEXT_2:
again_fixed_trail_if_zero(ACS_EXT_VALUE, 2+1, _ext_zero);
case CS_FIXEXT_4:
again_fixed_trail_if_zero(ACS_EXT_VALUE, 4+1, _ext_zero);
case CS_FIXEXT_8:
again_fixed_trail_if_zero(ACS_EXT_VALUE, 8+1, _ext_zero);
case CS_FIXEXT_16:
again_fixed_trail_if_zero(ACS_EXT_VALUE, 16+1, _ext_zero);
case CS_STR_8:
again_fixed_trail_if_zero(ACS_STR_VALUE, *(uint8_t*)n, _str_zero);
case CS_BIN_8:
again_fixed_trail_if_zero(ACS_BIN_VALUE, *(uint8_t*)n, _bin_zero);
case CS_EXT_8:
again_fixed_trail_if_zero(ACS_EXT_VALUE, (*(uint8_t*)n) + 1, _ext_zero);
case CS_STR_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
again_fixed_trail_if_zero(ACS_STR_VALUE, tmp, _str_zero);
}
case CS_BIN_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
again_fixed_trail_if_zero(ACS_BIN_VALUE, tmp, _bin_zero);
}
case CS_EXT_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
again_fixed_trail_if_zero(ACS_EXT_VALUE, tmp + 1, _ext_zero);
}
case CS_STR_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
again_fixed_trail_if_zero(ACS_STR_VALUE, tmp, _str_zero);
}
case CS_BIN_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
again_fixed_trail_if_zero(ACS_BIN_VALUE, tmp, _bin_zero);
}
case CS_EXT_32:{
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
again_fixed_trail_if_zero(ACS_EXT_VALUE, tmp + 1, _ext_zero);
}
case ACS_STR_VALUE:
_str_zero:
push_variable_value(_str, data, n, trail);
case ACS_BIN_VALUE:
_bin_zero:
push_variable_value(_bin, data, n, trail);
case ACS_EXT_VALUE:
_ext_zero:
push_variable_value(_ext, data, n, trail);
case CS_ARRAY_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
start_container(_array, tmp, CT_ARRAY_ITEM);
}
case CS_ARRAY_32:{
/* FIXME security guard */
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
start_container(_array, tmp, CT_ARRAY_ITEM);
}
case CS_MAP_16:{
uint16_t tmp;
_msgpack_load16(uint16_t,n,&tmp);
start_container(_map, tmp, CT_MAP_KEY);
}
case CS_MAP_32:{
/* FIXME security guard */
uint32_t tmp;
_msgpack_load32(uint32_t,n,&tmp);
start_container(_map, tmp, CT_MAP_KEY);
}
default:
goto _failed;
}
}
_push:
if(top == 0) { goto _finish; }
c = &stack[top-1];
switch(c->ct) {
case CT_ARRAY_ITEM:
if(msgpack_unpack_callback(_array_item)(user, &c->obj, obj) < 0) { goto _failed; }
if(--c->count == 0) {
obj = c->obj;
--top;
/*printf("stack pop %d\n", top);*/
goto _push;
}
goto _header_again;
case CT_MAP_KEY:
c->map_key = obj;
c->ct = CT_MAP_VALUE;
goto _header_again;
case CT_MAP_VALUE:
if(msgpack_unpack_callback(_map_item)(user, &c->obj, c->map_key, obj) < 0) { goto _failed; }
if(--c->count == 0) {
obj = c->obj;
--top;
/*printf("stack pop %d\n", top);*/
goto _push;
}
c->ct = CT_MAP_KEY;
goto _header_again;
default:
goto _failed;
}
_header_again:
cs = CS_HEADER;
++p;
} while(p != pe);
goto _out;
_finish:
stack[0].obj = obj;
++p;
ret = 1;
/*printf("-- finish --\n"); */
goto _end;
_failed:
/*printf("** FAILED **\n"); */
ret = -1;
goto _end;
_out:
ret = 0;
goto _end;
_end:
ctx->cs = cs;
ctx->trail = trail;
ctx->top = top;
*off = (size_t)(p - (const unsigned char*)data);
return ret;
}
#undef msgpack_unpack_func
#undef msgpack_unpack_callback
#undef msgpack_unpack_struct
#undef msgpack_unpack_object
#undef msgpack_unpack_user
#undef push_simple_value
#undef push_fixed_value
#undef push_variable_value
#undef again_fixed_trail
#undef again_fixed_trail_if_zero
#undef start_container
#undef NEXT_CS

23
include/msgpack/util.h Normal file
View File

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

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_VERSION_H__
#define MSGPACK_VERSION_H__
#ifndef MSGPACK_VERSION_H
#define MSGPACK_VERSION_H
#ifdef __cplusplus
extern "C" {
@ -27,10 +27,12 @@ const char* msgpack_version(void);
int msgpack_version_major(void);
int msgpack_version_minor(void);
#define MSGPACK_VERSION "@VERSION@"
#define MSGPACK_VERSION_MAJOR @VERSION_MAJOR@
#define MSGPACK_VERSION_MINOR @VERSION_MINOR@
#include "version_master.h"
#define MSGPACK_STR(v) #v
#define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev)
#define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION)
#ifdef __cplusplus
}

View File

@ -0,0 +1,44 @@
/*
* MessagePack for C++ version information
*
* Copyright (C) 2008-2013 FURUHASHI Sadayuki and Takatoshi Kondo
*
* 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_VERSION_HPP
#define MSGPACK_VERSION_HPP
#include "version_master.h"
#define MSGPACK_STR(v) #v
#define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev)
#define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION)
inline const char* msgpack_version(void) {
return MSGPACK_VERSION;
}
inline int msgpack_version_major(void) {
return MSGPACK_VERSION_MAJOR;
}
inline int msgpack_version_minor(void) {
return MSGPACK_VERSION_MINOR;
}
inline int msgpack_version_revision(void) {
return MSGPACK_VERSION_REVISION;
}
#endif /* msgpack/version.hpp */

View File

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

View File

@ -0,0 +1,77 @@
/*
* MessagePack for C++ version switcher
*
* 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_VERSIONING_HPP
#define MSGPACK_VERSIONING_HPP
#if !defined(MSGPACK_DEFAULT_API_VERSION)
#define MSGPACK_DEFAULT_API_VERSION 1
#endif
#define MSGPACK_DEFAULT_API_NS MSGPACK_PP_CAT(v, MSGPACK_DEFAULT_API_VERSION)
#if MSGPACK_DEFAULT_API_VERSION == 1
#define MSGPACK_PP_ENABLE_NS_v1 ()
//#elif MSGPACK_DEFAULT_API_VERSION == 2
//#define MSGPACK_PP_ENABLE_NS_v2 ()
#else
#error
#endif
#define MSGPACK_PP_CAT(a, ...) MSGPACK_PP_PRIMITIVE_CAT(a, __VA_ARGS__)
#define MSGPACK_PP_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__
#define MSGPACK_PP_IIF(c) MSGPACK_PP_PRIMITIVE_CAT(MSGPACK_PP_IIF_, c)
#define MSGPACK_PP_IIF_0(t, ...) __VA_ARGS__
#define MSGPACK_PP_IIF_1(t, ...) t
#define MSGPACK_PP_PROBE(x) x, 1
#if defined(__MSC_VER)
#define MSGPACK_PP_MSVC_VA_ARGS_WORKAROUND(define, args) define args
#define MSGPACK_PP_CHECK(...) MSGPACK_PP_MSVC_VA_ARGS_WORKAROUND(MSGPACK_PP_CHECK_N, (__VA_ARGS__, 0))
#define MSGPACK_PP_CHECK_N(x, n, ...) n
#else // defined(__MSC_VER)
#define MSGPACK_PP_CHECK(...) MSGPACK_PP_CHECK_N(__VA_ARGS__, 0)
#define MSGPACK_PP_CHECK_N(x, n, ...) n
#endif // defined(__MSC_VER)
#define MSGPACK_PP_NS_ENABLED_PROBE(ns) MSGPACK_PP_NS_ENABLED_PROBE_PROXY( MSGPACK_PP_ENABLE_NS_##ns )
#define MSGPACK_PP_NS_ENABLED_PROBE_PROXY(...) MSGPACK_PP_NS_ENABLED_PROBE_PRIMIVIE(__VA_ARGS__)
#define MSGPACK_PP_NS_ENABLED_PROBE_PRIMIVIE(x) MSGPACK_PP_NS_ENABLED_PROBE_COMBINE_ x
#define MSGPACK_PP_NS_ENABLED_PROBE_COMBINE_(...) MSGPACK_PP_PROBE(~)
#define MSGPACK_PP_IS_NS_ENABLED(ns) MSGPACK_PP_CHECK(MSGPACK_PP_NS_ENABLED_PROBE(ns))
#if __cplusplus < 201103
#define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_PP_IIF(MSGPACK_PP_IS_NS_ENABLED(ns)) \
(namespace ns{}; using namespace ns; namespace ns, \
namespace ns)
#else // __cplusplus < 201103
#define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_PP_IIF(MSGPACK_PP_IS_NS_ENABLED(ns)) \
(inline namespace ns, namespace ns)
#endif // __cplusplus < 201103
#endif // MSGPACK_VERSIONING_HPP

View File

@ -15,8 +15,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef MSGPACK_VREFBUFFER_H__
#define MSGPACK_VREFBUFFER_H__
#ifndef MSGPACK_VREFBUFFER_H
#define MSGPACK_VREFBUFFER_H
#include "zone.h"
#include <stdlib.h>

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