Compare commits

..

66 Commits

Author SHA1 Message Date
Nobuyuki Kubota
197ed8c983 Merge pull request #92 from nobu-k/version0.5.9
version 0.5.9
2014-07-03 11:45:20 +09:00
Nobuyuki Kubota
990860fe65 Change CMAKE_MINIMUM_REQUIRED to 2.8.6 for SET_PROPERTY APPEND_STRING 2014-07-03 11:39:43 +09:00
Nobuyuki Kubota
dbeb6e61c6 version 0.5.9 2014-07-02 18:44:07 +09:00
Nobuyuki Kubota
2b3f37f9e0 Add fbuffer.h and fbuffer.hpp to CMakeLists.txt and msgpack_vc.postbuild.bat 2014-07-02 18:07:07 +09:00
Nobuyuki Kubota
f50148a9cc Merge branch 'fbuffer' 2014-07-02 17:53:18 +09:00
Takatoshi Kondo
9fc8ec5b61 Merge branch 'tbeu-fix-bool-and-inline-for-C-compilation-with-MSVC' 2014-07-02 17:44:18 +09:00
Takatoshi Kondo
751a6f98fe Moved bool and inline definition from msgpack.h to sysdep.h.
Set compile settiong on MSVC. ".c" files are compliled as C, not C++. (msgpack_vc8.vcproj, CMakeLists.txt)
Fixed msgpack root object initialization problem on MSVC. {} initialization is not supported on MSVC.
2014-07-02 17:43:07 +09:00
Nobuyuki Kubota
9d8e6b92fc Add fclose to fbuffer's tests 2014-07-02 17:35:15 +09:00
Nobuyuki Kubota
c868da2879 Fix Makefile.am to install fbuffer.h and fbuffer.hpp 2014-07-02 17:32:41 +09:00
tbeu
e0c40c1c59 fix type bool and inline specifier
For a pure C compilation with MSVC type bool is not available. Not tested with other targets (Mingw, cygwin). Thats why only active of ```_MSC_VER``` is defined. So not sure if the bool fix should be also applied to other targets.

For MSVC the inline specifier is not valid and must be named __inline (or _inline).
2014-07-02 17:13:31 +09:00
Nobuyuki Kubota
f185284776 Merge branch 'mpapierski-cmake' 2014-07-02 16:22:33 +09:00
Takatoshi Kondo
1656ef0111 Merge pull request #90 from tbeu/fix-c-compilation
Fix pure C compilation
2014-06-23 21:43:56 +09:00
tbeu
3cb2e4f7c6 Fix pure C compilation 2014-06-23 13:55:25 +02:00
Takatoshi Kondo
3104f7e451 Added -O3 -g option for gcc and clang. Improved compiler checking method. 2014-06-21 19:00:59 +09:00
Takatoshi Kondo
ab8e7ea822 Added -DPIC option on shared library. 2014-06-21 11:27:33 +09:00
Takatoshi Kondo
6daef66ea7 Added warning flags. 2014-06-21 11:11:32 +09:00
Takatoshi Kondo
04286eb9dc Modified the way to install msgpack headers. 2014-06-12 11:18:06 +09:00
Takatoshi Kondo
d15e30bf4a Fixed major_version and minor_version.
Fixed relase_version.
Added msgpack.pc creating proccess.
2014-06-08 15:25:24 +00:00
Takatoshi Kondo
fb1d480faf Added the SOVERSION same as autotools.
Set CMAKE_MINIMUM_REQUIRED to 2.6.4.
2014-06-08 14:05:33 +00:00
Takatoshi Kondo
c8fa0be345 Supported make install.
Removed vc2008 files from make dist.
2014-06-07 14:39:59 +00:00
Takatoshi Kondo
643b0c9523 Supported shared library on cmake.
Updated the documentation.
2014-06-07 00:13:23 +09:00
Takatoshi Kondo
06930616b2 Added cmake files.
https://github.com/msgpack/msgpack-c/pull/20
Removed 'preprocess' from original CMakeLists.txt.
Removed file copy from original CMakeLists.txt.

Removed 'preprocess' from bootstrap.
Removed file copy from bootstrap.

Added erb generated files. Ruby is no longer required.
Moved cases.mpac, cases_compact.mpa, pack_define.h,
pack_template.h, unpack_define.h, unpack_template.h,
and sysdep.h to apropriate location.

If you want to re-generate zone.hpp, define.hpp, and tuple.hpp,
then you execute preprocess.
2014-06-05 20:49:15 +00:00
Nobuyuki Kubota
6e5fc6d396 Merge pull request #83 from redboltz/fixed_readme
Fixed https://github.com/msgpack/msgpack-c/issues/82
2014-06-01 19:16:10 +09:00
Takatoshi Kondo
17b0753023 Fixed linking order. 2014-06-01 19:03:51 +00:00
Nobuyuki Kubota
7491348d40 Merge branch 'philix-Wconversion' 2014-06-01 19:09:02 +09:00
Nobuyuki Kubota
eef2036c36 Remove implicit type conversions from (un)pack_template.h 2014-06-01 19:06:40 +09:00
Nobuyuki Kubota
fbec8f4470 Merge pull request #80 from redboltz/fix_enum_member_test
Fixed dereferencing type-punned pointer will break strict-aliasing rules warning
2014-06-01 18:22:46 +09:00
Felipe Oliveira Carvalho
8e0137e1d2 Fix to allow projects to compile with -Wconversion
Projects that use -Wconversion don't compile due to errors in msgpack header
files. This commit fixes all the errors in msgpack-c for when -Wconversion is
enabled.

Now I can even compile msgpack-c itself with -Wconversion and all my projects:

    CFLAGS=-Wconversion ./configure
		make
2014-05-19 15:30:14 -03:00
Takatoshi Kondo
1dac3f890a Fixed https://github.com/msgpack/msgpack-c/issues/82 2014-04-24 22:39:01 +00:00
Nobuyuki Kubota
9f33266f23 Merge pull request #81 from watsonsong/master
fix compile error on Linux by gcc 4.7
2014-04-07 10:37:54 +09:00
Frank Watson Song
d8c7fd5161 fix compile error on Linux by gcc 4.7 2014-04-01 17:34:28 +08:00
Nobuyuki Kubota
731bc643d0 Merge pull request #79 from redboltz/add_inline
Fixed https://github.com/msgpack/msgpack-c/issues/77
2014-03-31 17:36:06 +09:00
Takatoshi Kondo
12e8615ac5 Fixed dereferencing type-punned pointer will break strict-aliasing rules warning. 2014-03-31 16:37:29 +09:00
Takatoshi Kondo
22703d2cdb Fixed https://github.com/msgpack/msgpack-c/issues/77 2014-03-30 18:42:15 +00:00
Takatoshi Kondo
cb518f472a Merge pull request #73 from ovz/master
Fixed failing test zone_allocate_constructor.
2014-03-30 18:46:15 +09:00
Takatoshi Kondo
271f1fa319 Merge pull request #75 from mogemimi/fix/typo
Fix typo in QUICKSTART-CPP
2014-03-30 18:21:34 +09:00
mogemimi
9ecc4f0a1e Fix typo in QUICKSTART-CPP 2014-03-24 23:07:10 +09:00
ovz
977eab7c4a Fixed failing test zone_allocate_constructor.
Corrected a typo in definition of myclass constructor with parameters.
2014-03-18 14:25:55 -07:00
Vladimir Volodko
c9f342f4b2 Make fbuffer's constructor explicit. 2014-03-03 10:21:03 +07:00
Nobuyuki Kubota
126e4d8414 Merge pull request #70 from redboltz/remove_cxx11_features
Removed C++11 features
2014-03-02 16:58:16 +09:00
Takatoshi Kondo
14ee1e5827 Removed C++11 features 2014-03-02 14:14:04 +00:00
Nobuyuki Kubota
ecbb9055a2 Merge branch 'vvolodko/improve-define' 2014-02-28 16:15:20 +09:00
Nobuyuki Kubota
862f04104d Changed the format a little 2014-02-28 16:14:49 +09:00
Vladimir Volodko
d47f72be0c Refactor define::msgpack_unpack() to use 'switch' instead of several if's.
convert.benchmark test show some improvement.
2014-02-28 16:14:33 +09:00
Nobuyuki Kubota
98c5767372 Merge branch 'redboltz/add_integer_to_float_conv' 2014-02-28 15:53:11 +09:00
Nobuyuki Kubota
97a7b7545a Refactored test cases with type parameterized test 2014-02-28 15:52:36 +09:00
Nobuyuki Kubota
caf5616573 Merge pull request #69 from redboltz/support_libcpp_and_vcxx_unordered
Support libcpp and vcxx unordered
2014-02-28 15:22:27 +09:00
Takatoshi Kondo
b8076fa71f Supported VC++. Fixed testing macro for tr1 containers. 2014-02-27 23:54:48 +00:00
Takatoshi Kondo
2360466aa9 Added unordered containers support for libc++. 2014-02-22 20:43:18 +00:00
Nobuyuki Kubota
28370b36aa Replaced deprecated functions in example/stream.cc 2014-02-07 20:16:51 +09:00
Nobuyuki Kubota
9d82356ea9 Merge pull request #62 from redboltz/remove_redundant_null_check
Removed a redundant null check.
2014-02-07 20:05:49 +09:00
Nobuyuki Kubota
ca24e040c4 Merge pull request #61 from redboltz/fix_delete_free_mismatch
Fixed the free and delete mismatch problem.
2014-02-07 20:04:57 +09:00
Takatoshi Kondo
0fd629857d Removed a redundant null check. 2014-02-03 09:34:48 +00:00
Takatoshi Kondo
8eff14db11 Removed redundant null check. 2014-02-02 16:22:07 +00:00
Takatoshi Kondo
81e26fe9b9 Fixed the free and delete mismatch problem.
https://github.com/msgpack/msgpack-c/issues/52
2014-02-02 00:07:45 +00:00
Takatoshi Kondo
9eb4583dd5 Merge pull request #59 from redboltz/add_null_check
Added null pointer check.
2014-01-27 17:53:19 -08:00
Takatoshi Kondo
5a23c86dc1 Added null pointer check. 2014-01-28 10:54:57 +09:00
Takatoshi Kondo
ffd0525607 Replaced types of length from unsigned int to size_t. 2014-01-26 11:29:19 +00:00
Drew Crawford
3dc636bf3e This patch fixes a type conversion warning in clang 5 when compiling for arm64 targets.
```
$ clang --version
Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)
Target: x86_64-apple-darwin13.0.0
Thread model: posix

In file included from /Users/drew/Dropbox/Code/caffeine-ios/ext/msgpack/src/msgpack/pack.h:120:
/Users/drew/Dropbox/Code/caffeine-ios/ext/msgpack/src/msgpack/pack_template.h:773:57: warning: implicit conversion loses integer precision: 'size_t' (aka 'unsigned long') to 'unsigned int' [-Wshorten-64-to-32]
        msgpack_pack_append_buffer(x, (const unsigned char*)b, l);
        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
In file included from /Users/drew/Dropbox/Code/caffeine-ios/ext/msgpack/src/objectc.c:19:
/Users/drew/Dropbox/Code/caffeine-ios/ext/msgpack/src/msgpack/pack.h:118:61: note: expanded from macro 'msgpack_pack_append_buffer'
        return (*(user)->callback)((user)->data, (const char*)buf, len)
                                                                   ^
1 warning generated.
```

This patch is provided under the Apache License version 2.
2014-01-24 12:41:13 -06:00
Takatoshi Kondo
260ce4aa1d Added object that has integer to float and double converter. 2014-01-21 21:12:13 +00:00
Takatoshi Kondo
8bc827ebf5 Merge pull request #51 from xunzhang/master
update type.hpp
2014-01-13 18:10:49 -08:00
xunzhang
a97f764088 update type.hpp, support std::tr1::unordered_map and std::tr1::unordered_set 2014-01-13 14:12:17 +08:00
Nobuyuki Kubota
143b90af3e Merge branch 'claws/readme_overhaul' 2013-12-22 21:12:04 -08:00
Nobuyuki Kubota
4e0a6ae624 Fixed some URL syntaxes 2013-12-22 21:04:53 -08:00
Chris Laws
17aa517e41 Fix up README, include accurate instructions 2013-12-17 08:53:15 +10:30
Vladimir Volodko
2c1a1fd4f8 Add C/C++ FILE* buffer adaptor.
* add function msgpack_fbuffer_write();
* add class msgpack::fbuffer;
* add tests buffer.fbuffer and buffer.fbuffer_c .
2013-11-22 12:57:30 +07:00
49 changed files with 18510 additions and 245 deletions

10
.gitignore vendored
View File

@@ -9,16 +9,6 @@
/configure
/msgpack_vc2008.sln
/msgpack_vc2008.vcproj
/src/msgpack/pack_define.h
/src/msgpack/pack_template.h
/src/msgpack/sysdep.h
/src/msgpack/type/define.hpp
/src/msgpack/type/tuple.hpp
/src/msgpack/unpack_define.h
/src/msgpack/unpack_template.h
/src/msgpack/zone.hpp
/test/cases.mpac
/test/cases_compact.mpac
Makefile.in
# Files generated by the configure script.

188
CMakeLists.txt Normal file
View File

@@ -0,0 +1,188 @@
CMAKE_MINIMUM_REQUIRED (VERSION 2.8.6)
PROJECT (msgpack)
SET (VERSION 0.5.9)
SET (VERSION_MAJOR 0)
SET (VERSION_MINOR 5)
SET (prefix ${CMAKE_INSTALL_PREFIX})
SET (exec_prefix "\${prefix}")
SET (libdir "\${exec_prefix}/lib")
SET (includedir "\${prefix}/include")
FIND_PACKAGE (GTest)
FIND_PACKAGE (ZLIB)
FIND_PACKAGE (Threads)
IF (GTEST_FOUND AND ZLIB_FOUND AND THREADS_FOUND)
OPTION (MSGPACK_BUILD_TESTS "Build msgpack tests." ON)
ENDIF ()
OPTION (MSGPACK_ENABLE_CXX "Enable C++ interface." ON)
INCLUDE (CheckCXXSourceCompiles)
CHECK_CXX_SOURCE_COMPILES ("
#include <bits/atomicity.h>
int atomic_sub(int i) { return __gnu_cxx::__exchange_and_add(&i, -1) - 1; }
int atomic_add(int i) { return __gnu_cxx::__exchange_and_add(&i, 1) + 1; }
int main(int argc, char * argv[])
{
atomic_sub(1);
atomic_add(1);
}
" MSGPACK_ENABLE_GCC_CXX_ATOMIC)
IF (MSGPACK_ENABLE_CXX)
LIST (APPEND msgpack_SOURCES
src/object.cpp
)
ENDIF ()
IF (MSGPACK_ENABLE_GCC_CXX_ATOMIC)
LIST (APPEND msgpack_SOURCES
src/gcc_atomic.cpp
)
ENDIF ()
LIST (APPEND msgpack_SOURCES
src/unpack.c
src/objectc.c
src/version.c
src/vrefbuffer.c
src/zone.c
)
LIST (APPEND msgpack_HEADERS
src/msgpack/pack_define.h
src/msgpack/pack_template.h
src/msgpack/unpack_define.h
src/msgpack/unpack_template.h
src/msgpack/sysdep.h
src/msgpack/sbuffer.h
src/msgpack/version.h
src/msgpack/vrefbuffer.h
src/msgpack/zbuffer.h
src/msgpack/fbuffer.h
src/msgpack/pack.h
src/msgpack/unpack.h
src/msgpack/object.h
src/msgpack/zone.h
)
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
)
ENDIF ()
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
@ONLY
)
INCLUDE_DIRECTORIES (
./
src/
src/msgpack/
${CMAKE_CURRENT_BINARY_DIR}/src/
${CMAKE_CURRENT_BINARY_DIR}/src/msgpack/
)
ADD_LIBRARY (msgpack SHARED
${msgpack_SOURCES}
${msgpack_HEADERS}
)
ADD_LIBRARY (msgpack-static STATIC
${msgpack_SOURCES}
${msgpack_HEADERS}
)
SET_TARGET_PROPERTIES (msgpack-static PROPERTIES OUTPUT_NAME "msgpack")
SET_TARGET_PROPERTIES (msgpack PROPERTIES IMPORT_SUFFIX "_import.lib")
SET_TARGET_PROPERTIES (msgpack PROPERTIES SOVERSION 3 VERSION 3.0.0)
IF (MSGPACK_BUILD_TESTS)
ENABLE_TESTING ()
ADD_SUBDIRECTORY (test)
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET_PROPERTY (TARGET msgpack APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3 -DPIC")
SET_PROPERTY (TARGET msgpack-static APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3" )
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE ()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
ENDIF ()
ENDIF ()
INSTALL (TARGETS msgpack msgpack-static DESTINATION lib)
INSTALL (DIRECTORY src/msgpack DESTINATION include)
INSTALL (FILES src/msgpack.h src/msgpack.hpp DESTINATION include)
INSTALL (FILES msgpack.pc DESTINATION lib/pkgconfig)
# Doxygen
FIND_PACKAGE (Doxygen)
IF (DOXYGEN_FOUND)
ADD_CUSTOM_TARGET (
doxygen_c
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.h" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_c" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_c
VERBATIM
)
ADD_CUSTOM_TARGET (
doxygen_cpp
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.hpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc_cpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"MessagePack for C++\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile_cpp
VERBATIM
)
ADD_CUSTOM_TARGET (
doxygen
DEPENDS doxygen_c doxygen_cpp
)
ENDIF ()

View File

@@ -1,3 +1,17 @@
2014-07-02 version 0.5.9:
* Support std::tr1 unordered containers by default (#51, #63, #68, #69)
* Remove some warnings (#56)
* Fix segmentation fault after malloc failures (#58, #59)
* Fix alloc/dealloc mismatch (#52, #61)
* Fix sample codes (#60, #64)
* Support implicit conversion from integer to float/double (#54)
* Improve documents (#45, #75, #82, #83)
* Support CMake (#20, #87)
* Remove Ruby dependencies in bootstrap (#86, #87)
* Add FILE* buffer (#40)
* Other bug fixes and refactoring: #39, #73, #77, #79, #80, #81, #84, #90
2013-12-23 version 0.5.8:
* Move to the new github repository msgpack/msgpack-c

View File

@@ -6,12 +6,10 @@ DOC_FILES = \
NOTICE \
msgpack_vc8.vcproj \
msgpack_vc8.sln \
msgpack_vc2008.vcproj \
msgpack_vc2008.sln \
msgpack_vc.postbuild.bat
EXTRA_DIST = \
$(DOC_FILES)
$(DOC_FILES) CMakeLists.txt test/CMakeLists.txt
pkgconfigdir = $(libdir)/pkgconfig
pkgconfig_DATA = msgpack.pc

View File

@@ -103,7 +103,7 @@ int main(void) {
msgpack::sbuffer buffer;
msgpack::packer<msgpack::sbuffer> pk(&buffer);
pk.pack_array(3)
pk.pack_array(3);
pk.pack(std::string("Log message ... 1"));
pk.pack(std::string("Log message ... 2"));
pk.pack(std::string("Log message ... 3"));
@@ -112,10 +112,10 @@ int main(void) {
msgpack::sbuffer buffer2;
msgpack::packer<msgpack::sbuffer> pk2(&buffer2);
pk2.pack_map(2)
pk2.pack_map(2);
pk2.pack(std::string("x"));
pk2.pack(3);
pk2.pack(std::string("y));
pk2.pack(std::string("y"));
pk2.pack(3.4321);
}
@@ -124,7 +124,7 @@ int main(void) {
## User-defined classes
You can use serialize/deserializes user-defined classes using MSGPACK_DEFINE macro.
You can use serialize/deserializes user-defined classes using `MSGPACK_DEFINE` macro.
```cpp
#include <msgpack.hpp>

174
README.md
View File

@@ -1,73 +1,159 @@
MessagePack for C/C++
=====================
Binary-based efficient object serialization library.
# Msgpack for C/C++
It's like JSON but small and fast.
## Installation
## Overview
Download latest package from [releases of MessagePack](http://sourceforge.net/projects/msgpack/files/) and extract it.
On UNIX-like platform, run ./configure && make && sudo make install:
$ ./configure
$ make
$ sudo make install
On Windows, open msgpack_vc8.vcproj or msgpack_vc2008 file and build it using batch build. DLLs are built on lib folder,
and the headers are built on include folder.
To use the library in your program, include msgpack.hpp header and link "msgpack" library.
MessagePack is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON. But it's faster and smaller. Small integers are encoded into a single byte, and typical short strings require only one extra byte in addition to the strings themselves.
## Example
## 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.
## Contributing
The source for msgpack-c is held at [msgpack-c](https://github.com/msgpack/msgpack-c) github.com site.
To report an issue, use the [msgpack-c issue tracker](https://github.com/msgpack/msgpack-c/issues) at github.com.
## Using Msgpack
### Building and Installing
#### Install from git repository
##### Using autotools
You will need gcc (4.1.0 or higher), autotools.
```
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ ./bootstrap
$ ./configure
$ make
$ sudo make install
```
##### Using cmake
You will need gcc (4.1.0 or higher), cmake.
```
$ git clone https://github.com/msgpack/msgpack-c.git
$ cd msgpack-c
$ cmake .
$ make
```
#### 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
On FreeBSD, you can use Ports Collection. Install [net/msgpack](http://www.freebsd.org/cgi/cvsweb.cgi/ports/devel/msgpack/) package.
##### Gentoo Linux with Portage
On Gentoo Linux, you can use emerge. Install [dev-libs/msgpack](http://gentoo-portage.com/dev-libs/msgpack) package.
##### 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
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
Set 'Where is the source code:' text box and 'Where to build the binaries:' text box.
Click 'Configure' button.
Choose your Visual Studio version.
Click 'Generate' button.
Open the created msgpack.sln on Visual Studio.
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
### Code Example
```CPP
#include <msgpack.hpp>
#include <vector>
int main(void) {
#include <string>
#include <iostream>
int main() {
// This is target object.
std::vector<std::string> target;
target.push_back("Hello,");
target.push_back("World!");
// Serialize it.
msgpack::sbuffer sbuf; // simple buffer
msgpack::pack(&sbuf, target);
// Deserialize the serialized data.
msgpack::unpacked msg; // includes memory pool and deserialized object
msgpack::unpack(&msg, sbuf.data(), sbuf.size());
msgpack::object obj = msg.get();
// Print the deserialized object to stdout.
std::cout << obj << std::endl; // ["Hello," "World!"]
// Convert the deserialized object to staticaly typed object.
std::vector<std::string> result;
obj.convert(&result);
// If the type is mismatched, it throws msgpack::type_error.
obj.as<int>(); // type is mismatched, msgpack::type_error is thrown
}
```
### Quickstart Guides
See [QuickStart for C](QUICKSTART-C.md) and [QuickStart for C++](QUICKSTART-CPP.md) for other example codes.
## License
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.
See also NOTICE file.
For more detailed examples see [QuickStart for C](QUICKSTART-C.md) and [QuickStart for C++](QUICKSTART-CPP.md).

View File

@@ -22,7 +22,7 @@ as comparing that implementations.
or
$ port install msgpack # MacPorts
$ g++ -Wall -lmsgpack crosslang.cc -o crosslang
$ g++ -Wall crosslang.cc -lmsgpack -o crosslang
$ ./crosslang
Usage: ./crosslang [in-file] [out-file]

View File

@@ -38,13 +38,6 @@ test -f ChangeLog || touch ChangeLog
test -f NEWS || touch NEWS
test -f README || cp -f README.md README
./preprocess
if [ $? -ne 0 ]; then
exit 1
fi
ACLOCAL="aclocal"
ACLOCAL_FILES="aclocal.m4"
ALWAYS_CLEAN="config.status config.log config.cache libtool"

View File

@@ -1,6 +1,6 @@
AC_INIT(src/object.cpp)
AC_CONFIG_AUX_DIR(ac)
AM_INIT_AUTOMAKE(msgpack, 0.5.8)
AM_INIT_AUTOMAKE(msgpack, 0.5.9)
AC_CONFIG_HEADER(config.h)
AC_SUBST(CFLAGS)

View File

@@ -5,7 +5,7 @@
// or
// $ port install msgpack # MacPorts
//
// $ g++ -Wall -lmsgpack crosslang.cc
// $ g++ -Wall crosslang.cc -lmsgpack
//
#include <msgpack.hpp>
#include <iostream>

View File

@@ -34,13 +34,10 @@ public:
m_pac.buffer_consumed(count);
while(m_pac.execute()) {
msgpack::object msg = m_pac.data();
auto_zone life( m_pac.release_zone() );
m_pac.reset();
msgpack::unpacked result;
while (m_pac.next(&result)) {
msgpack::object msg = result.get();
auto_zone& life = result.zone();
process_message(msg, life);
}

View File

@@ -12,6 +12,7 @@ copy src\msgpack\sbuffer.h include\msgpack\
copy src\msgpack\version.h include\msgpack\
copy src\msgpack\vrefbuffer.h include\msgpack\
copy src\msgpack\zbuffer.h include\msgpack\
copy src\msgpack\fbuffer.h include\msgpack\
copy src\msgpack\pack.h include\msgpack\
copy src\msgpack\unpack.h include\msgpack\
copy src\msgpack\object.h include\msgpack\
@@ -20,6 +21,7 @@ copy src\msgpack.hpp include\
copy src\msgpack\sbuffer.hpp include\msgpack\
copy src\msgpack\vrefbuffer.hpp include\msgpack\
copy src\msgpack\zbuffer.hpp include\msgpack\
copy src\msgpack\fbuffer.hpp include\msgpack\
copy src\msgpack\pack.hpp include\msgpack\
copy src\msgpack\unpack.hpp include\msgpack\
copy src\msgpack\object.hpp include\msgpack\

View File

@@ -159,102 +159,22 @@
<File
RelativePath=".\src\objectc.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\unpack.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\version.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\vrefbuffer.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\zone.c"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
CompileAs="2"
/>
</FileConfiguration>
</File>
<File
RelativePath=".\src\object.cpp"

View File

@@ -12,23 +12,6 @@ preprocess() {
fi
}
if [ "$1" = "clean" ];then
rm -f src/msgpack/type/tuple.hpp
rm -f src/msgpack/type/define.hpp
rm -f src/msgpack/zone.hpp
else
preprocess src/msgpack/type/tuple.hpp
preprocess src/msgpack/type/define.hpp
preprocess src/msgpack/zone.hpp
fi
cp -f sysdep.h src/msgpack/
cp -f pack_define.h src/msgpack/
cp -f pack_template.h src/msgpack/
cp -f unpack_define.h src/msgpack/
cp -f unpack_template.h src/msgpack/
cp -f cases.mpac test/
cp -f cases_compact.mpac test/
sed -e 's/8\.00/9.00/' < msgpack_vc8.vcproj > msgpack_vc2008.vcproj
sed -e 's/9\.00/10.00/' -e 's/msgpack_vc8/msgpack_vc2008/' < msgpack_vc8.sln > msgpack_vc2008.sln
preprocess src/msgpack/type/tuple.hpp
preprocess src/msgpack/type/define.hpp
preprocess src/msgpack/zone.hpp

View File

@@ -47,6 +47,7 @@ nobase_include_HEADERS = \
msgpack/version.h \
msgpack/vrefbuffer.h \
msgpack/zbuffer.h \
msgpack/fbuffer.h \
msgpack/pack.h \
msgpack/unpack.h \
msgpack/object.h \
@@ -58,6 +59,7 @@ nobase_include_HEADERS += \
msgpack/sbuffer.hpp \
msgpack/vrefbuffer.hpp \
msgpack/zbuffer.hpp \
msgpack/fbuffer.hpp \
msgpack/pack.hpp \
msgpack/unpack.hpp \
msgpack/object.hpp \

View File

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

47
src/msgpack/fbuffer.h Normal file
View File

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

56
src/msgpack/fbuffer.hpp Normal file
View File

@@ -0,0 +1,56 @@
//
// MessagePack for C++ FILE* buffer adaptor
//
// Copyright (C) 2013 Vladimir Volodko
//
// 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_FBUFFER_HPP__
#define MSGPACK_FBUFFER_HPP__
#include <cstdio>
#include <stdexcept>
namespace msgpack {
class fbuffer {
public:
explicit fbuffer(FILE* file) : m_file(file) { }
public:
void write(const char* buf, unsigned int len)
{
if (1 != fwrite(buf, len, 1, m_file)) {
throw std::runtime_error("fwrite() failed");
}
}
FILE* file() const
{
return m_file;
}
private:
fbuffer(const fbuffer&);
fbuffer& operator= (const fbuffer&);
private:
FILE* m_file;
};
} // namespace msgpack
#endif /* msgpack/fbuffer.hpp */

View File

@@ -40,7 +40,7 @@ extern "C" {
* @{
*/
typedef int (*msgpack_packer_write)(void* data, const char* buf, unsigned int len);
typedef int (*msgpack_packer_write)(void* data, const char* buf, size_t len);
typedef struct msgpack_packer {
void* data;

View File

@@ -656,18 +656,18 @@ if(sizeof(unsigned long long) == 2) {
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;
unsigned char buf[5];
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;
unsigned char buf[9];
buf[0] = 0xcb;
#if defined(__arm__) && !(__ARM_EABI__) // arm-oabi
// https://github.com/msgpack/msgpack-perl/pull/1
@@ -713,7 +713,7 @@ msgpack_pack_inline_func(_false)(msgpack_pack_user x)
msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x90 | n;
unsigned char d = 0x90 | (uint8_t)n;
msgpack_pack_append_buffer(x, &d, 1);
} else if(n < 65536) {
unsigned char buf[3];
@@ -734,7 +734,7 @@ msgpack_pack_inline_func(_array)(msgpack_pack_user x, size_t n)
msgpack_pack_inline_func(_map)(msgpack_pack_user x, size_t n)
{
if(n < 16) {
unsigned char d = 0x80 | n;
unsigned char d = 0x80 | (uint8_t)n;
msgpack_pack_append_buffer(x, &TAKE8_8(d), 1);
} else if(n < 65536) {
unsigned char buf[3];

View File

@@ -64,17 +64,18 @@ static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf)
#define MSGPACK_SBUFFER_INIT_SIZE 8192
#endif
static inline int msgpack_sbuffer_write(void* data, const char* buf, unsigned int len)
static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len)
{
msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data;
if(sbuf->alloc - sbuf->size < len) {
void* tmp;
size_t nsize = (sbuf->alloc) ?
sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE;
while(nsize < sbuf->size + len) { nsize *= 2; }
void* tmp = realloc(sbuf->data, nsize);
tmp = realloc(sbuf->data, nsize);
if(!tmp) { return -1; }
sbuf->data = (char*)tmp;

View File

@@ -47,7 +47,7 @@ public:
}
public:
void write(const char* buf, unsigned int len)
void write(const char* buf, size_t len)
{
if(base::alloc - base::size < len) {
expand_buffer(len);

View File

@@ -191,5 +191,18 @@ typedef unsigned int _msgpack_atomic_counter_t;
*/
#if !defined(__cplusplus) && defined(_MSC_VER)
#if !defined(FALSE)
#define FALSE (0)
#endif
#if !defined(TRUE)
#define TRUE (!FALSE)
#endif
#define bool int
#define true TRUE
#define false FALSE
#define inline __inline
#endif
#endif /* msgpack/sysdep.h */

View File

@@ -13,4 +13,5 @@
#include "type/vector.hpp"
#include "type/tuple.hpp"
#include "type/define.hpp"
#include "type/tr1/unordered_map.hpp"
#include "type/tr1/unordered_set.hpp"

3465
src/msgpack/type/define.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -46,7 +46,7 @@
return v; \
} \
template <> \
void operator<< (object::with_zone& o, const enum& v) \
inline void operator<< (object::with_zone& o, const enum& v) \
{ \
o << static_cast<int>(v); \
} \
@@ -107,8 +107,13 @@ struct define<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
{
if(o.type != type::ARRAY) { throw type_error(); }
const size_t size = o.via.array.size;
<%0.upto(i) {|j|%>
if(size <= <%=j%>) { return; } o.via.array.ptr[<%=j%>].convert(&a<%=j%>);<%}%>
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
{

View File

@@ -29,8 +29,18 @@ namespace msgpack {
inline float& operator>> (object o, float& v)
{
if(o.type != type::DOUBLE) { throw type_error(); }
v = (float)o.via.dec;
if(o.type == type::DOUBLE) {
v = (float)o.via.dec;
}
else if (o.type == type::POSITIVE_INTEGER) {
v = (float)o.via.u64;
}
else if (o.type == type::NEGATIVE_INTEGER) {
v = (float)o.via.i64;
}
else {
throw type_error();
}
return v;
}
@@ -44,8 +54,18 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const float& v)
inline double& operator>> (object o, double& v)
{
if(o.type != type::DOUBLE) { throw type_error(); }
v = o.via.dec;
if(o.type == type::DOUBLE) {
v = o.via.dec;
}
else if (o.type == type::POSITIVE_INTEGER) {
v = (double)o.via.u64;
}
else if (o.type == type::NEGATIVE_INTEGER) {
v = (double)o.via.i64;
}
else {
throw type_error();
}
return v;
}

View File

@@ -19,13 +19,32 @@
#define MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP__
#include "msgpack/object.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 {
template <typename K, typename V>
inline std::tr1::unordered_map<K, V> operator>> (object o, std::tr1::unordered_map<K, V>& v)
inline MSGPACK_STD_TR1::unordered_map<K, V> operator>> (object o, MSGPACK_STD_TR1::unordered_map<K, V>& v)
{
if(o.type != type::MAP) { throw type_error(); }
object_kv* p(o.via.map.ptr);
@@ -39,10 +58,10 @@ inline std::tr1::unordered_map<K, V> operator>> (object o, std::tr1::unordered_m
}
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_map<K,V>& v)
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v)
{
o.pack_map(v.size());
for(typename std::tr1::unordered_map<K,V>::const_iterator it(v.begin()), it_end(v.end());
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);
@@ -51,7 +70,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_
}
template <typename K, typename V>
inline void operator<< (object::with_zone& o, const std::tr1::unordered_map<K,V>& v)
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_map<K,V>& v)
{
o.type = type::MAP;
if(v.empty()) {
@@ -62,7 +81,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_map<K,V>
object_kv* const pend = p + v.size();
o.via.map.ptr = p;
o.via.map.size = v.size();
typename std::tr1::unordered_map<K,V>::const_iterator it(v.begin());
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);
@@ -74,7 +93,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_map<K,V>
template <typename K, typename V>
inline std::tr1::unordered_multimap<K, V> operator>> (object o, std::tr1::unordered_multimap<K, V>& v)
inline MSGPACK_STD_TR1::unordered_multimap<K, V> operator>> (object o, MSGPACK_STD_TR1::unordered_multimap<K, V>& v)
{
if(o.type != type::MAP) { throw type_error(); }
object_kv* p(o.via.map.ptr);
@@ -89,10 +108,10 @@ inline std::tr1::unordered_multimap<K, V> operator>> (object o, std::tr1::unorde
}
template <typename Stream, typename K, typename V>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_multimap<K,V>& v)
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v)
{
o.pack_map(v.size());
for(typename std::tr1::unordered_multimap<K,V>::const_iterator it(v.begin()), it_end(v.end());
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);
@@ -101,7 +120,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_
}
template <typename K, typename V>
inline void operator<< (object::with_zone& o, const std::tr1::unordered_multimap<K,V>& v)
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap<K,V>& v)
{
o.type = type::MAP;
if(v.empty()) {
@@ -112,7 +131,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_multimap
object_kv* const pend = p + v.size();
o.via.map.ptr = p;
o.via.map.size = v.size();
typename std::tr1::unordered_multimap<K,V>::const_iterator it(v.begin());
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);
@@ -125,5 +144,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_multimap
} // namespace msgpack
#undef MSGPACK_STD_TR1
#endif /* msgpack/type/map.hpp */

View File

@@ -19,13 +19,31 @@
#define MSGPACK_TYPE_TR1_UNORDERED_SET_HPP__
#include "msgpack/object.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 {
template <typename T>
inline std::tr1::unordered_set<T>& operator>> (object o, std::tr1::unordered_set<T>& v)
inline MSGPACK_STD_TR1::unordered_set<T>& operator>> (object 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;
@@ -38,10 +56,10 @@ inline std::tr1::unordered_set<T>& operator>> (object o, std::tr1::unordered_set
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_set<T>& v)
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_set<T>& v)
{
o.pack_array(v.size());
for(typename std::tr1::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
for(typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
@@ -49,7 +67,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_
}
template <typename T>
inline void operator<< (object::with_zone& o, const std::tr1::unordered_set<T>& v)
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_set<T>& v)
{
o.type = type::ARRAY;
if(v.empty()) {
@@ -60,7 +78,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_set<T>&
object* const pend = p + v.size();
o.via.array.ptr = p;
o.via.array.size = v.size();
typename std::tr1::unordered_set<T>::const_iterator it(v.begin());
typename MSGPACK_STD_TR1::unordered_set<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);
++p;
@@ -71,7 +89,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_set<T>&
template <typename T>
inline std::tr1::unordered_multiset<T>& operator>> (object o, std::tr1::unordered_multiset<T>& v)
inline MSGPACK_STD_TR1::unordered_multiset<T>& operator>> (object 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;
@@ -84,10 +102,10 @@ inline std::tr1::unordered_multiset<T>& operator>> (object o, std::tr1::unordere
}
template <typename Stream, typename T>
inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_multiset<T>& v)
inline packer<Stream>& operator<< (packer<Stream>& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v)
{
o.pack_array(v.size());
for(typename std::tr1::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
for(typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin()), it_end(v.end());
it != it_end; ++it) {
o.pack(*it);
}
@@ -95,7 +113,7 @@ inline packer<Stream>& operator<< (packer<Stream>& o, const std::tr1::unordered_
}
template <typename T>
inline void operator<< (object::with_zone& o, const std::tr1::unordered_multiset<T>& v)
inline void operator<< (object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset<T>& v)
{
o.type = type::ARRAY;
if(v.empty()) {
@@ -106,7 +124,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_multiset
object* const pend = p + v.size();
o.via.array.ptr = p;
o.via.array.size = v.size();
typename std::tr1::unordered_multiset<T>::const_iterator it(v.begin());
typename MSGPACK_STD_TR1::unordered_multiset<T>::const_iterator it(v.begin());
do {
*p = object(*it, o.zone);
++p;
@@ -118,5 +136,7 @@ inline void operator<< (object::with_zone& o, const std::tr1::unordered_multiset
} // namespace msgpack
#undef MSGPACK_STD_TR1
#endif /* msgpack/type/set.hpp */

13691
src/msgpack/type/tuple.hpp Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -232,7 +232,7 @@ msgpack_unpack_func(int, _execute)(msgpack_unpack_struct(_context)* ctx, const c
case 0xdd: // array 32
case 0xde: // map 16
case 0xdf: // map 32
again_fixed_trail(NEXT_CS(p), 2 << (((unsigned int)*p) & 0x01));
again_fixed_trail(NEXT_CS(p), 2u << (((unsigned int)*p) & 0x01));
default:
goto _failed;
}
@@ -397,7 +397,7 @@ _end:
ctx->cs = cs;
ctx->trail = trail;
ctx->top = top;
*off = p - (const unsigned char*)data;
*off = (size_t)(p - (const unsigned char*)data);
return ret;
}

View File

@@ -98,6 +98,7 @@ void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vref);
static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size)
{
msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer));
if (vbuf == NULL) return NULL;
if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) {
free(vbuf);
return NULL;
@@ -130,7 +131,7 @@ static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffe
static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref)
{
return vref->tail - vref->array;
return (size_t)(vref->tail - vref->array);
}

View File

@@ -65,7 +65,7 @@ static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf);
#define MSGPACK_ZBUFFER_RESERVE_SIZE 512
#endif
static inline int msgpack_zbuffer_write(void* data, const char* buf, unsigned int len);
static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len);
static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf);
@@ -91,6 +91,7 @@ void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf)
msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size)
{
msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer));
if (zbuf == NULL) return NULL;
if(!msgpack_zbuffer_init(zbuf, level, init_size)) {
free(zbuf);
return NULL;
@@ -123,7 +124,7 @@ bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf)
return true;
}
int msgpack_zbuffer_write(void* data, const char* buf, unsigned int len)
int msgpack_zbuffer_write(void* data, const char* buf, size_t len)
{
msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data;

View File

@@ -40,7 +40,7 @@ public:
}
public:
void write(const char* buf, unsigned int len)
void write(const char* buf, size_t len)
{
if(msgpack_zbuffer_write(this, buf, len) < 0) {
throw std::bad_alloc();

View File

@@ -90,13 +90,14 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size);
void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size)
{
char* ptr;
msgpack_zone_chunk_list* cl = &zone->chunk_list;
if(zone->chunk_list.free < size) {
return msgpack_zone_malloc_expand(zone, size);
}
char* ptr = cl->ptr;
ptr = cl->ptr;
cl->free -= size;
cl->ptr += size;

464
src/msgpack/zone.hpp Normal file
View File

@@ -0,0 +1,464 @@
//
// 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_ZONE_HPP__
#define MSGPACK_ZONE_HPP__
#include "zone.h"
#include <cstdlib>
#include <memory>
#include <vector>
namespace msgpack {
class zone : public msgpack_zone {
public:
zone(size_t chunk_size = MSGPACK_ZONE_CHUNK_SIZE);
~zone();
public:
void* malloc(size_t size);
void* malloc_no_align(size_t size);
void push_finalizer(void (*func)(void*), void* data);
template <typename T>
void push_finalizer(std::auto_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);
}
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_malloc(size_t size);
template <typename T>
static void object_destructor(void* obj);
typedef msgpack_zone base;
private:
zone(const zone&);
};
inline zone::zone(size_t chunk_size)
{
msgpack_zone_init(this, chunk_size);
}
inline zone::~zone()
{
msgpack_zone_destroy(this);
}
inline void* zone::malloc(size_t size)
{
void* ptr = msgpack_zone_malloc(this, size);
if(!ptr) {
throw std::bad_alloc();
}
return ptr;
}
inline void* zone::malloc_no_align(size_t size)
{
void* ptr = msgpack_zone_malloc_no_align(this, size);
if(!ptr) {
throw std::bad_alloc();
}
return ptr;
}
inline void zone::push_finalizer(void (*func)(void*), void* data)
{
if(!msgpack_zone_push_finalizer(this, func, data)) {
throw std::bad_alloc();
}
}
template <typename T>
inline void zone::push_finalizer(std::auto_ptr<T> obj)
{
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, obj.get())) {
throw std::bad_alloc();
}
obj.release();
}
inline void zone::clear()
{
msgpack_zone_clear(this);
}
inline void zone::swap(zone& o)
{
msgpack_zone_swap(this, &o);
}
template <typename T>
void zone::object_destructor(void* obj)
{
reinterpret_cast<T*>(obj)->~T();
}
inline void zone::undo_malloc(size_t size)
{
base::chunk_list.ptr -= size;
base::chunk_list.free += size;
}
template <typename T>
T* zone::allocate()
{
void* x = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T();
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(sizeof(T));
throw;
}
}
template <typename T, typename A1>
T* zone::allocate(A1 a1)
{
void* x = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2>
T* zone::allocate(A1 a1, A2 a2)
{
void* x = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(sizeof(T));
throw;
}
}
template <typename T, typename A1, typename A2, typename A3>
T* zone::allocate(A1 a1, A2 a2, A3 a3)
{
void* x = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(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 = malloc(sizeof(T));
if(!msgpack_zone_push_finalizer(this, &zone::object_destructor<T>, x)) {
undo_malloc(sizeof(T));
throw std::bad_alloc();
}
try {
return new (x) T(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10, a11, a12, a13, a14, a15);
} catch (...) {
--base::finalizer_array.tail;
undo_malloc(sizeof(T));
throw;
}
}
} // namespace msgpack
#endif /* msgpack/zone.hpp */

View File

@@ -44,7 +44,16 @@ public:
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);
}
<%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(', ')%>);

View File

@@ -111,11 +111,11 @@ void msgpack_object_print(FILE* out, msgpack_object o)
break;
case MSGPACK_OBJECT_POSITIVE_INTEGER:
fprintf(out, "%"PRIu64, o.via.u64);
fprintf(out, "%" PRIu64, o.via.u64);
break;
case MSGPACK_OBJECT_NEGATIVE_INTEGER:
fprintf(out, "%"PRIi64, o.via.i64);
fprintf(out, "%" PRIi64, o.via.i64);
break;
case MSGPACK_OBJECT_DOUBLE:
@@ -164,7 +164,7 @@ void msgpack_object_print(FILE* out, msgpack_object o)
default:
// FIXME
fprintf(out, "#<UNKNOWN %i %"PRIu64">", o.type, o.via.u64);
fprintf(out, "#<UNKNOWN %i %" PRIu64 ">", o.type, o.via.u64);
}
}

View File

@@ -56,7 +56,7 @@ static int template_execute(template_context* ctx,
static inline msgpack_object template_callback_root(unpack_user* u)
{ msgpack_object o = {}; return o; }
{ msgpack_object o = { MSGPACK_OBJECT_NIL }; return o; }
static inline int template_callback_uint8(unpack_user* u, uint8_t d, msgpack_object* o)
{ o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
@@ -71,19 +71,19 @@ static inline int template_callback_uint64(unpack_user* u, uint64_t d, msgpack_o
{ o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
static inline int template_callback_int8(unpack_user* u, int8_t d, msgpack_object* o)
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
static inline int template_callback_int16(unpack_user* u, int16_t d, msgpack_object* o)
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
static inline int template_callback_int32(unpack_user* u, int32_t d, msgpack_object* o)
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
static inline int template_callback_int64(unpack_user* u, int64_t d, msgpack_object* o)
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = d; return 0; }
{ if(d >= 0) { o->type = MSGPACK_OBJECT_POSITIVE_INTEGER; o->via.u64 = (uint64_t)d; return 0; }
else { o->type = MSGPACK_OBJECT_NEGATIVE_INTEGER; o->via.i64 = d; return 0; } }
static inline int template_callback_float(unpack_user* u, float d, msgpack_object* o)

View File

@@ -98,7 +98,7 @@ int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf,
const char* buf, size_t len)
{
if(vbuf->tail == vbuf->end) {
const size_t nused = vbuf->tail - vbuf->array;
const size_t nused = (size_t)(vbuf->tail - vbuf->array);
const size_t nnext = nused * 2;
struct iovec* nvec = (struct iovec*)realloc(
@@ -169,11 +169,11 @@ int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to)
empty->next = NULL;
const size_t nused = vbuf->tail - vbuf->array;
const size_t nused = (size_t)(vbuf->tail - vbuf->array);
if(to->tail + nused < vbuf->end) {
const size_t tosize = to->tail - to->array;
const size_t tosize = (size_t)(to->tail - to->array);
const size_t reqsize = nused + tosize;
size_t nnext = (to->end - to->array) * 2;
size_t nnext = (size_t)(to->end - to->array) * 2;
while(nnext < reqsize) {
nnext *= 2;
}

View File

@@ -84,9 +84,8 @@ void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size)
msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc(
sizeof(msgpack_zone_chunk) + sz);
if (chunk == NULL) return NULL;
char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk);
chunk->next = cl->head;
cl->head = chunk;
cl->free = sz - size;
@@ -128,7 +127,7 @@ bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone,
{
msgpack_zone_finalizer_array* const fa = &zone->finalizer_array;
const size_t nused = fa->end - fa->array;
const size_t nused = (size_t)(fa->end - fa->array);
size_t nnext;
if(nused == 0) {

55
test/CMakeLists.txt Normal file
View File

@@ -0,0 +1,55 @@
FIND_PACKAGE (GTest REQUIRED)
FIND_PACKAGE (ZLIB REQUIRED)
FIND_PACKAGE (Threads REQUIRED)
INCLUDE_DIRECTORIES (
${GTEST_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
)
SET (check_PROGRAMS
pack_unpack.cc
version.cc
streaming_c.cc
pack_unpack_c.cc
zone.cc
msgpack_test.cpp
buffer.cc
msgpackc_test.cpp
streaming.cc
convert.cc
fixint_c.cc
)
IF (MSGPACK_ENABLE_CXX)
LIST (APPEND check_PROGRAMS
cases.cc
fixint.cc
object.cc
)
ENDIF ()
FOREACH (source_file ${check_PROGRAMS})
GET_FILENAME_COMPONENT (source_file_we ${source_file} NAME_WE)
ADD_EXECUTABLE (
${source_file_we}
${source_file}
)
TARGET_LINK_LIBRARIES (${source_file_we}
msgpack
${GTEST_BOTH_LIBRARIES}
${ZLIB_LIBRARIES}
${CMAKE_THREAD_LIBS_INIT}
)
ADD_TEST (${source_file_we} ${source_file_we})
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET_PROPERTY (TARGET ${source_file_we} APPEND_STRING PROPERTY COMPILE_FLAGS "-Wall -g -O3")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
IF (CMAKE_CXX_FLAGS MATCHES "/W[0-4]")
STRING(REGEX REPLACE "/W[0-4]" "/W4" CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
ELSE ()
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
ENDIF ()
ENDIF ()
ENDFOREACH ()

View File

@@ -1,4 +1,6 @@
#include <msgpack.hpp>
#include <msgpack/fbuffer.hpp>
#include <msgpack/fbuffer.h>
#include <msgpack/zbuffer.hpp>
#include <gtest/gtest.h>
#include <string.h>
@@ -70,3 +72,49 @@ TEST(buffer, zbuffer)
zbuf.flush();
}
TEST(buffer, fbuffer)
{
FILE* file = tmpfile();
EXPECT_TRUE( file != NULL );
msgpack::fbuffer fbuf(file);
EXPECT_EQ(file, fbuf.file());
fbuf.write("a", 1);
fbuf.write("a", 1);
fbuf.write("a", 1);
fflush(file);
rewind(file);
for (size_t i=0; i < 3; ++i) {
int ch = fgetc(file);
EXPECT_TRUE(ch != EOF);
EXPECT_EQ('a', static_cast<char>(ch));
}
EXPECT_EQ(EOF, fgetc(file));
fclose(file);
}
TEST(buffer, fbuffer_c)
{
FILE* file = tmpfile();
void* fbuf = (void*)file;
EXPECT_TRUE( file != NULL );
EXPECT_EQ(0, msgpack_fbuffer_write(fbuf, "a", 1));
EXPECT_EQ(0, msgpack_fbuffer_write(fbuf, "a", 1));
EXPECT_EQ(0, msgpack_fbuffer_write(fbuf, "a", 1));
fflush(file);
rewind(file);
for (size_t i=0; i < 3; ++i) {
int ch = fgetc(file);
EXPECT_TRUE(ch != EOF);
EXPECT_EQ('a', (char) ch);
}
EXPECT_EQ(EOF, fgetc(file));
fclose(file);
}

View File

@@ -7,6 +7,7 @@
#include <deque>
#include <set>
#include <list>
#include <limits>
#include <gtest/gtest.h>
@@ -178,6 +179,59 @@ TEST(MSGPACK, simple_buffer_float)
}
}
namespace {
template<typename F, typename I>
struct TypePair {
typedef F float_type;
typedef I integer_type;
};
} // namespace
template <typename T>
class IntegerToFloatingPointTest : public testing::Test {
};
TYPED_TEST_CASE_P(IntegerToFloatingPointTest);
TYPED_TEST_P(IntegerToFloatingPointTest, simple_buffer)
{
typedef typename TypeParam::float_type float_type;
typedef typename TypeParam::integer_type integer_type;
vector<integer_type> v;
v.push_back(0);
v.push_back(1);
if (numeric_limits<integer_type>::is_signed) v.push_back(-1);
else v.push_back(2);
v.push_back(numeric_limits<integer_type>::min());
v.push_back(numeric_limits<integer_type>::max());
for (unsigned int i = 0; i < kLoop; i++) {
v.push_back(rand());
}
for (unsigned int i = 0; i < v.size() ; i++) {
msgpack::sbuffer sbuf;
integer_type val1 = v[i];
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
float_type val2;
obj.convert(&val2);
EXPECT_TRUE(fabs(val2 - val1) <= kEPS);
}
}
REGISTER_TYPED_TEST_CASE_P(IntegerToFloatingPointTest,
simple_buffer);
typedef testing::Types<TypePair<float, signed long long>,
TypePair<float, unsigned long long>,
TypePair<double, signed long long>,
TypePair<double, unsigned long long> > IntegerToFloatingPointTestTypes;
INSTANTIATE_TYPED_TEST_CASE_P(IntegerToFloatingPointTestInstance,
IntegerToFloatingPointTest,
IntegerToFloatingPointTestTypes);
TEST(MSGPACK, simple_buffer_double)
{
vector<double> v;
@@ -452,10 +506,10 @@ TEST(MSGPACK_STL, simple_buffer_multiset)
// TR1
#ifdef HAVE_TR1_UNORDERED_MAP
#ifdef MSGPACK_HAS_STD_TR1_UNOURDERED_MAP
#include <tr1/unordered_map>
#include "msgpack/type/tr1/unordered_map.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_map)
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_map)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_map<int, int> val1;
@@ -479,7 +533,7 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_map)
}
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multimap)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_multimap<int, int> val1;
@@ -513,10 +567,10 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
}
#endif
#ifdef HAVE_TR1_UNORDERED_SET
#ifdef MSGPACK_HAS_STD_TR1_UNOURDERED_SET
#include <tr1/unordered_set>
#include "msgpack/type/tr1/unordered_set.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_set)
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_set)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_set<int> val1;
@@ -538,7 +592,7 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_set)
}
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
TEST(MSGPACK_TR1, simple_buffer_tr1_unordered_multiset)
{
for (unsigned int k = 0; k < kLoop; k++) {
tr1::unordered_multiset<int> val1;
@@ -569,6 +623,123 @@ TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
}
#endif
#ifdef MSGPACK_HAS_STD_UNOURDERED_MAP
#include <unordered_map>
#include "msgpack/type/tr1/unordered_map.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_map)
{
for (unsigned int k = 0; k < kLoop; k++) {
unordered_map<int, int> val1;
for (unsigned int i = 0; i < kElements; i++)
val1[rand()] = rand();
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
unordered_map<int, int> val2;
obj.convert(&val2);
EXPECT_EQ(val1.size(), val2.size());
unordered_map<int, int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it) {
EXPECT_TRUE(val2.find(it->first) != val2.end());
EXPECT_EQ(it->second, val2.find(it->first)->second);
}
}
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multimap)
{
for (unsigned int k = 0; k < kLoop; k++) {
unordered_multimap<int, int> val1;
for (unsigned int i = 0; i < kElements; i++) {
int i1 = rand();
val1.insert(make_pair(i1, rand()));
val1.insert(make_pair(i1, rand()));
}
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
unordered_multimap<int, int> val2;
obj.convert(&val2);
vector<pair<int, int> > v1, v2;
unordered_multimap<int, int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
v1.push_back(make_pair(it->first, it->second));
for (it = val2.begin(); it != val2.end(); ++it)
v2.push_back(make_pair(it->first, it->second));
EXPECT_EQ(val1.size(), val2.size());
EXPECT_EQ(v1.size(), v2.size());
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
EXPECT_TRUE(v1 == v2);
}
}
#endif
#ifdef MSGPACK_HAS_STD_UNOURDERED_SET
#include <unordered_set>
#include "msgpack/type/tr1/unordered_set.hpp"
TEST(MSGPACK_TR1, simple_buffer_unordered_set)
{
for (unsigned int k = 0; k < kLoop; k++) {
unordered_set<int> val1;
for (unsigned int i = 0; i < kElements; i++)
val1.insert(rand());
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
unordered_set<int> val2;
obj.convert(&val2);
EXPECT_EQ(val1.size(), val2.size());
unordered_set<int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
EXPECT_TRUE(val2.find(*it) != val2.end());
}
}
TEST(MSGPACK_TR1, simple_buffer_unordered_multiset)
{
for (unsigned int k = 0; k < kLoop; k++) {
unordered_multiset<int> val1;
for (unsigned int i = 0; i < kElements; i++)
val1.insert(rand());
msgpack::sbuffer sbuf;
msgpack::pack(sbuf, val1);
msgpack::zone z;
msgpack::object obj;
msgpack::unpack_return ret =
msgpack::unpack(sbuf.data(), sbuf.size(), NULL, &z, &obj);
EXPECT_EQ(msgpack::UNPACK_SUCCESS, ret);
unordered_multiset<int> val2;
obj.convert(&val2);
vector<int> v1, v2;
unordered_multiset<int>::const_iterator it;
for (it = val1.begin(); it != val1.end(); ++it)
v1.push_back(*it);
for (it = val2.begin(); it != val2.end(); ++it)
v2.push_back(*it);
EXPECT_EQ(val1.size(), val2.size());
EXPECT_EQ(v1.size(), v2.size());
sort(v1.begin(), v1.end());
sort(v2.begin(), v2.end());
EXPECT_TRUE(v1 == v2);
}
}
#endif
// User-Defined Structures
class TestClass
@@ -672,9 +843,11 @@ public:
TestEnumType t2;
TestEnumType t3;
MSGPACK_DEFINE((int&)t1, (int&)t2, (int&)t3);
MSGPACK_DEFINE(t1, t2, t3);
};
MSGPACK_ADD_ENUM(TestEnumMemberClass::TestEnumType);
TEST(MSGPACK_USER_DEFINED, simple_buffer_enum_member)
{
TestEnumMemberClass val1;

View File

@@ -31,7 +31,7 @@ struct myclass {
myclass() : num(0), str("default") { }
myclass(int num, const std::string& str) :
num(0), str("default") { }
num(num), str(str) { }
~myclass() { }