├── .gitignore ├── .travis.yml ├── LICENSE ├── README.md ├── bin ├── json2msgpack └── msgpack2json ├── binding.gyp ├── deps └── msgpack │ ├── AUTHORS │ ├── COPYING │ ├── LICENSE │ ├── gcc_atomic.hpp │ ├── msgpack.gyp │ ├── msgpack.h │ ├── msgpack.hpp │ ├── msgpack │ ├── adaptor │ │ ├── adaptor_base.hpp │ │ ├── bool.hpp │ │ ├── char_ptr.hpp │ │ ├── check_container_size.hpp │ │ ├── cpp11 │ │ │ ├── array.hpp │ │ │ ├── array_char.hpp │ │ │ ├── forward_list.hpp │ │ │ ├── tuple.hpp │ │ │ ├── unordered_map.hpp │ │ │ └── unordered_set.hpp │ │ ├── define.hpp │ │ ├── deque.hpp │ │ ├── detail │ │ │ ├── cpp03_define.hpp │ │ │ ├── cpp03_msgpack_tuple.hpp │ │ │ ├── cpp11_define.hpp │ │ │ └── cpp11_msgpack_tuple.hpp │ │ ├── fixint.hpp │ │ ├── float.hpp │ │ ├── int.hpp │ │ ├── list.hpp │ │ ├── map.hpp │ │ ├── msgpack_tuple.hpp │ │ ├── nil.hpp │ │ ├── pair.hpp │ │ ├── raw.hpp │ │ ├── set.hpp │ │ ├── string.hpp │ │ ├── tr1 │ │ │ ├── unordered_map.hpp │ │ │ └── unordered_set.hpp │ │ ├── vector.hpp │ │ ├── vector_bool.hpp │ │ └── vector_char.hpp │ ├── cpp_config.hpp │ ├── detail │ │ ├── cpp03_zone.hpp │ │ └── cpp11_zone.hpp │ ├── fbuffer.h │ ├── fbuffer.hpp │ ├── gcc_atomic.h │ ├── iterator.hpp │ ├── object.h │ ├── object.hpp │ ├── object_fwd.hpp │ ├── pack.h │ ├── pack.hpp │ ├── pack_define.h │ ├── pack_template.h │ ├── sbuffer.h │ ├── sbuffer.hpp │ ├── sysdep.h │ ├── type.hpp │ ├── unpack.h │ ├── unpack.hpp │ ├── unpack_define.h │ ├── unpack_template.h │ ├── util.h │ ├── version.h │ ├── version.hpp │ ├── version_master.h │ ├── versioning.hpp │ ├── vrefbuffer.h │ ├── vrefbuffer.hpp │ ├── zbuffer.h │ ├── zbuffer.hpp │ ├── zone.h │ └── zone.hpp │ ├── objectc.c │ ├── unpack.c │ ├── version.c │ ├── vrefbuffer.c │ └── zone.c ├── lib └── msgpack.js ├── package.json ├── run_tests ├── src └── msgpack.cc └── test ├── benchmark └── benchmark.js ├── fixtures └── stub.js ├── lib └── msgpack.js └── regression.js /.gitignore: -------------------------------------------------------------------------------- 1 | README.html 2 | tags 3 | build 4 | src/.lock-wscript 5 | deps/msgpack/dist 6 | deps/msgpack/*.o 7 | deps/msgpack/*.lo 8 | deps/msgpack/.deps 9 | deps/msgpack/.libs 10 | test/packed-data 11 | node_modules 12 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | 3 | node_js: 4 | - "0.8" 5 | - "0.10" 6 | 7 | sudo: false 8 | 9 | cache: 10 | directories: 11 | - node_modules 12 | 13 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | ================================================================================ 2 | Copyright (c) 2010, Peter Griess 3 | All rights reserved. 4 | 5 | Redistribution and use in source and binary forms, with or without 6 | modification, are permitted provided that the following conditions are met: 7 | 8 | * Redistributions of source code must retain the above copyright notice, 9 | this list of conditions and the following disclaimer. 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | * Neither the name node-msgpack nor the names of its contributors 14 | may be used to endorse or promote products derived from this software 15 | without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 18 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 19 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 20 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 21 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 23 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 24 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 25 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 26 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 | ================================================================================ 28 | 29 | The above license applies to the contents of all directories other than deps/. 30 | The contents of the deps/ directory contain third-party dependencies which 31 | provided under different licenses. These dependencies and their associated 32 | licenses are as follows 33 | 34 | . MessagePack, located in deps/msgpack/. 35 | 36 | This is licensed under the Apache 2 license. See deps/msgpack/LICENSE 37 | and deps/msgpack/NOTICE for further information> 38 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | `node-msgpack` is an addon for [NodeJS](http://nodejs.org) that provides an 2 | API for serializing and de-serializing JavaScript objects using the 3 | [MessagePack](http://msgpack.sourceforge.net) library. The performance of this 4 | addon compared to the native `JSON` object isn't too bad, and the space 5 | required for serialized data is far less than JSON. 6 | 7 | ### Performance 8 | 9 | `node-msgpack` is currently slower than the built-in `JSON.stringify()` and 10 | `JSON.parse()` methods. In recent versions of node.js, the JSON functions 11 | have been heavily optimized. node-msgpack is still more compact, and we are 12 | currently working performance improvements. Testing shows that, over 500k 13 | iterations, `msgpack.pack()` is about 5x slower than `JSON.stringify()`, and 14 | `msgpack.unpack()` is about 3.5x slower than `JSON.parse()`. 15 | 16 | Old performance numbers are below. 17 | 18 | The following tests were performed with 500,000 instances of 19 | the JavaScript object `{'abcdef' : 1, 'qqq' : 13, '19' : [1, 2, 3, 4]}`: 20 | 21 | * `JSON.stringify()` 7.17 seconds 22 | * `JSON.parse(JSON.stringify())` 22.18 seconds 23 | * `msgpack.pack()` 5.80 seconds 24 | * `msgpack.unpack(msgpack.pack())` 8.62 seconds 25 | 26 | Note that `node-msgpack` produces and consumes Buffer objects, and a such does 27 | not incur encoding/decoding overhead when performing I/O with native strings. 28 | 29 | ### Usage 30 | 31 | This module provides two methods: `pack()`, which consumes a JavaScript object 32 | and produces a node Buffer object; and `unpack()`, which consumes a node Buffer 33 | object and produces a JavaScript object. Packing of all native JavaScript types 34 | (undefined, boolean, numbers, strings, arrays and objects) is supported, as 35 | is the node Buffer type. 36 | 37 | The below code snippet packs and then unpacks a JavaScript object, verifying 38 | the resulting object at the end using `assert.deepEqual()`. 39 | 40 | ```javascript 41 | var assert = require('assert'); 42 | var msgpack = require('msgpack'); 43 | 44 | var o = {"a" : 1, "b" : 2, "c" : [1, 2, 3]}; 45 | var b = msgpack.pack(o); 46 | var oo = msgpack.unpack(b); 47 | 48 | assert.deepEqual(oo, o); 49 | ``` 50 | 51 | As a convenience, a higher level streaming API is provided in the 52 | `msgpack.Stream` class, which can be constructed around a `net.Stream` 53 | instance. This object emits `msg` events when an object has been received. 54 | 55 | ```javascript 56 | var msgpack = require('msgpack'); 57 | 58 | // ... get a net.Stream instance, s, from somewhere 59 | 60 | var ms = new msgpack.Stream(s); 61 | ms.addListener('msg', function(m) { 62 | sys.debug('received message: ' + sys.inspect(m)); 63 | }); 64 | ``` 65 | 66 | ### Type Mapping 67 | 68 | The JavaScript type system does not map cleanly on to the MsgPack type system, 69 | though it's pretty close. 70 | 71 | When packing, JavaScript values are mapped to MsgPack types as follows 72 | 73 | * `undefined` and `null` values map to `MSGPACK_OBJECT_NIL` 74 | * `boolean` values map to `MSGPACK_OBJECT_BOOLEAN` 75 | * `number` values map differently depending on their value 76 | * Floating point values map to `MSGPACK_OBJECT_DOUBLE` 77 | * Positive values map to `MSGPACK_OBJECT_POSITIVE_INTEGER` 78 | * Negative values map to `MSGPACK_OBJECT_NEGATIVE_INTEGER` 79 | * `string` values map to `MSGPACK_OBJECT_RAW`; all strings are serialized 80 | with UTF-8 encoding 81 | * Array values (as defined by `Array.isArray()`) map to 82 | `MSGPACK_OBJECT_ARRAY`; each element in the array is packed individually 83 | the rules in this list 84 | * NodeJS Buffer values map to `MSGPACK_OBJECT_RAW` 85 | * Everything else maps to `MSGPACK_OBJECT_MAP`, where we iterate over 86 | the object's properties and pack them and their values as per the 87 | mappings in this list 88 | 89 | When unpacking, MsgPack types are mapped to JavaScript values as follows 90 | 91 | * `MSGPACK_OBJECT_NIL` values map to the `null` value 92 | * `MSGPACK_OBJECT_BOOLEAN` values map to `boolean` values 93 | * `MSGPACK_OBJECT_POSITIVE_INTEGER`, `MSGPACK_OBJECT_NEGATIVE_INTEGER` and 94 | `MSGPACK_OBJECT_DOUBLE` values map to `number` values 95 | * `MSGPACK_OBJECT_ARRAY` values map to arrays; each object in the array is 96 | packed individually using the rules in this list 97 | * `MSGPACK_OBJECT_RAW` values are mapped to `string` values; these values are 98 | unpacked using either UTF-8 or ASCII encoding, depending on the contents 99 | of the raw buffer 100 | * `MSGPACK_OBJECT_MAP` values are mapped to JavaScript objects; keys and 101 | values are unpacked individually using the rules in this list 102 | 103 | Strings are particularly problematic here, as it's difficult to get hints down 104 | into the packing and unpacking codepaths about how to interpret a particular 105 | string or `MSGPACK_OBJECT_RAW`. If you have strict requirements about the 106 | encoding of your strings, it's recommended that you populate a Buffer object 107 | yourself (e.g. using `Buffer.write()`) and pack that buffer rather than the 108 | string. This will ensure that you can control what gets packed. 109 | 110 | When unpacking, things are trickier as there is no way to know the encoding 111 | used when a string was packed. There is an [an open 112 | ticket](http://github.com/msgpack/msgpack/issues/issue/13) for the MsgPack 113 | format to address this. 114 | 115 | ### Command Line Utilities 116 | 117 | As a convenience and for debugging, `bin/json2msgpack` and `bin/msgpack2json` 118 | are provided to convert JSON data to and from MessagePack data, reading from 119 | stdin and writing to stdout. 120 | 121 | % echo '[1, 2, 3]' | ./bin/json2msgpack | xxd - 122 | 0000000: 9301 0203 .... 123 | % echo '[1, 2, 3]' | ./bin/json2msgpack | ./bin/msgpack2json 124 | [1,2,3] 125 | 126 | ### Building, Installation, Testing 127 | 128 | There are two ways to install msgpack. 129 | 130 | ## NPM 131 | 132 | npm install msgpack 133 | 134 | This should build and install msgpack for you. Then just `require('msgpack')`. 135 | 136 | ## Manually 137 | 138 | You will need node-gyp: 139 | 140 | npm install -g node-gyp 141 | 142 | Then from the root of the msgpack repo, you can run: 143 | 144 | node-gyp rebuild 145 | 146 |
147 |
NOTE:
148 |
149 | node-gyp attempts to contact the Internet and download the target version 150 | of node.js source and store it locally. This will only happen once for 151 | each time it sees a new node.js version. If you're on a host with no 152 | direct Internet access, you may need to shuffle this source over from 153 | another box or sneaker net. Good luck! 154 |
155 |
156 | 157 | ## Testing 158 | 159 | To run all tests use: 160 | 161 | ./run_tests 162 | 163 | To run a specific test: 164 | 165 | ./run_tests test/lib/msgpack.js 166 | 167 |
168 |
NOTE:
169 |
170 | Tests are based on a modified version of 171 | nodeunit (https://github.com/godsflaw/nodeunit). 172 | Follow ./run_tests instructions if you run into problems. 173 |
174 |
175 | 176 | ## Benchmarks 177 | 178 | To run benchmarks: 179 | 180 | ./run_tests test/benchmark/benchmark.js 181 | -------------------------------------------------------------------------------- /bin/json2msgpack: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Read JSON data from stdin and write MessagePack data to stdout. 3 | 4 | var msgpack = require('msgpack'); 5 | var net = require('net'); 6 | 7 | var data = ''; 8 | 9 | var s = new net.Stream(0); 10 | s.addListener('data', function(d) { 11 | data += d; 12 | }); 13 | s.addListener('end', function() { 14 | s = new net.Stream(1); 15 | s.resume(); 16 | 17 | if (s.write(msgpack.pack(JSON.parse(data)))) { 18 | process.exit(0); 19 | } else { 20 | s.addListener('drain', function() { 21 | process.exit(0); 22 | }); 23 | } 24 | }); 25 | s.resume(); 26 | 27 | // vim:ts=4 sw=4 et filetype=javascript 28 | -------------------------------------------------------------------------------- /bin/msgpack2json: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | // Read MessagePack data from stdin and write JSON data to stdout. 3 | 4 | var msgpack = require('msgpack'); 5 | var net = require('net'); 6 | var sys = require('sys'); 7 | 8 | var s = new net.Stream(0); 9 | s.addListener('data', function(b) { 10 | sys.puts(JSON.stringify(msgpack.unpack(b))); 11 | }); 12 | s.resume(); 13 | 14 | // vim:ts=4 sw=4 et filetype=javascript 15 | -------------------------------------------------------------------------------- /binding.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | 'target_name': 'msgpackBinding', 5 | 'sources': [ 6 | 'src/msgpack.cc', 7 | ], 8 | 'include_dirs': [ 9 | 'deps/msgpack', 10 | ' 2 | -------------------------------------------------------------------------------- /deps/msgpack/COPYING: -------------------------------------------------------------------------------- 1 | Copyright (C) 2008-2010 FURUHASHI Sadayuki 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | 15 | -------------------------------------------------------------------------------- /deps/msgpack/gcc_atomic.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ old gcc workaround for atomic operation 3 | // 4 | // Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | #ifndef MSGPACK_GCC_ATOMIC_HPP 20 | #define MSGPACK_GCC_ATOMIC_HPP 21 | 22 | #ifdef ENABLE_GCC_CXX_ATOMIC 23 | #if defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) 24 | 25 | #include "msgpack/gcc_atomic.h" 26 | #include 27 | 28 | int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr) 29 | { 30 | return __gnu_cxx::__exchange_and_add(ptr, -1) - 1; 31 | } 32 | 33 | int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr) 34 | { 35 | return __gnu_cxx::__exchange_and_add(ptr, 1) + 1; 36 | } 37 | 38 | #endif // old gcc workaround 39 | #endif // ENABLE_GCC_CXX_ATOMIC 40 | 41 | #endif /* gcc_atomic.hpp */ 42 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack.gyp: -------------------------------------------------------------------------------- 1 | { 2 | "targets": [ 3 | { 4 | 'target_name': 'libmsgpack', 5 | 'include_dirs': [ '.' ], 6 | 'type': 'static_library', 7 | 'sources': [ 8 | 'objectc.c', 9 | 'unpack.c', 10 | 'vrefbuffer.c', 11 | 'zone.c', 12 | 'version.c' 13 | ], 14 | 'cflags_cc': [ 15 | '-Wall', 16 | '-O3' 17 | ], 18 | 'cflags': [ 19 | '-Wall', 20 | '-O3' 21 | ], 22 | 'cflags!': [ 23 | '-fno-exceptions', 24 | '-Wno-unused-function' 25 | ], 26 | 'cflags_cc!': [ 27 | '-fno-exceptions', 28 | '-Wno-unused-function' 29 | ], 30 | 'conditions': [ 31 | ['OS=="mac"', { 32 | 'configurations': { 33 | 'Debug': { 34 | 'xcode_settings': { 35 | 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', 36 | 'WARNING_CFLAGS': ['-Wall', '-Wno-unused-function'], 37 | } 38 | }, 39 | 'Release': { 40 | 'xcode_settings': { 41 | 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES', 42 | 'WARNING_CFLAGS': ['-Wall', '-Wno-unused-function'], 43 | }, 44 | }, 45 | }, 46 | }], 47 | ['OS=="win"', { 48 | 'configurations': { 49 | 'Debug': { 50 | 'msvs_settings': { 51 | 'VCCLCompilerTool': { 52 | 'CompileAs': '2', 53 | 'ExceptionHandling': '1', 54 | }, 55 | }, 56 | }, 57 | 'Release': { 58 | 'msvs_settings': { 59 | 'VCCLCompilerTool': { 60 | 'CompileAs': '2', 61 | 'ExceptionHandling': '1', 62 | }, 63 | }, 64 | }, 65 | }, 66 | }] 67 | ] 68 | }, 69 | ] 70 | } 71 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | /** 19 | * @defgroup msgpack MessagePack C 20 | * @{ 21 | * @} 22 | */ 23 | 24 | #include "msgpack/util.h" 25 | #include "msgpack/object.h" 26 | #include "msgpack/zone.h" 27 | #include "msgpack/pack.h" 28 | #include "msgpack/unpack.h" 29 | #include "msgpack/sbuffer.h" 30 | #include "msgpack/vrefbuffer.h" 31 | #include "msgpack/version.h" 32 | 33 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #include "msgpack/object.hpp" 19 | #include "msgpack/iterator.hpp" 20 | #include "msgpack/zone.hpp" 21 | #include "msgpack/pack.hpp" 22 | #include "msgpack/unpack.hpp" 23 | #include "msgpack/sbuffer.hpp" 24 | #include "msgpack/vrefbuffer.hpp" 25 | #include "msgpack/version.hpp" 26 | #include "msgpack/type.hpp" 27 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/adaptor_base.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_ADAPTOR_BASE_HPP 19 | #define MSGPACK_ADAPTOR_BASE_HPP 20 | 21 | #include "msgpack/object_fwd.hpp" 22 | 23 | namespace msgpack { 24 | 25 | /// @cond 26 | MSGPACK_API_VERSION_NAMESPACE(v1) { 27 | /// @endcond 28 | 29 | template 30 | class packer; 31 | 32 | namespace adaptor { 33 | 34 | // Adaptor functors 35 | 36 | template 37 | struct convert { 38 | msgpack::object const& operator()(msgpack::object const& o, T& v) const; 39 | }; 40 | 41 | template 42 | struct pack { 43 | template 44 | msgpack::packer& operator()(msgpack::packer& o, T const& v) const; 45 | }; 46 | 47 | template 48 | struct object { 49 | void operator()(msgpack::object& o, T const& v) const; 50 | }; 51 | 52 | template 53 | struct object_with_zone { 54 | void operator()(msgpack::object::with_zone& o, T const& v) const; 55 | }; 56 | 57 | } // namespace adaptor 58 | 59 | // operators 60 | 61 | template 62 | inline 63 | msgpack::object const& operator>> (msgpack::object const& o, T& v) { 64 | return adaptor::convert()(o, v); 65 | } 66 | 67 | template 68 | inline 69 | msgpack::packer& operator<< (msgpack::packer& o, T const& v) { 70 | return adaptor::pack()(o, v); 71 | } 72 | 73 | template 74 | inline 75 | void operator<< (msgpack::object& o, T const& v) { 76 | adaptor::object()(o, v); 77 | } 78 | 79 | template 80 | inline 81 | void operator<< (msgpack::object::with_zone& o, T const& v) { 82 | adaptor::object_with_zone()(o, v); 83 | } 84 | 85 | /// @cond 86 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 87 | /// @endcond 88 | 89 | } // namespace msgpack 90 | 91 | 92 | #endif // MSGPACK_ADAPTOR_BASE_HPP 93 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/bool.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_BOOL_HPP 19 | #define MSGPACK_TYPE_BOOL_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | 24 | namespace msgpack { 25 | 26 | /// @cond 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | /// @endcond 29 | 30 | namespace adaptor { 31 | 32 | template <> 33 | struct convert { 34 | msgpack::object const& operator()(msgpack::object const& o, bool& v) const { 35 | if(o.type != msgpack::type::BOOLEAN) { throw msgpack::type_error(); } 36 | v = o.via.boolean; 37 | return o; 38 | } 39 | }; 40 | 41 | template <> 42 | struct pack { 43 | template 44 | msgpack::packer& operator()(msgpack::packer& o, const bool& v) const { 45 | if(v) { o.pack_true(); } 46 | else { o.pack_false(); } 47 | return o; 48 | } 49 | }; 50 | 51 | template <> 52 | struct object { 53 | void operator()(msgpack::object& o, bool v) const { 54 | o.type = msgpack::type::BOOLEAN; 55 | o.via.boolean = v; 56 | } 57 | }; 58 | 59 | template <> 60 | struct object_with_zone { 61 | void operator()(msgpack::object::with_zone& o, bool v) const { 62 | static_cast(o) << v; 63 | } 64 | }; 65 | 66 | } // namespace adaptor 67 | 68 | /// @cond 69 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 70 | /// @endcond 71 | 72 | } // namespace msgpack 73 | 74 | #endif // MSGPACK_TYPE_BOOL_HPP 75 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/char_ptr.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014-2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_CHAR_PTR_HPP 19 | #define MSGPACK_TYPE_CHAR_PTR_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template <> 36 | struct pack { 37 | template 38 | msgpack::packer& operator()(msgpack::packer& o, const char* v) const { 39 | uint32_t size = checked_get_container_size(std::strlen(v)); 40 | o.pack_str(size); 41 | o.pack_str_body(v, size); 42 | return o; 43 | } 44 | }; 45 | 46 | template <> 47 | struct object_with_zone { 48 | void operator()(msgpack::object::with_zone& o, const char* v) const { 49 | uint32_t size = checked_get_container_size(std::strlen(v)); 50 | o.type = msgpack::type::STR; 51 | char* ptr = static_cast(o.zone.allocate_align(size)); 52 | o.via.str.ptr = ptr; 53 | o.via.str.size = size; 54 | std::memcpy(ptr, v, size); 55 | } 56 | }; 57 | 58 | template <> 59 | struct object { 60 | void operator()(msgpack::object& o, const char* v) const { 61 | uint32_t size = checked_get_container_size(std::strlen(v)); 62 | o.type = msgpack::type::STR; 63 | o.via.str.ptr = v; 64 | o.via.str.size = size; 65 | } 66 | }; 67 | 68 | 69 | template <> 70 | struct pack { 71 | template 72 | packer& operator()(packer& o, char* v) const { 73 | return o << static_cast(v); 74 | } 75 | }; 76 | 77 | template <> 78 | struct object_with_zone { 79 | void operator()(msgpack::object::with_zone& o, char* v) const { 80 | o << static_cast(v); 81 | } 82 | }; 83 | 84 | template <> 85 | struct object { 86 | void operator()(msgpack::object& o, char* v) const { 87 | o << static_cast(v); 88 | } 89 | }; 90 | 91 | template 92 | struct pack { 93 | template 94 | msgpack::packer& operator()(msgpack::packer& o, const char* v) const { 95 | uint32_t size = checked_get_container_size(std::strlen(v)); 96 | o.pack_str(size); 97 | o.pack_str_body(v, size); 98 | return o; 99 | } 100 | }; 101 | 102 | template 103 | struct object_with_zone { 104 | void operator()(msgpack::object::with_zone& o, const char* v) const { 105 | uint32_t size = checked_get_container_size(std::strlen(v)); 106 | o.type = msgpack::type::STR; 107 | char* ptr = static_cast(o.zone.allocate_align(size)); 108 | o.via.str.ptr = ptr; 109 | o.via.str.size = size; 110 | std::memcpy(ptr, v, size); 111 | } 112 | }; 113 | 114 | template 115 | struct object { 116 | void operator()(msgpack::object& o, const char* v) const { 117 | uint32_t size = checked_get_container_size(std::strlen(v)); 118 | o.type = msgpack::type::STR; 119 | o.via.str.ptr = v; 120 | o.via.str.size = size; 121 | } 122 | }; 123 | 124 | template 125 | struct pack { 126 | template 127 | msgpack::packer& operator()(msgpack::packer& o, const char* v) const { 128 | uint32_t size = checked_get_container_size(std::strlen(v)); 129 | o.pack_str(size); 130 | o.pack_str_body(v, size); 131 | return o; 132 | } 133 | }; 134 | 135 | template 136 | struct object_with_zone { 137 | void operator()(msgpack::object::with_zone& o, const char* v) const { 138 | uint32_t size = checked_get_container_size(std::strlen(v)); 139 | o.type = msgpack::type::STR; 140 | char* ptr = static_cast(o.zone.allocate_align(size)); 141 | o.via.str.ptr = ptr; 142 | o.via.str.size = size; 143 | std::memcpy(ptr, v, size); 144 | } 145 | }; 146 | 147 | template 148 | struct object { 149 | void operator()(msgpack::object& o, const char* v) const { 150 | uint32_t size = checked_get_container_size(std::strlen(v)); 151 | o.type = msgpack::type::STR; 152 | o.via.str.ptr = v; 153 | o.via.str.size = size; 154 | } 155 | }; 156 | 157 | } // namespace adaptor 158 | 159 | /// @cond 160 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 161 | /// @endcond 162 | 163 | } // namespace msgpack 164 | 165 | #endif // MSGPACK_TYPE_CHAR_PTR_HPP 166 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/check_container_size.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_CHECK_CONTAINER_SIZE_HPP 19 | #define MSGPACK_CHECK_CONTAINER_SIZE_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include 23 | 24 | namespace msgpack { 25 | 26 | /// @cond 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | /// @endcond 29 | 30 | struct container_size_overflow : public std::runtime_error { 31 | explicit container_size_overflow(const std::string& msg) 32 | :std::runtime_error(msg) {} 33 | #if !defined(MSGPACK_USE_CPP03) 34 | explicit container_size_overflow(const char* msg): 35 | std::runtime_error(msg) {} 36 | #endif // !defined(MSGPACK_USE_CPP03) 37 | }; 38 | 39 | namespace detail { 40 | 41 | template 42 | inline void check_container_size(std::size_t size) { 43 | if (size > 0xffffffff) throw container_size_overflow("container size overflow"); 44 | } 45 | 46 | template <> 47 | inline void check_container_size<4>(std::size_t size) { 48 | } 49 | 50 | } // namespace detail 51 | 52 | template 53 | inline uint32_t checked_get_container_size(T size) { 54 | detail::check_container_size(size); 55 | return static_cast(size); 56 | } 57 | 58 | 59 | /// @cond 60 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 61 | /// @endcond 62 | 63 | } // namespace msgpack 64 | 65 | #endif // MSGPACK_CHECK_CONTAINER_SIZE_HPP 66 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/cpp11/array.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014-2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | #ifndef MSGPACK_CPP11_ARRAY_HPP 20 | #define MSGPACK_CPP11_ARRAY_HPP 21 | 22 | #include "msgpack/versioning.hpp" 23 | #include "msgpack/adaptor/adaptor_base.hpp" 24 | #include "msgpack/adaptor/check_container_size.hpp" 25 | 26 | #include 27 | 28 | namespace msgpack { 29 | 30 | /// @cond 31 | MSGPACK_API_VERSION_NAMESPACE(v1) { 32 | /// @endcond 33 | 34 | namespace adaptor { 35 | 36 | template 37 | struct convert> { 38 | msgpack::object const& operator()(msgpack::object const& o, std::array& v) const { 39 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 40 | if(o.via.array.size != N) { throw msgpack::type_error(); } 41 | if(o.via.array.size > 0) { 42 | msgpack::object* p = o.via.array.ptr; 43 | msgpack::object* const pend = o.via.array.ptr + o.via.array.size; 44 | T* it = &v[0]; 45 | do { 46 | p->convert(*it); 47 | ++p; 48 | ++it; 49 | } while(p < pend); 50 | } 51 | return o; 52 | } 53 | }; 54 | 55 | template 56 | struct pack> { 57 | template 58 | msgpack::packer& operator()(msgpack::packer& o, const std::array& v) const { 59 | uint32_t size = checked_get_container_size(v.size()); 60 | o.pack_array(size); 61 | for(auto const& e : v) o.pack(e); 62 | return o; 63 | } 64 | }; 65 | 66 | template 67 | struct object_with_zone> { 68 | void operator()(msgpack::object::with_zone& o, const std::array& v) const { 69 | o.type = msgpack::type::ARRAY; 70 | if(v.empty()) { 71 | o.via.array.ptr = nullptr; 72 | o.via.array.size = 0; 73 | } else { 74 | uint32_t size = checked_get_container_size(v.size()); 75 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 76 | o.via.array.size = size; 77 | o.via.array.ptr = p; 78 | for (auto const& e : v) *p++ = msgpack::object(e, o.zone); 79 | } 80 | } 81 | }; 82 | 83 | } // namespace adaptor 84 | 85 | /// @cond 86 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 87 | /// @endcond 88 | 89 | } // namespace msgpack 90 | 91 | #endif // MSGPACK_CPP11_ARRAY_HPP 92 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/cpp11/array_char.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014-2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_ARRAY_CHAR_HPP 19 | #define MSGPACK_TYPE_ARRAY_CHAR_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template 36 | struct convert> { 37 | msgpack::object const& operator()(msgpack::object const& o, std::array& v) const { 38 | switch (o.type) { 39 | case msgpack::type::BIN: 40 | if(o.via.bin.size != N) { throw msgpack::type_error(); } 41 | std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size); 42 | break; 43 | case msgpack::type::STR: 44 | if(o.via.str.size != N) { throw msgpack::type_error(); } 45 | std::memcpy(v.data(), o.via.str.ptr, N); 46 | break; 47 | default: 48 | throw msgpack::type_error(); 49 | break; 50 | } 51 | return o; 52 | } 53 | }; 54 | 55 | template 56 | struct pack> { 57 | template 58 | msgpack::packer& operator()(msgpack::packer& o, const std::array& v) const { 59 | uint32_t size = checked_get_container_size(v.size()); 60 | o.pack_bin(size); 61 | o.pack_bin_body(v.data(), size); 62 | 63 | return o; 64 | } 65 | }; 66 | 67 | template 68 | struct object> { 69 | void operator()(msgpack::object& o, const std::array& v) const { 70 | uint32_t size = checked_get_container_size(v.size()); 71 | o.type = msgpack::type::BIN; 72 | o.via.bin.ptr = v.data(); 73 | o.via.bin.size = size; 74 | } 75 | }; 76 | 77 | template 78 | struct object_with_zone> { 79 | void operator()(msgpack::object::with_zone& o, const std::array& v) const { 80 | uint32_t size = checked_get_container_size(v.size()); 81 | o.type = msgpack::type::BIN; 82 | char* ptr = static_cast(o.zone.allocate_align(size)); 83 | o.via.bin.ptr = ptr; 84 | o.via.bin.size = size; 85 | std::memcpy(ptr, v.data(), size); 86 | } 87 | }; 88 | 89 | } // namespace adaptor 90 | 91 | /// @cond 92 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 93 | /// @endcond 94 | 95 | } // namespace msgpack 96 | 97 | #endif // MSGPACK_TYPE_ARRAY_CHAR_HPP 98 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/cpp11/forward_list.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014 KONDO-2015 Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | #ifndef MSGPACK_CPP11_FORWARD_LIST_HPP 20 | #define MSGPACK_CPP11_FORWARD_LIST_HPP 21 | 22 | #include "msgpack/versioning.hpp" 23 | #include "msgpack/adaptor/adaptor_base.hpp" 24 | #include "msgpack/adaptor/check_container_size.hpp" 25 | 26 | #include 27 | 28 | namespace msgpack { 29 | 30 | /// @cond 31 | MSGPACK_API_VERSION_NAMESPACE(v1) { 32 | /// @endcond 33 | 34 | namespace adaptor { 35 | 36 | template 37 | struct convert> { 38 | msgpack::object const& operator()(msgpack::object const& o, std::forward_list& v) const { 39 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 40 | v.resize(o.via.array.size); 41 | msgpack::object* p = o.via.array.ptr; 42 | for (auto &e : v) { 43 | p->convert(e); 44 | ++p; 45 | } 46 | return o; 47 | } 48 | }; 49 | 50 | template 51 | struct pack> { 52 | template 53 | msgpack::packer& operator()(msgpack::packer& o, const std::forward_list& v) const { 54 | uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end())); 55 | o.pack_array(size); 56 | for(auto const& e : v) o.pack(e); 57 | return o; 58 | } 59 | }; 60 | 61 | template 62 | struct object_with_zone> { 63 | void operator()(msgpack::object::with_zone& o, const std::forward_list& v) const { 64 | o.type = msgpack::type::ARRAY; 65 | if(v.empty()) { 66 | o.via.array.ptr = nullptr; 67 | o.via.array.size = 0; 68 | } else { 69 | uint32_t size = checked_get_container_size(std::distance(v.begin(), v.end())); 70 | o.via.array.size = size; 71 | msgpack::object* p = static_cast( 72 | o.zone.allocate_align(sizeof(msgpack::object)*size)); 73 | o.via.array.ptr = p; 74 | for(auto const& e : v) *p++ = msgpack::object(e, o.zone); 75 | } 76 | } 77 | }; 78 | 79 | } // namespace adaptor 80 | 81 | /// @cond 82 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 83 | /// @endcond 84 | 85 | } // namespace msgpack 86 | 87 | #endif // MSGPACK_CPP11_FORWARD_LIST_HPP 88 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/cpp11/tuple.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2015 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_CPP11_TUPLE_HPP 19 | #define MSGPACK_CPP11_TUPLE_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | // --- Pack from tuple to packer stream --- 34 | template 35 | struct StdTuplePacker { 36 | static void pack( 37 | msgpack::packer& o, 38 | const Tuple& v) { 39 | StdTuplePacker::pack(o, v); 40 | o.pack(std::get(v)); 41 | } 42 | }; 43 | 44 | template 45 | struct StdTuplePacker { 46 | static void pack ( 47 | msgpack::packer& o, 48 | const Tuple& v) { 49 | o.pack(std::get<0>(v)); 50 | } 51 | }; 52 | 53 | template 54 | struct StdTuplePacker { 55 | static void pack ( 56 | msgpack::packer&, 57 | const Tuple&) { 58 | } 59 | }; 60 | 61 | namespace adaptor { 62 | 63 | template 64 | struct pack> { 65 | template 66 | msgpack::packer& operator()( 67 | msgpack::packer& o, 68 | const std::tuple& v) const { 69 | uint32_t size = checked_get_container_size(sizeof...(Args)); 70 | o.pack_array(size); 71 | StdTuplePacker::pack(o, v); 72 | return o; 73 | } 74 | }; 75 | 76 | } // namespace adaptor 77 | 78 | // --- Convert from tuple to object --- 79 | 80 | template 81 | struct StdTupleConverter { 82 | static void convert( 83 | msgpack::object const& o, 84 | Tuple& v) { 85 | StdTupleConverter::convert(o, v); 86 | o.via.array.ptr[N-1].convert(v))>::type>(std::get(v)); 87 | } 88 | }; 89 | 90 | template 91 | struct StdTupleConverter { 92 | static void convert ( 93 | msgpack::object const& o, 94 | Tuple& v) { 95 | o.via.array.ptr[0].convert(v))>::type>(std::get<0>(v)); 96 | } 97 | }; 98 | 99 | template 100 | struct StdTupleConverter { 101 | static void convert ( 102 | msgpack::object const&, 103 | Tuple&) { 104 | } 105 | }; 106 | 107 | namespace adaptor { 108 | 109 | template 110 | struct convert> { 111 | msgpack::object const& operator()( 112 | msgpack::object const& o, 113 | std::tuple& v) const { 114 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 115 | if(o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); } 116 | StdTupleConverter::convert(o, v); 117 | return o; 118 | } 119 | }; 120 | 121 | } // namespace adaptor 122 | 123 | // --- Convert from tuple to object with zone --- 124 | template 125 | struct StdTupleToObjectWithZone { 126 | static void convert( 127 | msgpack::object::with_zone& o, 128 | const Tuple& v) { 129 | StdTupleToObjectWithZone::convert(o, v); 130 | o.via.array.ptr[N-1] = msgpack::object(std::get(v), o.zone); 131 | } 132 | }; 133 | 134 | template 135 | struct StdTupleToObjectWithZone { 136 | static void convert ( 137 | msgpack::object::with_zone& o, 138 | const Tuple& v) { 139 | o.via.array.ptr[0] = msgpack::object(std::get<0>(v), o.zone); 140 | } 141 | }; 142 | 143 | template 144 | struct StdTupleToObjectWithZone { 145 | static void convert ( 146 | msgpack::object::with_zone&, 147 | const Tuple&) { 148 | } 149 | }; 150 | 151 | namespace adaptor { 152 | 153 | template 154 | struct object_with_zone> { 155 | void operator()( 156 | msgpack::object::with_zone& o, 157 | std::tuple const& v) const { 158 | uint32_t size = checked_get_container_size(sizeof...(Args)); 159 | o.type = msgpack::type::ARRAY; 160 | o.via.array.ptr = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 161 | o.via.array.size = size; 162 | StdTupleToObjectWithZone::convert(o, v); 163 | } 164 | }; 165 | 166 | } // namespace adaptor 167 | 168 | /// @cond 169 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 170 | /// @endcond 171 | 172 | } // namespace msgpack 173 | 174 | #endif // MSGPACK_CPP11_TUPLE_HPP 175 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/cpp11/unordered_map.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014-2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_UNORDERED_MAP_HPP 19 | #define MSGPACK_TYPE_UNORDERED_MAP_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template 36 | struct convert> { 37 | msgpack::object const& operator()(msgpack::object const& o, std::unordered_map& v) const { 38 | if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); } 39 | msgpack::object_kv* p(o.via.map.ptr); 40 | msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size); 41 | std::unordered_map tmp; 42 | for(; p != pend; ++p) { 43 | K key; 44 | p->key.convert(key); 45 | p->val.convert(tmp[key]); 46 | } 47 | tmp.swap(v); 48 | return o; 49 | } 50 | }; 51 | 52 | template 53 | struct pack> { 54 | template 55 | msgpack::packer& operator()(msgpack::packer& o, const std::unordered_map& v) const { 56 | uint32_t size = checked_get_container_size(v.size()); 57 | o.pack_map(size); 58 | for(typename std::unordered_map::const_iterator it(v.begin()), it_end(v.end()); 59 | it != it_end; ++it) { 60 | o.pack(it->first); 61 | o.pack(it->second); 62 | } 63 | return o; 64 | } 65 | }; 66 | 67 | template 68 | struct object_with_zone> { 69 | void operator()(msgpack::object::with_zone& o, const std::unordered_map& v) const { 70 | o.type = msgpack::type::MAP; 71 | if(v.empty()) { 72 | o.via.map.ptr = nullptr; 73 | o.via.map.size = 0; 74 | } else { 75 | uint32_t size = checked_get_container_size(v.size()); 76 | msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object_kv)*size)); 77 | msgpack::object_kv* const pend = p + size; 78 | o.via.map.ptr = p; 79 | o.via.map.size = size; 80 | typename std::unordered_map::const_iterator it(v.begin()); 81 | do { 82 | p->key = msgpack::object(it->first, o.zone); 83 | p->val = msgpack::object(it->second, o.zone); 84 | ++p; 85 | ++it; 86 | } while(p < pend); 87 | } 88 | } 89 | }; 90 | 91 | 92 | template 93 | struct convert> { 94 | msgpack::object const& operator()(msgpack::object const& o, std::unordered_multimap& v) const { 95 | if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); } 96 | msgpack::object_kv* p(o.via.map.ptr); 97 | msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size); 98 | std::unordered_multimap tmp; 99 | for(; p != pend; ++p) { 100 | std::pair value; 101 | p->key.convert(value.first); 102 | p->val.convert(value.second); 103 | tmp.insert(value); 104 | } 105 | tmp.swap(v); 106 | return o; 107 | } 108 | }; 109 | 110 | template 111 | struct pack> { 112 | template 113 | msgpack::packer& operator()(msgpack::packer& o, const std::unordered_multimap& v) const { 114 | uint32_t size = checked_get_container_size(v.size()); 115 | o.pack_map(size); 116 | for(typename std::unordered_multimap::const_iterator it(v.begin()), it_end(v.end()); 117 | it != it_end; ++it) { 118 | o.pack(it->first); 119 | o.pack(it->second); 120 | } 121 | return o; 122 | } 123 | }; 124 | 125 | template 126 | struct object_with_zone> { 127 | void operator()(msgpack::object::with_zone& o, const std::unordered_multimap& v) const { 128 | o.type = msgpack::type::MAP; 129 | if(v.empty()) { 130 | o.via.map.ptr = nullptr; 131 | o.via.map.size = 0; 132 | } else { 133 | uint32_t size = checked_get_container_size(v.size()); 134 | msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object_kv)*size)); 135 | msgpack::object_kv* const pend = p + size; 136 | o.via.map.ptr = p; 137 | o.via.map.size = size; 138 | typename std::unordered_multimap::const_iterator it(v.begin()); 139 | do { 140 | p->key = msgpack::object(it->first, o.zone); 141 | p->val = msgpack::object(it->second, o.zone); 142 | ++p; 143 | ++it; 144 | } while(p < pend); 145 | } 146 | } 147 | }; 148 | 149 | } // namespace adaptor 150 | 151 | /// @cond 152 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 153 | /// @endcond 154 | 155 | } // namespace msgpack 156 | 157 | 158 | #endif // MSGPACK_TYPE_UNORDERED_MAP_HPP 159 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/cpp11/unordered_set.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014-2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_UNORDERED_SET_HPP 19 | #define MSGPACK_TYPE_UNORDERED_SET_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template 36 | struct convert> { 37 | msgpack::object const& operator()(msgpack::object const& o, std::unordered_set& v) const { 38 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 39 | msgpack::object* p = o.via.array.ptr + o.via.array.size; 40 | msgpack::object* const pbegin = o.via.array.ptr; 41 | std::unordered_set tmp; 42 | while(p > pbegin) { 43 | --p; 44 | tmp.insert(p->as()); 45 | } 46 | tmp.swap(v); 47 | return o; 48 | } 49 | }; 50 | 51 | template 52 | struct pack> { 53 | template 54 | msgpack::packer& operator()(msgpack::packer& o, const std::unordered_set& v) const { 55 | uint32_t size = checked_get_container_size(v.size()); 56 | o.pack_array(size); 57 | for(typename std::unordered_set::const_iterator it(v.begin()), it_end(v.end()); 58 | it != it_end; ++it) { 59 | o.pack(*it); 60 | } 61 | return o; 62 | } 63 | }; 64 | 65 | template 66 | struct object_with_zone> { 67 | void operator()(msgpack::object::with_zone& o, const std::unordered_set& v) const { 68 | o.type = msgpack::type::ARRAY; 69 | if(v.empty()) { 70 | o.via.array.ptr = nullptr; 71 | o.via.array.size = 0; 72 | } else { 73 | uint32_t size = checked_get_container_size(v.size()); 74 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 75 | msgpack::object* const pend = p + size; 76 | o.via.array.ptr = p; 77 | o.via.array.size = size; 78 | typename std::unordered_set::const_iterator it(v.begin()); 79 | do { 80 | *p = msgpack::object(*it, o.zone); 81 | ++p; 82 | ++it; 83 | } while(p < pend); 84 | } 85 | } 86 | }; 87 | 88 | 89 | template 90 | struct convert> { 91 | msgpack::object const& operator()(msgpack::object const& o, std::unordered_multiset& v) const { 92 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 93 | msgpack::object* p = o.via.array.ptr + o.via.array.size; 94 | msgpack::object* const pbegin = o.via.array.ptr; 95 | std::unordered_multiset tmp; 96 | while(p > pbegin) { 97 | --p; 98 | tmp.insert(p->as()); 99 | } 100 | tmp.swap(v); 101 | return o; 102 | } 103 | }; 104 | 105 | template 106 | struct pack> { 107 | template 108 | msgpack::packer& operator()(msgpack::packer& o, const std::unordered_multiset& v) const { 109 | uint32_t size = checked_get_container_size(v.size()); 110 | o.pack_array(size); 111 | for(typename std::unordered_multiset::const_iterator it(v.begin()), it_end(v.end()); 112 | it != it_end; ++it) { 113 | o.pack(*it); 114 | } 115 | return o; 116 | } 117 | }; 118 | 119 | template 120 | struct object_with_zone> { 121 | void operator()(msgpack::object::with_zone& o, const std::unordered_multiset& v) const { 122 | o.type = msgpack::type::ARRAY; 123 | if(v.empty()) { 124 | o.via.array.ptr = nullptr; 125 | o.via.array.size = 0; 126 | } else { 127 | uint32_t size = checked_get_container_size(v.size()); 128 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 129 | msgpack::object* const pend = p + size; 130 | o.via.array.ptr = p; 131 | o.via.array.size = size; 132 | typename std::unordered_multiset::const_iterator it(v.begin()); 133 | do { 134 | *p = msgpack::object(*it, o.zone); 135 | ++p; 136 | ++it; 137 | } while(p < pend); 138 | } 139 | } 140 | }; 141 | 142 | } // namespace adaptor 143 | 144 | /// @cond 145 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 146 | /// @endcond 147 | 148 | } // namespace msgpack 149 | 150 | #endif // MSGPACK_TYPE_UNORDERED_SET_HPP 151 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/define.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_DEFINE_HPP 19 | #define MSGPACK_DEFINE_HPP 20 | 21 | #include "msgpack/cpp_config.hpp" 22 | 23 | #if defined(MSGPACK_USE_CPP03) 24 | #include "detail/cpp03_define.hpp" 25 | #else // MSGPACK_USE_CPP03 26 | #include "detail/cpp11_define.hpp" 27 | #endif // MSGPACK_USE_CPP03 28 | 29 | #endif // MSGPACK_DEFINE_HPP 30 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/deque.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2015 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_DEQUE_HPP 19 | #define MSGPACK_TYPE_DEQUE_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template 36 | struct convert > { 37 | msgpack::object const& operator()(msgpack::object const& o, std::deque& v) const { 38 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 39 | v.resize(o.via.array.size); 40 | msgpack::object* p = o.via.array.ptr; 41 | msgpack::object* const pend = o.via.array.ptr + o.via.array.size; 42 | typename std::deque::iterator it = v.begin(); 43 | for(; p < pend; ++p, ++it) { 44 | p->convert(*it); 45 | } 46 | return o; 47 | } 48 | }; 49 | 50 | template 51 | struct pack > { 52 | template 53 | msgpack::packer& operator()(msgpack::packer& o, const std::deque& v) const { 54 | uint32_t size = checked_get_container_size(v.size()); 55 | o.pack_array(size); 56 | for(typename std::deque::const_iterator it(v.begin()), it_end(v.end()); 57 | it != it_end; ++it) { 58 | o.pack(*it); 59 | } 60 | return o; 61 | } 62 | }; 63 | 64 | template 65 | struct object_with_zone > { 66 | void operator()(msgpack::object::with_zone& o, const std::deque& v) const { 67 | o.type = msgpack::type::ARRAY; 68 | if(v.empty()) { 69 | o.via.array.ptr = nullptr; 70 | o.via.array.size = 0; 71 | } else { 72 | uint32_t size = checked_get_container_size(v.size()); 73 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 74 | msgpack::object* const pend = p + size; 75 | o.via.array.ptr = p; 76 | o.via.array.size = size; 77 | typename std::deque::const_iterator it(v.begin()); 78 | do { 79 | *p = msgpack::object(*it, o.zone); 80 | ++p; 81 | ++it; 82 | } while(p < pend); 83 | } 84 | } 85 | }; 86 | 87 | } // namespace adaptor 88 | 89 | /// @cond 90 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 91 | /// @endcond 92 | 93 | } // namespace msgpack 94 | 95 | #endif /* msgpack/type/deque.hpp */ 96 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/detail/cpp11_define.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_CPP11_DEFINE_HPP 19 | #define MSGPACK_CPP11_DEFINE_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | 24 | // for MSGPACK_ADD_ENUM 25 | #include "msgpack/adaptor/int.hpp" 26 | 27 | #include 28 | #include 29 | 30 | #define MSGPACK_DEFINE(...) \ 31 | template \ 32 | void msgpack_pack(Packer& pk) const \ 33 | { \ 34 | msgpack::type::make_define(__VA_ARGS__).msgpack_pack(pk); \ 35 | } \ 36 | void msgpack_unpack(msgpack::object const& o) \ 37 | { \ 38 | msgpack::type::make_define(__VA_ARGS__).msgpack_unpack(o); \ 39 | }\ 40 | template \ 41 | void msgpack_object(MSGPACK_OBJECT* o, msgpack::zone& z) const \ 42 | { \ 43 | msgpack::type::make_define(__VA_ARGS__).msgpack_object(o, z); \ 44 | } 45 | 46 | // MSGPACK_ADD_ENUM must be used in the global namespace. 47 | #define MSGPACK_ADD_ENUM(enum_name) \ 48 | namespace msgpack { \ 49 | /** @cond */ \ 50 | MSGPACK_API_VERSION_NAMESPACE(v1) { \ 51 | /** @endcond */ \ 52 | namespace adaptor { \ 53 | template<> \ 54 | struct convert { \ 55 | msgpack::object const& operator()(msgpack::object const& o, enum_name& v) const { \ 56 | std::underlying_type::type tmp; \ 57 | o >> tmp; \ 58 | v = static_cast(tmp); \ 59 | return o; \ 60 | } \ 61 | }; \ 62 | template<> \ 63 | struct object { \ 64 | void operator()(msgpack::object& o, const enum_name& v) const { \ 65 | auto tmp = static_cast::type>(v); \ 66 | o << tmp; \ 67 | } \ 68 | }; \ 69 | template<> \ 70 | struct object_with_zone { \ 71 | void operator()(msgpack::object::with_zone& o, const enum_name& v) const { \ 72 | auto tmp = static_cast::type>(v); \ 73 | o << tmp; \ 74 | } \ 75 | }; \ 76 | template <> \ 77 | struct pack { \ 78 | template \ 79 | msgpack::packer& operator()(msgpack::packer& o, const enum_name& v) const { \ 80 | return o << static_cast::type>(v); \ 81 | } \ 82 | }; \ 83 | } \ 84 | /** @cond */ \ 85 | } \ 86 | /** @endcond */ \ 87 | } 88 | 89 | namespace msgpack { 90 | /// @cond 91 | MSGPACK_API_VERSION_NAMESPACE(v1) { 92 | /// @endcond 93 | namespace type { 94 | 95 | template 96 | struct define_imp { 97 | template 98 | static void pack(Packer& pk, Tuple const& t) { 99 | define_imp::pack(pk, t); 100 | pk.pack(std::get(t)); 101 | } 102 | static void unpack(msgpack::object const& o, Tuple& t) { 103 | define_imp::unpack(o, t); 104 | const size_t size = o.via.array.size; 105 | if(size <= N-1) { return; } 106 | o.via.array.ptr[N-1].convert(std::get(t)); 107 | } 108 | static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) { 109 | define_imp::object(o, z, t); 110 | o->via.array.ptr[N-1] = msgpack::object(std::get(t), z); 111 | } 112 | }; 113 | 114 | template 115 | struct define_imp { 116 | template 117 | static void pack(Packer& pk, Tuple const& t) { 118 | pk.pack(std::get<0>(t)); 119 | } 120 | static void unpack(msgpack::object const& o, Tuple& t) { 121 | const size_t size = o.via.array.size; 122 | if(size <= 0) { return; } 123 | o.via.array.ptr[0].convert(std::get<0>(t)); 124 | } 125 | static void object(msgpack::object* o, msgpack::zone& z, Tuple const& t) { 126 | o->via.array.ptr[0] = msgpack::object(std::get<0>(t), z); 127 | } 128 | }; 129 | 130 | template 131 | struct define { 132 | typedef define value_type; 133 | typedef std::tuple tuple_type; 134 | define(Args&... args) : 135 | a(args...) {} 136 | template 137 | void msgpack_pack(Packer& pk) const 138 | { 139 | pk.pack_array(sizeof...(Args)); 140 | 141 | define_imp, sizeof...(Args)>::pack(pk, a); 142 | } 143 | void msgpack_unpack(msgpack::object const& o) 144 | { 145 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 146 | 147 | define_imp, sizeof...(Args)>::unpack(o, a); 148 | } 149 | void msgpack_object(msgpack::object* o, msgpack::zone& z) const 150 | { 151 | o->type = msgpack::type::ARRAY; 152 | o->via.array.ptr = static_cast(z.allocate_align(sizeof(msgpack::object)*sizeof...(Args))); 153 | o->via.array.size = sizeof...(Args); 154 | 155 | define_imp, sizeof...(Args)>::object(o, z, a); 156 | } 157 | 158 | std::tuple a; 159 | }; 160 | 161 | template <> 162 | struct define<> { 163 | typedef define<> value_type; 164 | typedef std::tuple<> tuple_type; 165 | template 166 | void msgpack_pack(Packer& pk) const 167 | { 168 | pk.pack_array(0); 169 | } 170 | void msgpack_unpack(msgpack::object const& o) 171 | { 172 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 173 | } 174 | void msgpack_object(msgpack::object* o, msgpack::zone&) const 175 | { 176 | o->type = msgpack::type::ARRAY; 177 | o->via.array.ptr = NULL; 178 | o->via.array.size = 0; 179 | } 180 | }; 181 | 182 | inline define<> make_define() 183 | { 184 | return define<>(); 185 | } 186 | 187 | template 188 | define make_define(Args&... args) 189 | { 190 | return define(args...); 191 | } 192 | 193 | } // namespace type 194 | /// @cond 195 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 196 | /// @endcond 197 | } // namespace msgpack 198 | 199 | #endif // MSGPACK_CPP11_DEFINE_HPP 200 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/float.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_FLOAT_HPP 19 | #define MSGPACK_TYPE_FLOAT_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | /// @cond 28 | MSGPACK_API_VERSION_NAMESPACE(v1) { 29 | /// @endcond 30 | 31 | // FIXME check overflow, underflow 32 | 33 | namespace adaptor { 34 | 35 | template <> 36 | struct convert { 37 | msgpack::object const& operator()(msgpack::object const& o, float& v) const { 38 | if(o.type == msgpack::type::FLOAT) { 39 | v = static_cast(o.via.f64); 40 | } 41 | else if (o.type == msgpack::type::POSITIVE_INTEGER) { 42 | v = static_cast(o.via.u64); 43 | } 44 | else if (o.type == msgpack::type::NEGATIVE_INTEGER) { 45 | v = static_cast(o.via.i64); 46 | } 47 | else { 48 | throw msgpack::type_error(); 49 | } 50 | return o; 51 | } 52 | }; 53 | 54 | template <> 55 | struct pack { 56 | template 57 | msgpack::packer& operator()(msgpack::packer& o, const float& v) const { 58 | o.pack_float(v); 59 | return o; 60 | } 61 | }; 62 | 63 | 64 | template <> 65 | struct convert { 66 | msgpack::object const& operator()(msgpack::object const& o, double& v) const { 67 | if(o.type == msgpack::type::FLOAT) { 68 | v = o.via.f64; 69 | } 70 | else if (o.type == msgpack::type::POSITIVE_INTEGER) { 71 | v = static_cast(o.via.u64); 72 | } 73 | else if (o.type == msgpack::type::NEGATIVE_INTEGER) { 74 | v = static_cast(o.via.i64); 75 | } 76 | else { 77 | throw msgpack::type_error(); 78 | } 79 | return o; 80 | } 81 | }; 82 | 83 | template <> 84 | struct pack { 85 | template 86 | msgpack::packer& operator()(msgpack::packer& o, const double& v) const { 87 | o.pack_double(v); 88 | return o; 89 | } 90 | }; 91 | 92 | 93 | template <> 94 | struct object { 95 | void operator()(msgpack::object& o, float v) const { 96 | o.type = msgpack::type::FLOAT; 97 | o.via.f64 = static_cast(v); 98 | } 99 | }; 100 | 101 | template <> 102 | struct object { 103 | void operator()(msgpack::object& o, double v) const { 104 | o.type = msgpack::type::FLOAT; 105 | o.via.f64 = v; 106 | } 107 | }; 108 | 109 | template <> 110 | struct object_with_zone { 111 | void operator()(msgpack::object::with_zone& o, float v) const { 112 | static_cast(o) << v; 113 | } 114 | }; 115 | 116 | template <> 117 | struct object_with_zone { 118 | void operator()(msgpack::object::with_zone& o, double v) const { 119 | static_cast(o) << v; 120 | } 121 | }; 122 | 123 | } // namespace adaptor 124 | 125 | /// @cond 126 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 127 | /// @endcond 128 | 129 | } // namespace msgpack 130 | 131 | #endif // MSGPACK_TYPE_FLOAT_HPP 132 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/list.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2015 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_LIST_HPP 19 | #define MSGPACK_TYPE_LIST_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template 36 | struct convert > { 37 | msgpack::object const& operator()(msgpack::object const& o, std::list& v) const { 38 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 39 | v.resize(o.via.array.size); 40 | msgpack::object* p = o.via.array.ptr; 41 | msgpack::object* const pend = o.via.array.ptr + o.via.array.size; 42 | typename std::list::iterator it = v.begin(); 43 | for(; p < pend; ++p, ++it) { 44 | p->convert(*it); 45 | } 46 | return o; 47 | } 48 | }; 49 | 50 | template 51 | struct pack > { 52 | template 53 | msgpack::packer& operator()(msgpack::packer& o, const std::list& v) const { 54 | uint32_t size = checked_get_container_size(v.size()); 55 | o.pack_array(size); 56 | for(typename std::list::const_iterator it(v.begin()), it_end(v.end()); 57 | it != it_end; ++it) { 58 | o.pack(*it); 59 | } 60 | return o; 61 | } 62 | }; 63 | 64 | template 65 | struct object_with_zone > { 66 | void operator()(msgpack::object::with_zone& o, const std::list& v) const { 67 | o.type = msgpack::type::ARRAY; 68 | if(v.empty()) { 69 | o.via.array.ptr = nullptr; 70 | o.via.array.size = 0; 71 | } else { 72 | uint32_t size = checked_get_container_size(v.size()); 73 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 74 | msgpack::object* const pend = p + size; 75 | o.via.array.ptr = p; 76 | o.via.array.size = size; 77 | typename std::list::const_iterator it(v.begin()); 78 | do { 79 | *p = msgpack::object(*it, o.zone); 80 | ++p; 81 | ++it; 82 | } while(p < pend); 83 | } 84 | } 85 | }; 86 | 87 | } // namespace adaptor 88 | 89 | /// @cond 90 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 91 | /// @endcond 92 | 93 | } // namespace msgpack 94 | 95 | #endif // MSGPACK_TYPE_LIST_HPP 96 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/msgpack_tuple.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_MSGPACK_TUPLE_HPP 19 | #define MSGPACK_MSGPACK_TUPLE_HPP 20 | 21 | #include "msgpack/cpp_config.hpp" 22 | 23 | #if defined(MSGPACK_USE_CPP03) 24 | #include "detail/cpp03_msgpack_tuple.hpp" 25 | #else // MSGPACK_USE_CPP03 26 | #include "detail/cpp11_msgpack_tuple.hpp" 27 | #endif // MSGPACK_USE_CPP03 28 | 29 | #endif // MSGPACK_MSGPACK_TUPLE_HPP 30 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/nil.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_NIL_HPP 19 | #define MSGPACK_TYPE_NIL_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | 24 | namespace msgpack { 25 | 26 | /// @cond 27 | MSGPACK_API_VERSION_NAMESPACE(v1) { 28 | /// @endcond 29 | 30 | namespace type { 31 | 32 | struct nil { }; 33 | 34 | } // namespace type 35 | 36 | namespace adaptor { 37 | 38 | template <> 39 | struct convert { 40 | msgpack::object const& operator()(msgpack::object const& o, type::nil&) const { 41 | if(o.type != msgpack::type::NIL) { throw msgpack::type_error(); } 42 | return o; 43 | } 44 | }; 45 | 46 | template <> 47 | struct pack { 48 | template 49 | msgpack::packer& operator()(msgpack::packer& o, const type::nil&) const { 50 | o.pack_nil(); 51 | return o; 52 | } 53 | }; 54 | 55 | template <> 56 | struct object { 57 | void operator()(msgpack::object& o, type::nil) const { 58 | o.type = msgpack::type::NIL; 59 | } 60 | }; 61 | 62 | template <> 63 | struct object_with_zone { 64 | void operator()(msgpack::object::with_zone& o, type::nil v) const { 65 | static_cast(o) << v; 66 | } 67 | }; 68 | 69 | } // namespace adaptror 70 | 71 | template <> 72 | inline void msgpack::object::as() const 73 | { 74 | msgpack::type::nil v; 75 | convert(v); 76 | } 77 | 78 | /// @cond 79 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 80 | /// @endcond 81 | 82 | } // namespace msgpack 83 | 84 | #endif // MSGPACK_TYPE_NIL_HPP 85 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/pair.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_PAIR_HPP 19 | #define MSGPACK_TYPE_PAIR_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | /// @cond 28 | MSGPACK_API_VERSION_NAMESPACE(v1) { 29 | /// @endcond 30 | 31 | namespace adaptor { 32 | 33 | template 34 | struct convert > { 35 | msgpack::object const& operator()(msgpack::object const& o, std::pair& v) const { 36 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 37 | if(o.via.array.size != 2) { throw msgpack::type_error(); } 38 | o.via.array.ptr[0].convert(v.first); 39 | o.via.array.ptr[1].convert(v.second); 40 | return o; 41 | } 42 | }; 43 | 44 | template 45 | struct pack > { 46 | template 47 | msgpack::packer& operator()(msgpack::packer& o, const std::pair& v) const { 48 | o.pack_array(2); 49 | o.pack(v.first); 50 | o.pack(v.second); 51 | return o; 52 | } 53 | }; 54 | 55 | template 56 | struct object_with_zone > { 57 | void operator()(msgpack::object::with_zone& o, const std::pair& v) const { 58 | o.type = msgpack::type::ARRAY; 59 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*2)); 60 | o.via.array.ptr = p; 61 | o.via.array.size = 2; 62 | p[0] = msgpack::object(v.first, o.zone); 63 | p[1] = msgpack::object(v.second, o.zone); 64 | } 65 | }; 66 | 67 | } // namespace adaptor 68 | 69 | /// @cond 70 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 71 | /// @endcond 72 | 73 | } // namespace msgpack 74 | 75 | #endif // MSGPACK_TYPE_PAIR_HPP 76 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/raw.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_RAW_HPP 19 | #define MSGPACK_TYPE_RAW_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include 24 | #include 25 | 26 | namespace msgpack { 27 | 28 | /// @cond 29 | MSGPACK_API_VERSION_NAMESPACE(v1) { 30 | /// @endcond 31 | 32 | namespace type { 33 | 34 | struct raw_ref { 35 | raw_ref() : size(0), ptr(nullptr) {} 36 | raw_ref(const char* p, uint32_t s) : size(s), ptr(p) {} 37 | 38 | uint32_t size; 39 | const char* ptr; 40 | 41 | std::string str() const { return std::string(ptr, size); } 42 | 43 | bool operator== (const raw_ref& x) const 44 | { 45 | return size == x.size && std::memcmp(ptr, x.ptr, size) == 0; 46 | } 47 | 48 | bool operator!= (const raw_ref& x) const 49 | { 50 | return !(*this != x); 51 | } 52 | 53 | bool operator< (const raw_ref& x) const 54 | { 55 | if(size == x.size) { return std::memcmp(ptr, x.ptr, size) < 0; } 56 | else { return size < x.size; } 57 | } 58 | 59 | bool operator> (const raw_ref& x) const 60 | { 61 | if(size == x.size) { return std::memcmp(ptr, x.ptr, size) > 0; } 62 | else { return size > x.size; } 63 | } 64 | }; 65 | 66 | } // namespace type 67 | 68 | namespace adaptor { 69 | 70 | template <> 71 | struct convert { 72 | msgpack::object const& operator()(msgpack::object const& o, msgpack::type::raw_ref& v) const { 73 | if(o.type != msgpack::type::BIN) { throw msgpack::type_error(); } 74 | v.ptr = o.via.bin.ptr; 75 | v.size = o.via.bin.size; 76 | return o; 77 | } 78 | }; 79 | 80 | template <> 81 | struct pack { 82 | template 83 | msgpack::packer& operator()(msgpack::packer& o, const msgpack::type::raw_ref& v) const { 84 | o.pack_bin(v.size); 85 | o.pack_bin_body(v.ptr, v.size); 86 | return o; 87 | } 88 | }; 89 | 90 | template <> 91 | struct object { 92 | void operator()(msgpack::object& o, const msgpack::type::raw_ref& v) const { 93 | o.type = msgpack::type::BIN; 94 | o.via.bin.ptr = v.ptr; 95 | o.via.bin.size = v.size; 96 | } 97 | }; 98 | 99 | template <> 100 | struct object_with_zone { 101 | void operator()(msgpack::object::with_zone& o, const msgpack::type::raw_ref& v) const { 102 | static_cast(o) << v; 103 | } 104 | }; 105 | 106 | } // namespace adaptor 107 | 108 | /// @cond 109 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 110 | /// @endcond 111 | 112 | } // namespace msgpack 113 | 114 | #endif // MSGPACK_TYPE_RAW_HPP 115 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/set.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2015 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_SET_HPP 19 | #define MSGPACK_TYPE_SET_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template 36 | struct convert > { 37 | msgpack::object const& operator()(msgpack::object const& o, std::set& v) const { 38 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 39 | msgpack::object* p = o.via.array.ptr + o.via.array.size; 40 | msgpack::object* const pbegin = o.via.array.ptr; 41 | std::set tmp; 42 | while(p > pbegin) { 43 | --p; 44 | tmp.insert(p->as()); 45 | } 46 | tmp.swap(v); 47 | return o; 48 | } 49 | }; 50 | 51 | template 52 | struct pack > { 53 | template 54 | msgpack::packer& operator()(msgpack::packer& o, const std::set& v) const { 55 | uint32_t size = checked_get_container_size(v.size()); 56 | o.pack_array(size); 57 | for(typename std::set::const_iterator it(v.begin()), it_end(v.end()); 58 | it != it_end; ++it) { 59 | o.pack(*it); 60 | } 61 | return o; 62 | } 63 | }; 64 | 65 | template 66 | struct object_with_zone > { 67 | void operator()(msgpack::object::with_zone& o, const std::set& v) const { 68 | o.type = msgpack::type::ARRAY; 69 | if(v.empty()) { 70 | o.via.array.ptr = nullptr; 71 | o.via.array.size = 0; 72 | } else { 73 | uint32_t size = checked_get_container_size(v.size()); 74 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 75 | msgpack::object* const pend = p + size; 76 | o.via.array.ptr = p; 77 | o.via.array.size = size; 78 | typename std::set::const_iterator it(v.begin()); 79 | do { 80 | *p = msgpack::object(*it, o.zone); 81 | ++p; 82 | ++it; 83 | } while(p < pend); 84 | } 85 | } 86 | }; 87 | 88 | template 89 | struct convert > { 90 | msgpack::object const& operator()(msgpack::object const& o, std::multiset& v) const { 91 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 92 | msgpack::object* p = o.via.array.ptr + o.via.array.size; 93 | msgpack::object* const pbegin = o.via.array.ptr; 94 | std::multiset tmp; 95 | while(p > pbegin) { 96 | --p; 97 | tmp.insert(p->as()); 98 | } 99 | tmp.swap(v); 100 | return o; 101 | } 102 | }; 103 | 104 | template 105 | struct pack > { 106 | template 107 | msgpack::packer& operator()(msgpack::packer& o, const std::multiset& v) const { 108 | uint32_t size = checked_get_container_size(v.size()); 109 | o.pack_array(size); 110 | for(typename std::multiset::const_iterator it(v.begin()), it_end(v.end()); 111 | it != it_end; ++it) { 112 | o.pack(*it); 113 | } 114 | return o; 115 | } 116 | }; 117 | 118 | template 119 | struct object_with_zone > { 120 | void operator()(msgpack::object::with_zone& o, const std::multiset& v) const { 121 | o.type = msgpack::type::ARRAY; 122 | if(v.empty()) { 123 | o.via.array.ptr = nullptr; 124 | o.via.array.size = 0; 125 | } else { 126 | uint32_t size = checked_get_container_size(v.size()); 127 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 128 | msgpack::object* const pend = p + size; 129 | o.via.array.ptr = p; 130 | o.via.array.size = size; 131 | typename std::multiset::const_iterator it(v.begin()); 132 | do { 133 | *p = msgpack::object(*it, o.zone); 134 | ++p; 135 | ++it; 136 | } while(p < pend); 137 | } 138 | } 139 | }; 140 | 141 | } // namespace adaptor 142 | 143 | /// @cond 144 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 145 | /// @endcond 146 | 147 | } // namespace msgpack 148 | 149 | #endif // MSGPACK_TYPE_SET_HPP 150 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/string.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2015 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_STRING_HPP 19 | #define MSGPACK_TYPE_STRING_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template <> 36 | struct convert { 37 | msgpack::object const& operator()(msgpack::object const& o, std::string& v) const { 38 | switch (o.type) { 39 | case msgpack::type::BIN: 40 | v.assign(o.via.bin.ptr, o.via.bin.size); 41 | break; 42 | case msgpack::type::STR: 43 | v.assign(o.via.str.ptr, o.via.str.size); 44 | break; 45 | default: 46 | throw msgpack::type_error(); 47 | break; 48 | } 49 | return o; 50 | } 51 | }; 52 | 53 | template <> 54 | struct pack { 55 | template 56 | msgpack::packer& operator()(msgpack::packer& o, const std::string& v) const { 57 | uint32_t size = checked_get_container_size(v.size()); 58 | o.pack_str(size); 59 | o.pack_str_body(v.data(), size); 60 | return o; 61 | } 62 | }; 63 | 64 | template <> 65 | struct object { 66 | void operator()(msgpack::object& o, const std::string& v) const { 67 | uint32_t size = checked_get_container_size(v.size()); 68 | o.type = msgpack::type::STR; 69 | o.via.str.ptr = v.data(); 70 | o.via.str.size = size; 71 | } 72 | }; 73 | 74 | template <> 75 | struct object_with_zone { 76 | void operator()(msgpack::object::with_zone& o, const std::string& v) const { 77 | uint32_t size = checked_get_container_size(v.size()); 78 | o.type = msgpack::type::STR; 79 | char* ptr = static_cast(o.zone.allocate_align(size)); 80 | o.via.str.ptr = ptr; 81 | o.via.str.size = size; 82 | std::memcpy(ptr, v.data(), v.size()); 83 | } 84 | }; 85 | 86 | } // namespace adaptor 87 | 88 | /// @cond 89 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 90 | /// @endcond 91 | 92 | } // namespace msgpack 93 | 94 | #endif // MSGPACK_TYPE_STRING_HPP 95 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/tr1/unordered_map.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2015 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP 19 | #define MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) 26 | 27 | #define MSGPACK_HAS_STD_UNORDERED_MAP 28 | #include 29 | #define MSGPACK_STD_TR1 std 30 | 31 | #else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) 32 | 33 | #if __GNUC__ >= 4 34 | 35 | #define MSGPACK_HAS_STD_TR1_UNORDERED_MAP 36 | 37 | #include 38 | #define MSGPACK_STD_TR1 std::tr1 39 | 40 | #endif // __GNUC__ >= 4 41 | 42 | #endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) 43 | 44 | #if defined(MSGPACK_STD_TR1) 45 | 46 | namespace msgpack { 47 | 48 | /// @cond 49 | MSGPACK_API_VERSION_NAMESPACE(v1) { 50 | /// @endcond 51 | 52 | namespace adaptor { 53 | 54 | template 55 | struct convert > { 56 | msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_map& v) const { 57 | if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); } 58 | msgpack::object_kv* p(o.via.map.ptr); 59 | msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size); 60 | MSGPACK_STD_TR1::unordered_map tmp; 61 | for(; p != pend; ++p) { 62 | K key; 63 | p->key.convert(key); 64 | p->val.convert(tmp[key]); 65 | } 66 | tmp.swap(v); 67 | return o; 68 | } 69 | }; 70 | 71 | template 72 | struct pack > { 73 | template 74 | msgpack::packer& operator()(msgpack::packer& o, const MSGPACK_STD_TR1::unordered_map& v) const { 75 | uint32_t size = checked_get_container_size(v.size()); 76 | o.pack_map(size); 77 | for(typename MSGPACK_STD_TR1::unordered_map::const_iterator it(v.begin()), it_end(v.end()); 78 | it != it_end; ++it) { 79 | o.pack(it->first); 80 | o.pack(it->second); 81 | } 82 | return o; 83 | } 84 | }; 85 | 86 | template 87 | struct object_with_zone > { 88 | void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_map& v) const { 89 | o.type = msgpack::type::MAP; 90 | if(v.empty()) { 91 | o.via.map.ptr = nullptr; 92 | o.via.map.size = 0; 93 | } else { 94 | uint32_t size = checked_get_container_size(v.size()); 95 | msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object_kv)*size)); 96 | msgpack::object_kv* const pend = p + size; 97 | o.via.map.ptr = p; 98 | o.via.map.size = size; 99 | typename MSGPACK_STD_TR1::unordered_map::const_iterator it(v.begin()); 100 | do { 101 | p->key = msgpack::object(it->first, o.zone); 102 | p->val = msgpack::object(it->second, o.zone); 103 | ++p; 104 | ++it; 105 | } while(p < pend); 106 | } 107 | } 108 | }; 109 | 110 | template 111 | struct convert > { 112 | msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multimap& v) const { 113 | if(o.type != msgpack::type::MAP) { throw msgpack::type_error(); } 114 | msgpack::object_kv* p(o.via.map.ptr); 115 | msgpack::object_kv* const pend(o.via.map.ptr + o.via.map.size); 116 | MSGPACK_STD_TR1::unordered_multimap tmp; 117 | for(; p != pend; ++p) { 118 | std::pair value; 119 | p->key.convert(value.first); 120 | p->val.convert(value.second); 121 | tmp.insert(value); 122 | } 123 | tmp.swap(v); 124 | return o; 125 | } 126 | }; 127 | 128 | template 129 | struct pack > { 130 | template 131 | msgpack::packer& operator()(msgpack::packer& o, const MSGPACK_STD_TR1::unordered_multimap& v) const { 132 | uint32_t size = checked_get_container_size(v.size()); 133 | o.pack_map(size); 134 | for(typename MSGPACK_STD_TR1::unordered_multimap::const_iterator it(v.begin()), it_end(v.end()); 135 | it != it_end; ++it) { 136 | o.pack(it->first); 137 | o.pack(it->second); 138 | } 139 | return o; 140 | } 141 | }; 142 | 143 | template 144 | struct object_with_zone > { 145 | void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multimap& v) const { 146 | o.type = msgpack::type::MAP; 147 | if(v.empty()) { 148 | o.via.map.ptr = nullptr; 149 | o.via.map.size = 0; 150 | } else { 151 | uint32_t size = checked_get_container_size(v.size()); 152 | msgpack::object_kv* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object_kv)*size)); 153 | msgpack::object_kv* const pend = p + size; 154 | o.via.map.ptr = p; 155 | o.via.map.size = size; 156 | typename MSGPACK_STD_TR1::unordered_multimap::const_iterator it(v.begin()); 157 | do { 158 | p->key = msgpack::object(it->first, o.zone); 159 | p->val = msgpack::object(it->second, o.zone); 160 | ++p; 161 | ++it; 162 | } while(p < pend); 163 | } 164 | } 165 | }; 166 | 167 | } // namespace adaptor 168 | 169 | /// @cond 170 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 171 | /// @endcond 172 | 173 | } // namespace msgpack 174 | 175 | #undef MSGPACK_STD_TR1 176 | 177 | #endif // MSGPACK_STD_TR1 178 | 179 | #endif // MSGPACK_TYPE_TR1_UNORDERED_MAP_HPP 180 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/tr1/unordered_set.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2015 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_TR1_UNORDERED_SET_HPP 19 | #define MSGPACK_TYPE_TR1_UNORDERED_SET_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #if defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) 26 | 27 | #define MSGPACK_HAS_STD_UNORDERED_SET 28 | #include 29 | #define MSGPACK_STD_TR1 std 30 | 31 | #else // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) 32 | 33 | #if __GNUC__ >= 4 34 | 35 | #define MSGPACK_HAS_STD_TR1_UNORDERED_SET 36 | 37 | #include 38 | #define MSGPACK_STD_TR1 std::tr1 39 | 40 | #endif // __GNUC__ >= 4 41 | 42 | #endif // defined(_LIBCPP_VERSION) || (_MSC_VER >= 1700) 43 | 44 | #if defined(MSGPACK_STD_TR1) 45 | 46 | namespace msgpack { 47 | 48 | /// @cond 49 | MSGPACK_API_VERSION_NAMESPACE(v1) { 50 | /// @endcond 51 | 52 | namespace adaptor { 53 | 54 | template 55 | struct convert > { 56 | msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_set& v) const { 57 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 58 | msgpack::object* p = o.via.array.ptr + o.via.array.size; 59 | msgpack::object* const pbegin = o.via.array.ptr; 60 | MSGPACK_STD_TR1::unordered_set tmp; 61 | while(p > pbegin) { 62 | --p; 63 | tmp.insert(p->as()); 64 | } 65 | tmp.swap(v); 66 | return o; 67 | } 68 | }; 69 | 70 | template 71 | struct pack > { 72 | template 73 | msgpack::packer& operator()(msgpack::packer& o, const MSGPACK_STD_TR1::unordered_set& v) const { 74 | uint32_t size = checked_get_container_size(v.size()); 75 | o.pack_array(size); 76 | for(typename MSGPACK_STD_TR1::unordered_set::const_iterator it(v.begin()), it_end(v.end()); 77 | it != it_end; ++it) { 78 | o.pack(*it); 79 | } 80 | return o; 81 | } 82 | }; 83 | 84 | template 85 | struct object_with_zone > { 86 | void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_set& v) const { 87 | o.type = msgpack::type::ARRAY; 88 | if(v.empty()) { 89 | o.via.array.ptr = nullptr; 90 | o.via.array.size = 0; 91 | } else { 92 | uint32_t size = checked_get_container_size(v.size()); 93 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 94 | msgpack::object* const pend = p + size; 95 | o.via.array.ptr = p; 96 | o.via.array.size = size; 97 | typename MSGPACK_STD_TR1::unordered_set::const_iterator it(v.begin()); 98 | do { 99 | *p = msgpack::object(*it, o.zone); 100 | ++p; 101 | ++it; 102 | } while(p < pend); 103 | } 104 | } 105 | }; 106 | 107 | 108 | template 109 | struct convert > { 110 | msgpack::object const& operator()(msgpack::object const& o, MSGPACK_STD_TR1::unordered_multiset& v) const { 111 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 112 | msgpack::object* p = o.via.array.ptr + o.via.array.size; 113 | msgpack::object* const pbegin = o.via.array.ptr; 114 | MSGPACK_STD_TR1::unordered_multiset tmp; 115 | while(p > pbegin) { 116 | --p; 117 | tmp.insert(p->as()); 118 | } 119 | tmp.swap(v); 120 | return o; 121 | } 122 | }; 123 | 124 | template 125 | struct pack > { 126 | template 127 | msgpack::packer& operator()(msgpack::packer& o, const MSGPACK_STD_TR1::unordered_multiset& v) const { 128 | uint32_t size = checked_get_container_size(v.size()); 129 | o.pack_array(size); 130 | for(typename MSGPACK_STD_TR1::unordered_multiset::const_iterator it(v.begin()), it_end(v.end()); 131 | it != it_end; ++it) { 132 | o.pack(*it); 133 | } 134 | return o; 135 | } 136 | }; 137 | 138 | template 139 | struct object_with_zone > { 140 | void operator()(msgpack::object::with_zone& o, const MSGPACK_STD_TR1::unordered_multiset& v) const { 141 | o.type = msgpack::type::ARRAY; 142 | if(v.empty()) { 143 | o.via.array.ptr = nullptr; 144 | o.via.array.size = 0; 145 | } else { 146 | uint32_t size = checked_get_container_size(v.size()); 147 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 148 | msgpack::object* const pend = p + size; 149 | o.via.array.ptr = p; 150 | o.via.array.size = size; 151 | typename MSGPACK_STD_TR1::unordered_multiset::const_iterator it(v.begin()); 152 | do { 153 | *p = msgpack::object(*it, o.zone); 154 | ++p; 155 | ++it; 156 | } while(p < pend); 157 | } 158 | } 159 | }; 160 | 161 | } // namespace adaptor 162 | 163 | /// @cond 164 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 165 | /// @endcond 166 | 167 | } // namespace msgpack 168 | 169 | #undef MSGPACK_STD_TR1 170 | 171 | #endif // MSGPACK_STD_TR1 172 | 173 | #endif // MSGPACK_TYPE_TR1_UNORDERED_SET_HPP 174 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/vector.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_VECTOR_HPP 19 | #define MSGPACK_TYPE_VECTOR_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template 36 | struct convert > { 37 | msgpack::object const& operator()(msgpack::object const& o, std::vector& v) const { 38 | if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 39 | v.resize(o.via.array.size); 40 | if(o.via.array.size > 0) { 41 | msgpack::object* p = o.via.array.ptr; 42 | msgpack::object* const pend = o.via.array.ptr + o.via.array.size; 43 | typename std::vector::iterator it = v.begin(); 44 | do { 45 | p->convert(*it); 46 | ++p; 47 | ++it; 48 | } while(p < pend); 49 | } 50 | return o; 51 | } 52 | }; 53 | 54 | template 55 | struct pack > { 56 | template 57 | msgpack::packer& operator()(msgpack::packer& o, const std::vector& v) const { 58 | uint32_t size = checked_get_container_size(v.size()); 59 | o.pack_array(size); 60 | for(typename std::vector::const_iterator it(v.begin()), it_end(v.end()); 61 | it != it_end; ++it) { 62 | o.pack(*it); 63 | } 64 | return o; 65 | } 66 | }; 67 | 68 | template 69 | struct object_with_zone > { 70 | void operator()(msgpack::object::with_zone& o, const std::vector& v) const { 71 | o.type = msgpack::type::ARRAY; 72 | if(v.empty()) { 73 | o.via.array.ptr = nullptr; 74 | o.via.array.size = 0; 75 | } else { 76 | uint32_t size = checked_get_container_size(v.size()); 77 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 78 | msgpack::object* const pend = p + size; 79 | o.via.array.ptr = p; 80 | o.via.array.size = size; 81 | typename std::vector::const_iterator it(v.begin()); 82 | do { 83 | *p = msgpack::object(*it, o.zone); 84 | ++p; 85 | ++it; 86 | } while(p < pend); 87 | } 88 | } 89 | }; 90 | 91 | } // namespace adaptor 92 | 93 | /// @cond 94 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 95 | /// @endcond 96 | 97 | } // namespace msgpack 98 | 99 | #endif // MSGPACK_TYPE_VECTOR_HPP 100 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/vector_bool.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_VECTOR_BOOL_HPP 19 | #define MSGPACK_TYPE_VECTOR_BOOL_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/object_fwd.hpp" 23 | #include 24 | 25 | namespace msgpack { 26 | 27 | /// @cond 28 | MSGPACK_API_VERSION_NAMESPACE(v1) { 29 | /// @endcond 30 | 31 | namespace adaptor { 32 | 33 | template <> 34 | struct convert > { 35 | msgpack::object const& operator()(msgpack::object const& o, std::vector& v) const { 36 | if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); } 37 | if (o.via.array.size > 0) { 38 | v.resize(o.via.array.size); 39 | msgpack::object* p = o.via.array.ptr; 40 | for (std::vector::iterator it = v.begin(), end = v.end(); 41 | it != end; 42 | ++it) { 43 | *it = p->as(); 44 | ++p; 45 | } 46 | } 47 | return o; 48 | } 49 | }; 50 | 51 | template <> 52 | struct pack > { 53 | template 54 | msgpack::packer& operator()(msgpack::packer& o, const std::vector& v) const { 55 | uint32_t size = checked_get_container_size(v.size()); 56 | o.pack_array(size); 57 | for(std::vector::const_iterator it(v.begin()), it_end(v.end()); 58 | it != it_end; ++it) { 59 | o.pack(static_cast(*it)); 60 | } 61 | return o; 62 | } 63 | }; 64 | 65 | template <> 66 | struct object_with_zone > { 67 | void operator()(msgpack::object::with_zone& o, const std::vector& v) const { 68 | o.type = msgpack::type::ARRAY; 69 | if(v.empty()) { 70 | o.via.array.ptr = nullptr; 71 | o.via.array.size = 0; 72 | } else { 73 | uint32_t size = checked_get_container_size(v.size()); 74 | msgpack::object* p = static_cast(o.zone.allocate_align(sizeof(msgpack::object)*size)); 75 | msgpack::object* const pend = p + size; 76 | o.via.array.ptr = p; 77 | o.via.array.size = size; 78 | std::vector::const_iterator it(v.begin()); 79 | do { 80 | *p = msgpack::object(static_cast(*it), o.zone); 81 | ++p; 82 | ++it; 83 | } while(p < pend); 84 | } 85 | } 86 | }; 87 | 88 | } // namespace adaptor 89 | 90 | /// @cond 91 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 92 | /// @endcond 93 | 94 | } // namespace msgpack 95 | 96 | #endif // MSGPACK_TYPE_VECTOR_BOOL_HPP 97 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/adaptor/vector_char.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2014-2015 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_TYPE_VECTOR_CHAR_HPP 19 | #define MSGPACK_TYPE_VECTOR_CHAR_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | #include "msgpack/adaptor/adaptor_base.hpp" 23 | #include "msgpack/adaptor/check_container_size.hpp" 24 | 25 | #include 26 | 27 | namespace msgpack { 28 | 29 | /// @cond 30 | MSGPACK_API_VERSION_NAMESPACE(v1) { 31 | /// @endcond 32 | 33 | namespace adaptor { 34 | 35 | template <> 36 | struct convert > { 37 | msgpack::object const& operator()(msgpack::object const& o, std::vector& v) const { 38 | switch (o.type) { 39 | case msgpack::type::BIN: 40 | v.resize(o.via.bin.size); 41 | std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size); 42 | break; 43 | case msgpack::type::STR: 44 | v.resize(o.via.str.size); 45 | std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size); 46 | break; 47 | default: 48 | throw msgpack::type_error(); 49 | break; 50 | } 51 | return o; 52 | } 53 | }; 54 | 55 | template <> 56 | struct pack > { 57 | template 58 | msgpack::packer& operator()(msgpack::packer& o, const std::vector& v) const { 59 | uint32_t size = checked_get_container_size(v.size()); 60 | o.pack_bin(size); 61 | o.pack_bin_body(&v.front(), size); 62 | 63 | return o; 64 | } 65 | }; 66 | 67 | template <> 68 | struct object > { 69 | void operator()(msgpack::object& o, const std::vector& v) const { 70 | uint32_t size = checked_get_container_size(v.size()); 71 | o.type = msgpack::type::BIN; 72 | o.via.bin.ptr = &v.front(); 73 | o.via.bin.size = size; 74 | } 75 | }; 76 | 77 | template <> 78 | struct object_with_zone > { 79 | void operator()(msgpack::object::with_zone& o, const std::vector& v) const { 80 | uint32_t size = checked_get_container_size(v.size()); 81 | o.type = msgpack::type::BIN; 82 | char* ptr = static_cast(o.zone.allocate_align(size)); 83 | o.via.bin.ptr = ptr; 84 | o.via.bin.size = size; 85 | std::memcpy(ptr, &v.front(), size); 86 | } 87 | }; 88 | 89 | } // namespace adaptor 90 | 91 | /// @cond 92 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 93 | /// @endcond 94 | 95 | } // namespace msgpack 96 | 97 | #endif // MSGPACK_TYPE_VECTOR_CHAR_HPP 98 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/cpp_config.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ C++03/C++11 Adaptation 3 | // 4 | // Copyright (C) 2013 KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_CPP_CONFIG_HPP 19 | #define MSGPACK_CPP_CONFIG_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | 23 | #if !defined(MSGPACK_USE_CPP03) 24 | // If MSVC would support C++11 completely, 25 | // then 'defined(_MSC_VER)' would replace with 26 | // '_MSC_VER < XXXX' 27 | # if (__cplusplus < 201103) || defined(_MSC_VER) 28 | # define MSGPACK_USE_CPP03 29 | # endif 30 | #endif // MSGPACK_USE_CPP03 31 | 32 | 33 | 34 | #if defined __cplusplus 35 | #if __cplusplus < 201103 36 | 37 | #if !defined(nullptr) 38 | # if _MSC_VER < 1600 39 | # define nullptr (0) 40 | # endif 41 | #endif 42 | 43 | #include 44 | 45 | namespace msgpack { 46 | 47 | /// @cond 48 | MSGPACK_API_VERSION_NAMESPACE(v1) { 49 | /// @endcond 50 | 51 | template 52 | struct unique_ptr : std::auto_ptr { 53 | explicit unique_ptr(T* p = 0) throw() : std::auto_ptr(p) {} 54 | unique_ptr(unique_ptr& a) throw() : std::auto_ptr(a) {} 55 | template 56 | unique_ptr (unique_ptr& a) throw() : std::auto_ptr(a) {} 57 | }; 58 | 59 | template 60 | T& move(T& t) 61 | { 62 | return t; 63 | } 64 | 65 | template 66 | T const& move(T const& t) 67 | { 68 | return t; 69 | } 70 | 71 | template 72 | struct enable_if { 73 | typedef T type; 74 | }; 75 | 76 | template 77 | struct enable_if { 78 | }; 79 | 80 | /// @cond 81 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 82 | /// @endcond 83 | 84 | } // namespace msgpack 85 | 86 | 87 | #else // __cplusplus < 201103 88 | 89 | #include 90 | #include 91 | 92 | namespace msgpack { 93 | /// @cond 94 | MSGPACK_API_VERSION_NAMESPACE(v1) { 95 | /// @endcond 96 | 97 | // unique_ptr 98 | using std::unique_ptr; 99 | // using std::make_unique; // since C++14 100 | using std::hash; 101 | 102 | // utility 103 | using std::move; 104 | using std::swap; 105 | using std::enable_if; 106 | 107 | /// @cond 108 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 109 | /// @endcond 110 | } // namespace msgpack 111 | 112 | 113 | #endif // __cplusplus < 201103 114 | 115 | #endif // __cplusplus 116 | 117 | #endif /* msgpack/cpp_config.hpp */ 118 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/fbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C FILE* buffer adaptor 3 | * 4 | * Copyright (C) 2013 Vladimir Volodko 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_FBUFFER_H 19 | #define MSGPACK_FBUFFER_H 20 | 21 | #include 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /** 29 | * @defgroup msgpack_fbuffer FILE* buffer 30 | * @ingroup msgpack_buffer 31 | * @{ 32 | */ 33 | 34 | static inline int msgpack_fbuffer_write(void* data, const char* buf, unsigned int len) 35 | { 36 | return (1 == fwrite(buf, len, 1, (FILE *)data)) ? 0 : -1; 37 | } 38 | 39 | /** @} */ 40 | 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | 46 | #endif /* msgpack/fbuffer.h */ 47 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/fbuffer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ FILE* buffer adaptor 3 | // 4 | // Copyright (C) 2013 Vladimir Volodko 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_FBUFFER_HPP__ 19 | #define MSGPACK_FBUFFER_HPP__ 20 | 21 | #include "msgpack/versioning.hpp" 22 | 23 | #include 24 | #include 25 | 26 | namespace msgpack { 27 | 28 | /// @cond 29 | MSGPACK_API_VERSION_NAMESPACE(v1) { 30 | /// @endcond 31 | 32 | class fbuffer { 33 | public: 34 | explicit fbuffer(FILE* file) : m_file(file) { } 35 | 36 | public: 37 | void write(const char* buf, unsigned int len) 38 | { 39 | if (1 != fwrite(buf, len, 1, m_file)) { 40 | throw std::runtime_error("fwrite() failed"); 41 | } 42 | } 43 | 44 | FILE* file() const 45 | { 46 | return m_file; 47 | } 48 | 49 | #if defined(MSGPACK_USE_CPP03) 50 | private: 51 | fbuffer(const fbuffer&); 52 | fbuffer& operator=(const fbuffer&); 53 | #else // defined(MSGPACK_USE_CPP03) 54 | fbuffer(const fbuffer&) = delete; 55 | fbuffer& operator=(const fbuffer&) = delete; 56 | #endif // defined(MSGPACK_USE_CPP03) 57 | 58 | private: 59 | FILE* m_file; 60 | }; 61 | 62 | /// @cond 63 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 64 | /// @endcond 65 | 66 | } // namespace msgpack 67 | 68 | #endif /* msgpack/fbuffer.hpp */ 69 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/gcc_atomic.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Licensed under the Apache License, Version 2.0 (the "License"); 3 | * you may not use this file except in compliance with the License. 4 | * You may obtain a copy of the License at 5 | * 6 | * http://www.apache.org/licenses/LICENSE-2.0 7 | * 8 | * Unless required by applicable law or agreed to in writing, software 9 | * distributed under the License is distributed on an "AS IS" BASIS, 10 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 | * See the License for the specific language governing permissions and 12 | * limitations under the License. 13 | */ 14 | 15 | #ifndef MSGPACK_GCC_ATOMIC_H 16 | #define MSGPACK_GCC_ATOMIC_H 17 | 18 | #if defined(__cplusplus) 19 | extern "C" { 20 | #endif 21 | 22 | typedef int _msgpack_atomic_counter_t; 23 | 24 | int _msgpack_sync_decr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); 25 | int _msgpack_sync_incr_and_fetch(volatile _msgpack_atomic_counter_t* ptr); 26 | 27 | 28 | #if defined(__cplusplus) 29 | } 30 | #endif 31 | 32 | 33 | #endif // MSGPACK_GCC_ATOMIC_H 34 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/iterator.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2015 MIZUKI Hirata 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | #ifndef MSGPACK_ITERATOR_HPP 20 | #define MSGPACK_ITERATOR_HPP 21 | #if !defined(MSGPACK_USE_CPP03) 22 | 23 | #include 24 | 25 | namespace msgpack 26 | { 27 | /// @cond 28 | MSGPACK_API_VERSION_NAMESPACE(MSGPACK_DEFAULT_API_NS) 29 | { 30 | /// @endcond 31 | inline object_kv* begin(object_map &map) { return map.ptr; } 32 | inline const object_kv* begin(const object_map &map) { return map.ptr; } 33 | inline object_kv* end(object_map &map) { return map.ptr + map.size; } 34 | inline const object_kv* end(const object_map &map) { return map.ptr + map.size; } 35 | 36 | inline object* begin(object_array &array) { return array.ptr; } 37 | inline const object* begin(const object_array &array) { return array.ptr; } 38 | inline object* end(object_array &array) { return array.ptr + array.size; } 39 | inline const object* end(const object_array &array) { return array.ptr + array.size; } 40 | /// @cond 41 | } 42 | /// @endcond 43 | } 44 | 45 | #endif // !defined(MSGPACK_USE_CPP03) 46 | #endif // MSGPACK_ITERATOR_HPP 47 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/object.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C dynamic typing routine 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_OBJECT_H 19 | #define MSGPACK_OBJECT_H 20 | 21 | #include "zone.h" 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | /** 30 | * @defgroup msgpack_object Dynamically typed object 31 | * @ingroup msgpack 32 | * @{ 33 | */ 34 | 35 | typedef enum { 36 | MSGPACK_OBJECT_NIL = 0x00, 37 | MSGPACK_OBJECT_BOOLEAN = 0x01, 38 | MSGPACK_OBJECT_POSITIVE_INTEGER = 0x02, 39 | MSGPACK_OBJECT_NEGATIVE_INTEGER = 0x03, 40 | MSGPACK_OBJECT_FLOAT = 0x04, 41 | #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) 42 | MSGPACK_OBJECT_DOUBLE = MSGPACK_OBJECT_FLOAT, /* obsolete */ 43 | #endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */ 44 | MSGPACK_OBJECT_STR = 0x05, 45 | MSGPACK_OBJECT_ARRAY = 0x06, 46 | MSGPACK_OBJECT_MAP = 0x07, 47 | MSGPACK_OBJECT_BIN = 0x08, 48 | MSGPACK_OBJECT_EXT = 0x09 49 | } msgpack_object_type; 50 | 51 | 52 | struct msgpack_object; 53 | struct msgpack_object_kv; 54 | 55 | typedef struct { 56 | uint32_t size; 57 | struct msgpack_object* ptr; 58 | } msgpack_object_array; 59 | 60 | typedef struct { 61 | uint32_t size; 62 | struct msgpack_object_kv* ptr; 63 | } msgpack_object_map; 64 | 65 | typedef struct { 66 | uint32_t size; 67 | const char* ptr; 68 | } msgpack_object_str; 69 | 70 | typedef struct { 71 | uint32_t size; 72 | const char* ptr; 73 | } msgpack_object_bin; 74 | 75 | typedef struct { 76 | int8_t type; 77 | uint32_t size; 78 | const char* ptr; 79 | } msgpack_object_ext; 80 | 81 | typedef union { 82 | bool boolean; 83 | uint64_t u64; 84 | int64_t i64; 85 | #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) 86 | double dec; /* obsolete*/ 87 | #endif /* MSGPACK_USE_LEGACY_NAME_AS_FLOAT */ 88 | double f64; 89 | msgpack_object_array array; 90 | msgpack_object_map map; 91 | msgpack_object_str str; 92 | msgpack_object_bin bin; 93 | msgpack_object_ext ext; 94 | } msgpack_object_union; 95 | 96 | typedef struct msgpack_object { 97 | msgpack_object_type type; 98 | msgpack_object_union via; 99 | } msgpack_object; 100 | 101 | typedef struct msgpack_object_kv { 102 | msgpack_object key; 103 | msgpack_object val; 104 | } msgpack_object_kv; 105 | 106 | MSGPACK_DLLEXPORT 107 | void msgpack_object_print(FILE* out, msgpack_object o); 108 | 109 | MSGPACK_DLLEXPORT 110 | bool msgpack_object_equal(const msgpack_object x, const msgpack_object y); 111 | 112 | /** @} */ 113 | 114 | 115 | #ifdef __cplusplus 116 | } 117 | #endif 118 | 119 | #endif /* msgpack/object.h */ 120 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/object_fwd.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ static resolution routine 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | 19 | #ifndef MSGPACK_OBJECT_FWD_HPP 20 | #define MSGPACK_OBJECT_FWD_HPP 21 | 22 | #include "msgpack/versioning.hpp" 23 | #include "msgpack/zone.hpp" 24 | #include "msgpack/object.h" 25 | 26 | #include 27 | 28 | namespace msgpack { 29 | 30 | /// @cond 31 | MSGPACK_API_VERSION_NAMESPACE(v1) { 32 | /// @endcond 33 | 34 | 35 | namespace type { 36 | enum object_type { 37 | NIL = MSGPACK_OBJECT_NIL, 38 | BOOLEAN = MSGPACK_OBJECT_BOOLEAN, 39 | POSITIVE_INTEGER = MSGPACK_OBJECT_POSITIVE_INTEGER, 40 | NEGATIVE_INTEGER = MSGPACK_OBJECT_NEGATIVE_INTEGER, 41 | FLOAT = MSGPACK_OBJECT_FLOAT, 42 | #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) 43 | DOUBLE = MSGPACK_OBJECT_DOUBLE, // obsolete 44 | #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT 45 | STR = MSGPACK_OBJECT_STR, 46 | BIN = MSGPACK_OBJECT_BIN, 47 | ARRAY = MSGPACK_OBJECT_ARRAY, 48 | MAP = MSGPACK_OBJECT_MAP, 49 | EXT = MSGPACK_OBJECT_EXT 50 | }; 51 | } 52 | 53 | 54 | struct object; 55 | struct object_kv; 56 | 57 | struct object_array { 58 | uint32_t size; 59 | msgpack::object* ptr; 60 | }; 61 | 62 | struct object_map { 63 | uint32_t size; 64 | msgpack::object_kv* ptr; 65 | }; 66 | 67 | struct object_str { 68 | uint32_t size; 69 | const char* ptr; 70 | }; 71 | 72 | struct object_bin { 73 | uint32_t size; 74 | const char* ptr; 75 | }; 76 | 77 | struct object_ext { 78 | int8_t type() const { return ptr[0]; } 79 | const char* data() const { return &ptr[1]; } 80 | uint32_t size; 81 | const char* ptr; 82 | }; 83 | 84 | struct object { 85 | union union_type { 86 | bool boolean; 87 | uint64_t u64; 88 | int64_t i64; 89 | #if defined(MSGPACK_USE_LEGACY_NAME_AS_FLOAT) 90 | double dec; // obsolete 91 | #endif // MSGPACK_USE_LEGACY_NAME_AS_FLOAT 92 | double f64; 93 | msgpack::object_array array; 94 | msgpack::object_map map; 95 | msgpack::object_str str; 96 | msgpack::object_bin bin; 97 | msgpack::object_ext ext; 98 | }; 99 | 100 | msgpack::type::object_type type; 101 | union_type via; 102 | 103 | bool is_nil() const { return type == msgpack::type::NIL; } 104 | 105 | template 106 | T as() const; 107 | 108 | template 109 | void convert(T& v) const; 110 | template 111 | void convert(T* v) const; 112 | 113 | object(); 114 | 115 | object(const msgpack_object& o); 116 | 117 | template 118 | explicit object(const T& v); 119 | 120 | template 121 | object(const T& v, msgpack::zone& z); 122 | 123 | // obsolete 124 | template 125 | object(const T& v, msgpack::zone* z); 126 | 127 | template 128 | object& operator=(const T& v); 129 | 130 | operator msgpack_object() const; 131 | 132 | struct with_zone; 133 | 134 | private: 135 | struct implicit_type; 136 | 137 | public: 138 | implicit_type convert() const; 139 | }; 140 | 141 | class type_error : public std::bad_cast { }; 142 | 143 | struct object_kv { 144 | msgpack::object key; 145 | msgpack::object val; 146 | }; 147 | 148 | struct object::with_zone : object { 149 | with_zone(msgpack::zone& zone) : zone(zone) { } 150 | msgpack::zone& zone; 151 | private: 152 | with_zone(); 153 | }; 154 | 155 | /// @cond 156 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 157 | /// @endcond 158 | 159 | } // namespace msgpack 160 | 161 | #endif // MSGPACK_OBJECT_FWD_HPP 162 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/pack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C packing routine 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_PACK_H 19 | #define MSGPACK_PACK_H 20 | 21 | #include "pack_define.h" 22 | #include "object.h" 23 | #include 24 | 25 | #ifdef __cplusplus 26 | extern "C" { 27 | #endif 28 | 29 | 30 | /** 31 | * @defgroup msgpack_buffer Buffers 32 | * @ingroup msgpack 33 | * @{ 34 | * @} 35 | */ 36 | 37 | /** 38 | * @defgroup msgpack_pack Serializer 39 | * @ingroup msgpack 40 | * @{ 41 | */ 42 | 43 | typedef int (*msgpack_packer_write)(void* data, const char* buf, size_t len); 44 | 45 | typedef struct msgpack_packer { 46 | void* data; 47 | msgpack_packer_write callback; 48 | } msgpack_packer; 49 | 50 | static void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback); 51 | 52 | static msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback); 53 | static void msgpack_packer_free(msgpack_packer* pk); 54 | 55 | static int msgpack_pack_char(msgpack_packer* pk, char d); 56 | 57 | static int msgpack_pack_signed_char(msgpack_packer* pk, signed char d); 58 | static int msgpack_pack_short(msgpack_packer* pk, short d); 59 | static int msgpack_pack_int(msgpack_packer* pk, int d); 60 | static int msgpack_pack_long(msgpack_packer* pk, long d); 61 | static int msgpack_pack_long_long(msgpack_packer* pk, long long d); 62 | static int msgpack_pack_unsigned_char(msgpack_packer* pk, unsigned char d); 63 | static int msgpack_pack_unsigned_short(msgpack_packer* pk, unsigned short d); 64 | static int msgpack_pack_unsigned_int(msgpack_packer* pk, unsigned int d); 65 | static int msgpack_pack_unsigned_long(msgpack_packer* pk, unsigned long d); 66 | static int msgpack_pack_unsigned_long_long(msgpack_packer* pk, unsigned long long d); 67 | 68 | static int msgpack_pack_uint8(msgpack_packer* pk, uint8_t d); 69 | static int msgpack_pack_uint16(msgpack_packer* pk, uint16_t d); 70 | static int msgpack_pack_uint32(msgpack_packer* pk, uint32_t d); 71 | static int msgpack_pack_uint64(msgpack_packer* pk, uint64_t d); 72 | static int msgpack_pack_int8(msgpack_packer* pk, int8_t d); 73 | static int msgpack_pack_int16(msgpack_packer* pk, int16_t d); 74 | static int msgpack_pack_int32(msgpack_packer* pk, int32_t d); 75 | static int msgpack_pack_int64(msgpack_packer* pk, int64_t d); 76 | 77 | static int msgpack_pack_fix_uint8(msgpack_packer* pk, uint8_t d); 78 | static int msgpack_pack_fix_uint16(msgpack_packer* pk, uint16_t d); 79 | static int msgpack_pack_fix_uint32(msgpack_packer* pk, uint32_t d); 80 | static int msgpack_pack_fix_uint64(msgpack_packer* pk, uint64_t d); 81 | static int msgpack_pack_fix_int8(msgpack_packer* pk, int8_t d); 82 | static int msgpack_pack_fix_int16(msgpack_packer* pk, int16_t d); 83 | static int msgpack_pack_fix_int32(msgpack_packer* pk, int32_t d); 84 | static int msgpack_pack_fix_int64(msgpack_packer* pk, int64_t d); 85 | 86 | static int msgpack_pack_float(msgpack_packer* pk, float d); 87 | static int msgpack_pack_double(msgpack_packer* pk, double d); 88 | 89 | static int msgpack_pack_nil(msgpack_packer* pk); 90 | static int msgpack_pack_true(msgpack_packer* pk); 91 | static int msgpack_pack_false(msgpack_packer* pk); 92 | 93 | static int msgpack_pack_array(msgpack_packer* pk, size_t n); 94 | 95 | static int msgpack_pack_map(msgpack_packer* pk, size_t n); 96 | 97 | static int msgpack_pack_str(msgpack_packer* pk, size_t l); 98 | static int msgpack_pack_str_body(msgpack_packer* pk, const void* b, size_t l); 99 | 100 | static int msgpack_pack_bin(msgpack_packer* pk, size_t l); 101 | static int msgpack_pack_bin_body(msgpack_packer* pk, const void* b, size_t l); 102 | 103 | static int msgpack_pack_ext(msgpack_packer* pk, size_t l, int8_t type); 104 | static int msgpack_pack_ext_body(msgpack_packer* pk, const void* b, size_t l); 105 | 106 | int msgpack_pack_object(msgpack_packer* pk, msgpack_object d); 107 | 108 | 109 | /** @} */ 110 | 111 | 112 | #define msgpack_pack_inline_func(name) \ 113 | inline int msgpack_pack ## name 114 | 115 | #define msgpack_pack_inline_func_cint(name) \ 116 | inline int msgpack_pack ## name 117 | 118 | #define msgpack_pack_inline_func_fixint(name) \ 119 | inline int msgpack_pack_fix ## name 120 | 121 | #define msgpack_pack_user msgpack_packer* 122 | 123 | #define msgpack_pack_append_buffer(user, buf, len) \ 124 | return (*(user)->callback)((user)->data, (const char*)buf, len) 125 | 126 | #include "pack_template.h" 127 | 128 | inline void msgpack_packer_init(msgpack_packer* pk, void* data, msgpack_packer_write callback) 129 | { 130 | pk->data = data; 131 | pk->callback = callback; 132 | } 133 | 134 | inline msgpack_packer* msgpack_packer_new(void* data, msgpack_packer_write callback) 135 | { 136 | msgpack_packer* pk = (msgpack_packer*)calloc(1, sizeof(msgpack_packer)); 137 | if(!pk) { return NULL; } 138 | msgpack_packer_init(pk, data, callback); 139 | return pk; 140 | } 141 | 142 | inline void msgpack_packer_free(msgpack_packer* pk) 143 | { 144 | free(pk); 145 | } 146 | 147 | 148 | #ifdef __cplusplus 149 | } 150 | #endif 151 | 152 | #endif /* msgpack/pack.h */ 153 | 154 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/pack_define.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack unpacking routine template 3 | * 4 | * Copyright (C) 2008-2010 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_PACK_DEFINE_H 19 | #define MSGPACK_PACK_DEFINE_H 20 | 21 | #include "msgpack/sysdep.h" 22 | #include 23 | #include 24 | 25 | #endif /* msgpack/pack_define.h */ 26 | 27 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/sbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C simple buffer implementation 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_SBUFFER_H 19 | #define MSGPACK_SBUFFER_H 20 | 21 | #include 22 | #include 23 | 24 | #ifdef __cplusplus 25 | extern "C" { 26 | #endif 27 | 28 | 29 | /** 30 | * @defgroup msgpack_sbuffer Simple buffer 31 | * @ingroup msgpack_buffer 32 | * @{ 33 | */ 34 | 35 | typedef struct msgpack_sbuffer { 36 | size_t size; 37 | char* data; 38 | size_t alloc; 39 | } msgpack_sbuffer; 40 | 41 | static inline void msgpack_sbuffer_init(msgpack_sbuffer* sbuf) 42 | { 43 | memset(sbuf, 0, sizeof(msgpack_sbuffer)); 44 | } 45 | 46 | static inline void msgpack_sbuffer_destroy(msgpack_sbuffer* sbuf) 47 | { 48 | free(sbuf->data); 49 | } 50 | 51 | static inline msgpack_sbuffer* msgpack_sbuffer_new(void) 52 | { 53 | return (msgpack_sbuffer*)calloc(1, sizeof(msgpack_sbuffer)); 54 | } 55 | 56 | static inline void msgpack_sbuffer_free(msgpack_sbuffer* sbuf) 57 | { 58 | if(sbuf == NULL) { return; } 59 | msgpack_sbuffer_destroy(sbuf); 60 | free(sbuf); 61 | } 62 | 63 | #ifndef MSGPACK_SBUFFER_INIT_SIZE 64 | #define MSGPACK_SBUFFER_INIT_SIZE 8192 65 | #endif 66 | 67 | static inline int msgpack_sbuffer_write(void* data, const char* buf, size_t len) 68 | { 69 | msgpack_sbuffer* sbuf = (msgpack_sbuffer*)data; 70 | 71 | if(sbuf->alloc - sbuf->size < len) { 72 | void* tmp; 73 | size_t nsize = (sbuf->alloc) ? 74 | sbuf->alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE; 75 | 76 | while(nsize < sbuf->size + len) { 77 | size_t tmp_nsize = nsize * 2; 78 | if (tmp_nsize <= nsize) { 79 | nsize = sbuf->size + len; 80 | break; 81 | } 82 | nsize = tmp_nsize; 83 | } 84 | 85 | tmp = realloc(sbuf->data, nsize); 86 | if(!tmp) { return -1; } 87 | 88 | sbuf->data = (char*)tmp; 89 | sbuf->alloc = nsize; 90 | } 91 | 92 | memcpy(sbuf->data + sbuf->size, buf, len); 93 | sbuf->size += len; 94 | return 0; 95 | } 96 | 97 | static inline char* msgpack_sbuffer_release(msgpack_sbuffer* sbuf) 98 | { 99 | char* tmp = sbuf->data; 100 | sbuf->size = 0; 101 | sbuf->data = NULL; 102 | sbuf->alloc = 0; 103 | return tmp; 104 | } 105 | 106 | static inline void msgpack_sbuffer_clear(msgpack_sbuffer* sbuf) 107 | { 108 | sbuf->size = 0; 109 | } 110 | 111 | /** @} */ 112 | 113 | 114 | #ifdef __cplusplus 115 | } 116 | #endif 117 | 118 | #endif /* msgpack/sbuffer.h */ 119 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/sbuffer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ simple buffer implementation 3 | // 4 | // Copyright (C) 2008-2013 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_SBUFFER_HPP 19 | #define MSGPACK_SBUFFER_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | 23 | #include 24 | 25 | #ifndef MSGPACK_SBUFFER_INIT_SIZE 26 | #define MSGPACK_SBUFFER_INIT_SIZE 8192 27 | #endif 28 | 29 | namespace msgpack { 30 | 31 | /// @cond 32 | MSGPACK_API_VERSION_NAMESPACE(v1) { 33 | /// @endcond 34 | 35 | class sbuffer { 36 | public: 37 | sbuffer(size_t initsz = MSGPACK_SBUFFER_INIT_SIZE):m_size(0), m_alloc(initsz) 38 | { 39 | if(initsz == 0) { 40 | m_data = nullptr; 41 | } else { 42 | m_data = (char*)::malloc(initsz); 43 | if(!m_data) { 44 | throw std::bad_alloc(); 45 | } 46 | } 47 | } 48 | 49 | ~sbuffer() 50 | { 51 | ::free(m_data); 52 | } 53 | 54 | public: 55 | void write(const char* buf, size_t len) 56 | { 57 | if(m_alloc - m_size < len) { 58 | expand_buffer(len); 59 | } 60 | std::memcpy(m_data + m_size, buf, len); 61 | m_size += len; 62 | } 63 | 64 | char* data() 65 | { 66 | return m_data; 67 | } 68 | 69 | const char* data() const 70 | { 71 | return m_data; 72 | } 73 | 74 | size_t size() const 75 | { 76 | return m_size; 77 | } 78 | 79 | char* release() 80 | { 81 | char* tmp = m_data; 82 | m_size = 0; 83 | m_data = nullptr; 84 | m_alloc = 0; 85 | return tmp; 86 | } 87 | 88 | void clear() 89 | { 90 | m_size = 0; 91 | } 92 | 93 | private: 94 | void expand_buffer(size_t len) 95 | { 96 | size_t nsize = (m_alloc > 0) ? 97 | m_alloc * 2 : MSGPACK_SBUFFER_INIT_SIZE; 98 | 99 | while(nsize < m_size + len) { 100 | size_t tmp_nsize = nsize * 2; 101 | if (tmp_nsize <= nsize) { 102 | nsize = m_size + len; 103 | break; 104 | } 105 | nsize = tmp_nsize; 106 | } 107 | 108 | void* tmp = ::realloc(m_data, nsize); 109 | if(!tmp) { 110 | throw std::bad_alloc(); 111 | } 112 | 113 | m_data = static_cast(tmp); 114 | m_alloc = nsize; 115 | } 116 | 117 | #if defined(MSGPACK_USE_CPP03) 118 | private: 119 | sbuffer(const sbuffer&); 120 | sbuffer& operator=(const sbuffer&); 121 | #else // defined(MSGPACK_USE_CPP03) 122 | sbuffer(const sbuffer&) = delete; 123 | sbuffer& operator=(const sbuffer&) = delete; 124 | #endif // defined(MSGPACK_USE_CPP03) 125 | 126 | private: 127 | size_t m_size; 128 | char* m_data; 129 | size_t m_alloc; 130 | }; 131 | 132 | /// @cond 133 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 134 | /// @endcond 135 | 136 | } // namespace msgpack 137 | 138 | #endif /* msgpack/sbuffer.hpp */ 139 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/sysdep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack system dependencies 3 | * 4 | * Copyright (C) 2008-2010 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_SYSDEP_H 19 | #define MSGPACK_SYSDEP_H 20 | 21 | #include 22 | #include 23 | #if defined(_MSC_VER) && _MSC_VER < 1600 24 | typedef __int8 int8_t; 25 | typedef unsigned __int8 uint8_t; 26 | typedef __int16 int16_t; 27 | typedef unsigned __int16 uint16_t; 28 | typedef __int32 int32_t; 29 | typedef unsigned __int32 uint32_t; 30 | typedef __int64 int64_t; 31 | typedef unsigned __int64 uint64_t; 32 | #elif defined(_MSC_VER) // && _MSC_VER >= 1600 33 | #include 34 | #else 35 | #include 36 | #include 37 | #endif 38 | 39 | #if defined(_MSC_VER) 40 | #define MSGPACK_DLLEXPORT __declspec(dllexport) 41 | #else /* _MSC_VER */ 42 | #define MSGPACK_DLLEXPORT 43 | #endif /* _MSC_VER */ 44 | 45 | #ifdef _WIN32 46 | #define _msgpack_atomic_counter_header 47 | typedef long _msgpack_atomic_counter_t; 48 | #define _msgpack_sync_decr_and_fetch(ptr) InterlockedDecrement(ptr) 49 | #define _msgpack_sync_incr_and_fetch(ptr) InterlockedIncrement(ptr) 50 | #elif defined(__GNUC__) && ((__GNUC__*10 + __GNUC_MINOR__) < 41) 51 | 52 | #if defined(__cplusplus) 53 | #define _msgpack_atomic_counter_header "gcc_atomic.hpp" 54 | #else 55 | #define _msgpack_atomic_counter_header "gcc_atomic.h" 56 | #endif 57 | 58 | #else 59 | typedef unsigned int _msgpack_atomic_counter_t; 60 | #define _msgpack_sync_decr_and_fetch(ptr) __sync_sub_and_fetch(ptr, 1) 61 | #define _msgpack_sync_incr_and_fetch(ptr) __sync_add_and_fetch(ptr, 1) 62 | #endif 63 | 64 | #ifdef _WIN32 65 | 66 | #ifdef __cplusplus 67 | /* numeric_limits::min,max */ 68 | #ifdef max 69 | #undef max 70 | #endif 71 | #ifdef min 72 | #undef min 73 | #endif 74 | #endif 75 | 76 | #else 77 | 78 | #include /* __BYTE_ORDER */ 79 | # if !defined(__APPLE__) && !defined(__FreeBSD__) && !defined(__OpenBSD__) && \ 80 | !(defined(__sun) && defined(__SVR4)) 81 | # include 82 | # endif 83 | 84 | #endif 85 | 86 | #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) 87 | #if __BYTE_ORDER == __LITTLE_ENDIAN 88 | #define __LITTLE_ENDIAN__ 89 | #elif __BYTE_ORDER == __BIG_ENDIAN 90 | #define __BIG_ENDIAN__ 91 | #elif _WIN32 92 | #define __LITTLE_ENDIAN__ 93 | #endif 94 | #endif 95 | 96 | 97 | #ifdef __LITTLE_ENDIAN__ 98 | 99 | #ifdef _WIN32 100 | # if defined(ntohs) 101 | # define _msgpack_be16(x) ntohs(x) 102 | # elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400) 103 | # define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x)) 104 | # else 105 | # define _msgpack_be16(x) ( \ 106 | ((((uint16_t)x) << 8) ) | \ 107 | ((((uint16_t)x) >> 8) ) ) 108 | # endif 109 | #else 110 | # define _msgpack_be16(x) ntohs(x) 111 | #endif 112 | 113 | #ifdef _WIN32 114 | # if defined(ntohl) 115 | # define _msgpack_be32(x) ntohl(x) 116 | # elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400) 117 | # define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x)) 118 | # else 119 | # define _msgpack_be32(x) \ 120 | ( ((((uint32_t)x) << 24) ) | \ 121 | ((((uint32_t)x) << 8) & 0x00ff0000U ) | \ 122 | ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \ 123 | ((((uint32_t)x) >> 24) ) ) 124 | # endif 125 | #else 126 | # define _msgpack_be32(x) ntohl(x) 127 | #endif 128 | 129 | #if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400) 130 | # define _msgpack_be64(x) (_byteswap_uint64(x)) 131 | #elif defined(bswap_64) 132 | # define _msgpack_be64(x) bswap_64(x) 133 | #elif defined(__DARWIN_OSSwapInt64) 134 | # define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) 135 | #else 136 | #define _msgpack_be64(x) \ 137 | ( ((((uint64_t)x) << 56) ) | \ 138 | ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ 139 | ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ 140 | ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ 141 | ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ 142 | ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ 143 | ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ 144 | ((((uint64_t)x) >> 56) ) ) 145 | #endif 146 | 147 | #else /* __LITTLE_ENDIAN__ */ 148 | 149 | #define _msgpack_be16(x) (x) 150 | #define _msgpack_be32(x) (x) 151 | #define _msgpack_be64(x) (x) 152 | 153 | #endif 154 | 155 | #define _msgpack_load16(cast, from, to) do { \ 156 | memcpy((cast*)(to), (from), sizeof(cast)); \ 157 | *(to) = _msgpack_be16(*(to)); \ 158 | } while (0); 159 | 160 | #define _msgpack_load32(cast, from, to) do { \ 161 | memcpy((cast*)(to), (from), sizeof(cast)); \ 162 | *(to) = _msgpack_be32(*(to)); \ 163 | } while (0); 164 | #define _msgpack_load64(cast, from, to) do { \ 165 | memcpy((cast*)(to), (from), sizeof(cast)); \ 166 | *(to) = _msgpack_be64(*(to)); \ 167 | } while (0); 168 | 169 | #define _msgpack_store16(to, num) \ 170 | do { uint16_t val = _msgpack_be16(num); memcpy(to, &val, 2); } while(0) 171 | #define _msgpack_store32(to, num) \ 172 | do { uint32_t val = _msgpack_be32(num); memcpy(to, &val, 4); } while(0) 173 | #define _msgpack_store64(to, num) \ 174 | do { uint64_t val = _msgpack_be64(num); memcpy(to, &val, 8); } while(0) 175 | 176 | /* 177 | #define _msgpack_load16(cast, from) \ 178 | ({ cast val; memcpy(&val, (char*)from, 2); _msgpack_be16(val); }) 179 | #define _msgpack_load32(cast, from) \ 180 | ({ cast val; memcpy(&val, (char*)from, 4); _msgpack_be32(val); }) 181 | #define _msgpack_load64(cast, from) \ 182 | ({ cast val; memcpy(&val, (char*)from, 8); _msgpack_be64(val); }) 183 | */ 184 | 185 | 186 | #if !defined(__cplusplus) && defined(_MSC_VER) 187 | # if !defined(FALSE) 188 | # define FALSE (0) 189 | # endif 190 | # if !defined(TRUE) 191 | # define TRUE (!FALSE) 192 | # endif 193 | # if _MSC_VER >= 1800 194 | # include 195 | # else 196 | # define bool int 197 | # define true TRUE 198 | # define false FALSE 199 | # endif 200 | # define inline __inline 201 | #endif 202 | 203 | #endif /* msgpack/sysdep.h */ 204 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/type.hpp: -------------------------------------------------------------------------------- 1 | #include "cpp_config.hpp" 2 | #include "adaptor/bool.hpp" 3 | #include "adaptor/char_ptr.hpp" 4 | #include "adaptor/deque.hpp" 5 | #include "adaptor/fixint.hpp" 6 | #include "adaptor/float.hpp" 7 | #include "adaptor/int.hpp" 8 | #include "adaptor/list.hpp" 9 | #include "adaptor/map.hpp" 10 | #include "adaptor/nil.hpp" 11 | #include "adaptor/pair.hpp" 12 | #include "adaptor/raw.hpp" 13 | #include "adaptor/set.hpp" 14 | #include "adaptor/string.hpp" 15 | #include "adaptor/vector.hpp" 16 | #include "adaptor/vector_bool.hpp" 17 | #include "adaptor/vector_char.hpp" 18 | #include "adaptor/msgpack_tuple.hpp" 19 | #include "adaptor/define.hpp" 20 | 21 | #if defined(MSGPACK_USE_CPP03) 22 | 23 | #include "adaptor/tr1/unordered_map.hpp" 24 | #include "adaptor/tr1/unordered_set.hpp" 25 | 26 | #else // defined(MSGPACK_USE_CPP03) 27 | 28 | #include "adaptor/cpp11/array.hpp" 29 | #include "adaptor/cpp11/array_char.hpp" 30 | #include "adaptor/cpp11/forward_list.hpp" 31 | #include "adaptor/cpp11/tuple.hpp" 32 | #include "adaptor/cpp11/unordered_map.hpp" 33 | #include "adaptor/cpp11/unordered_set.hpp" 34 | 35 | #endif // defined(MSGPACK_USE_CPP03) 36 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/unpack_define.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack unpacking routine template 3 | * 4 | * Copyright (C) 2008-2010 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_UNPACK_DEFINE_H 19 | #define MSGPACK_UNPACK_DEFINE_H 20 | 21 | #include "msgpack/sysdep.h" 22 | #include 23 | #include 24 | #include 25 | #include 26 | 27 | #ifdef __cplusplus 28 | extern "C" { 29 | #endif 30 | 31 | 32 | #ifndef MSGPACK_EMBED_STACK_SIZE 33 | #define MSGPACK_EMBED_STACK_SIZE 32 34 | #endif 35 | 36 | 37 | typedef enum { 38 | MSGPACK_CS_HEADER = 0x00, // nil 39 | 40 | //MSGPACK_CS_ = 0x01, 41 | //MSGPACK_CS_ = 0x02, // false 42 | //MSGPACK_CS_ = 0x03, // true 43 | 44 | MSGPACK_CS_BIN_8 = 0x04, 45 | MSGPACK_CS_BIN_16 = 0x05, 46 | MSGPACK_CS_BIN_32 = 0x06, 47 | 48 | MSGPACK_CS_EXT_8 = 0x07, 49 | MSGPACK_CS_EXT_16 = 0x08, 50 | MSGPACK_CS_EXT_32 = 0x09, 51 | 52 | MSGPACK_CS_FLOAT = 0x0a, 53 | MSGPACK_CS_DOUBLE = 0x0b, 54 | MSGPACK_CS_UINT_8 = 0x0c, 55 | MSGPACK_CS_UINT_16 = 0x0d, 56 | MSGPACK_CS_UINT_32 = 0x0e, 57 | MSGPACK_CS_UINT_64 = 0x0f, 58 | MSGPACK_CS_INT_8 = 0x10, 59 | MSGPACK_CS_INT_16 = 0x11, 60 | MSGPACK_CS_INT_32 = 0x12, 61 | MSGPACK_CS_INT_64 = 0x13, 62 | 63 | MSGPACK_CS_FIXEXT_1 = 0x14, 64 | MSGPACK_CS_FIXEXT_2 = 0x15, 65 | MSGPACK_CS_FIXEXT_4 = 0x16, 66 | MSGPACK_CS_FIXEXT_8 = 0x17, 67 | MSGPACK_CS_FIXEXT_16 = 0x18, 68 | 69 | MSGPACK_CS_STR_8 = 0x19, // str8 70 | MSGPACK_CS_STR_16 = 0x1a, // str16 71 | MSGPACK_CS_STR_32 = 0x1b, // str32 72 | MSGPACK_CS_ARRAY_16 = 0x1c, 73 | MSGPACK_CS_ARRAY_32 = 0x1d, 74 | MSGPACK_CS_MAP_16 = 0x1e, 75 | MSGPACK_CS_MAP_32 = 0x1f, 76 | 77 | //MSGPACK_ACS_BIG_INT_VALUE, 78 | //MSGPACK_ACS_BIG_FLOAT_VALUE, 79 | MSGPACK_ACS_STR_VALUE, 80 | MSGPACK_ACS_BIN_VALUE, 81 | MSGPACK_ACS_EXT_VALUE 82 | } msgpack_unpack_state; 83 | 84 | 85 | typedef enum { 86 | MSGPACK_CT_ARRAY_ITEM, 87 | MSGPACK_CT_MAP_KEY, 88 | MSGPACK_CT_MAP_VALUE 89 | } msgpack_container_type; 90 | 91 | 92 | #ifdef __cplusplus 93 | } 94 | #endif 95 | 96 | #endif /* msgpack/unpack_define.h */ 97 | 98 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/util.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C utilities 3 | * 4 | * Copyright (C) 2014 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_UTIL_H 19 | #define MSGPACK_UTIL_H 20 | 21 | #define MSGPACK_UNUSED(a) (void)(a) 22 | 23 | #endif /* MSGPACK_UTIL_H */ 24 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/version.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C version information 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_VERSION_H 19 | #define MSGPACK_VERSION_H 20 | 21 | #ifdef __cplusplus 22 | extern "C" { 23 | #endif 24 | 25 | MSGPACK_DLLEXPORT 26 | const char* msgpack_version(void); 27 | MSGPACK_DLLEXPORT 28 | int msgpack_version_major(void); 29 | MSGPACK_DLLEXPORT 30 | int msgpack_version_minor(void); 31 | MSGPACK_DLLEXPORT 32 | int msgpack_version_revision(void); 33 | 34 | #include "version_master.h" 35 | 36 | #define MSGPACK_STR(v) #v 37 | #define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev) 38 | 39 | #define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION) 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* msgpack/version.h */ 46 | 47 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/version.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C++ version information 3 | * 4 | * Copyright (C) 2008-2013 FURUHASHI Sadayuki and Takatoshi Kondo 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_VERSION_HPP 19 | #define MSGPACK_VERSION_HPP 20 | 21 | #include "version_master.h" 22 | 23 | #define MSGPACK_STR(v) #v 24 | #define MSGPACK_VERSION_I(maj, min, rev) MSGPACK_STR(maj) "." MSGPACK_STR(min) "." MSGPACK_STR(rev) 25 | 26 | #define MSGPACK_VERSION MSGPACK_VERSION_I(MSGPACK_VERSION_MAJOR, MSGPACK_VERSION_MINOR, MSGPACK_VERSION_REVISION) 27 | 28 | inline const char* msgpack_version(void) { 29 | return MSGPACK_VERSION; 30 | } 31 | 32 | inline int msgpack_version_major(void) { 33 | return MSGPACK_VERSION_MAJOR; 34 | } 35 | 36 | inline int msgpack_version_minor(void) { 37 | return MSGPACK_VERSION_MINOR; 38 | } 39 | 40 | inline int msgpack_version_revision(void) { 41 | return MSGPACK_VERSION_REVISION; 42 | } 43 | 44 | #endif /* msgpack/version.hpp */ 45 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/version_master.h: -------------------------------------------------------------------------------- 1 | #define MSGPACK_VERSION_MAJOR 1 2 | #define MSGPACK_VERSION_MINOR 1 3 | #define MSGPACK_VERSION_REVISION 0 4 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/versioning.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C++ version switcher 3 | * 4 | * Copyright (C) 2014 KONDO Takatoshi 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_VERSIONING_HPP 19 | #define MSGPACK_VERSIONING_HPP 20 | 21 | #if !defined(MSGPACK_DEFAULT_API_VERSION) 22 | #define MSGPACK_DEFAULT_API_VERSION 1 23 | #endif 24 | 25 | #define MSGPACK_DEFAULT_API_NS MSGPACK_PP_CAT(v, MSGPACK_DEFAULT_API_VERSION) 26 | 27 | #if MSGPACK_DEFAULT_API_VERSION == 1 28 | #define MSGPACK_PP_ENABLE_NS_v1 () 29 | //#elif MSGPACK_DEFAULT_API_VERSION == 2 30 | //#define MSGPACK_PP_ENABLE_NS_v2 () 31 | #else 32 | #error 33 | #endif 34 | 35 | #define MSGPACK_PP_CAT(a, ...) MSGPACK_PP_PRIMITIVE_CAT(a, __VA_ARGS__) 36 | #define MSGPACK_PP_PRIMITIVE_CAT(a, ...) a ## __VA_ARGS__ 37 | 38 | #define MSGPACK_PP_IIF(c) MSGPACK_PP_PRIMITIVE_CAT(MSGPACK_PP_IIF_, c) 39 | #define MSGPACK_PP_IIF_0(t, ...) __VA_ARGS__ 40 | #define MSGPACK_PP_IIF_1(t, ...) t 41 | 42 | #define MSGPACK_PP_PROBE(x) x, 1 43 | 44 | #if defined(_MSC_VER) 45 | 46 | #define MSGPACK_PP_MSVC_VA_ARGS_WORKAROUND(define, args) define args 47 | #define MSGPACK_PP_CHECK(...) MSGPACK_PP_MSVC_VA_ARGS_WORKAROUND(MSGPACK_PP_CHECK_N, (__VA_ARGS__, 0)) 48 | #define MSGPACK_PP_CHECK_N(x, n, ...) n 49 | 50 | #else // defined(__MSC_VER) 51 | 52 | #define MSGPACK_PP_CHECK(...) MSGPACK_PP_CHECK_N(__VA_ARGS__, 0) 53 | #define MSGPACK_PP_CHECK_N(x, n, ...) n 54 | 55 | #endif // defined(__MSC_VER) 56 | 57 | 58 | #define MSGPACK_PP_NS_ENABLED_PROBE(ns) MSGPACK_PP_NS_ENABLED_PROBE_PROXY( MSGPACK_PP_ENABLE_NS_##ns ) 59 | #define MSGPACK_PP_NS_ENABLED_PROBE_PROXY(...) MSGPACK_PP_NS_ENABLED_PROBE_PRIMIVIE(__VA_ARGS__) 60 | #define MSGPACK_PP_NS_ENABLED_PROBE_PRIMIVIE(x) MSGPACK_PP_NS_ENABLED_PROBE_COMBINE_ x 61 | #define MSGPACK_PP_NS_ENABLED_PROBE_COMBINE_(...) MSGPACK_PP_PROBE(~) 62 | 63 | #define MSGPACK_PP_IS_NS_ENABLED(ns) MSGPACK_PP_CHECK(MSGPACK_PP_NS_ENABLED_PROBE(ns)) 64 | 65 | #if __cplusplus < 201103 66 | #define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_PP_IIF(MSGPACK_PP_IS_NS_ENABLED(ns)) \ 67 | (namespace ns{}; using namespace ns; namespace ns, \ 68 | namespace ns) 69 | 70 | #else // __cplusplus < 201103 71 | 72 | #define MSGPACK_API_VERSION_NAMESPACE(ns) MSGPACK_PP_IIF(MSGPACK_PP_IS_NS_ENABLED(ns)) \ 73 | (inline namespace ns, namespace ns) 74 | 75 | #endif // __cplusplus < 201103 76 | 77 | #endif // MSGPACK_VERSIONING_HPP 78 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/vrefbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C zero-copy buffer implementation 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_VREFBUFFER_H 19 | #define MSGPACK_VREFBUFFER_H 20 | 21 | #include "zone.h" 22 | #include 23 | 24 | #ifndef _WIN32 25 | #include 26 | #else 27 | struct iovec { 28 | void *iov_base; 29 | size_t iov_len; 30 | }; 31 | #endif 32 | 33 | #ifdef __cplusplus 34 | extern "C" { 35 | #endif 36 | 37 | 38 | /** 39 | * @defgroup msgpack_vrefbuffer Vectored Referencing buffer 40 | * @ingroup msgpack_buffer 41 | * @{ 42 | */ 43 | 44 | struct msgpack_vrefbuffer_chunk; 45 | typedef struct msgpack_vrefbuffer_chunk msgpack_vrefbuffer_chunk; 46 | 47 | typedef struct msgpack_vrefbuffer_inner_buffer { 48 | size_t free; 49 | char* ptr; 50 | msgpack_vrefbuffer_chunk* head; 51 | } msgpack_vrefbuffer_inner_buffer; 52 | 53 | typedef struct msgpack_vrefbuffer { 54 | struct iovec* tail; 55 | struct iovec* end; 56 | struct iovec* array; 57 | 58 | size_t chunk_size; 59 | size_t ref_size; 60 | 61 | msgpack_vrefbuffer_inner_buffer inner_buffer; 62 | } msgpack_vrefbuffer; 63 | 64 | 65 | #ifndef MSGPACK_VREFBUFFER_REF_SIZE 66 | #define MSGPACK_VREFBUFFER_REF_SIZE 32 67 | #endif 68 | 69 | #ifndef MSGPACK_VREFBUFFER_CHUNK_SIZE 70 | #define MSGPACK_VREFBUFFER_CHUNK_SIZE 8192 71 | #endif 72 | 73 | MSGPACK_DLLEXPORT 74 | bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, 75 | size_t ref_size, size_t chunk_size); 76 | MSGPACK_DLLEXPORT 77 | void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf); 78 | 79 | static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size); 80 | static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf); 81 | 82 | static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len); 83 | 84 | static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref); 85 | static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref); 86 | 87 | MSGPACK_DLLEXPORT 88 | int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf, 89 | const char* buf, size_t len); 90 | 91 | MSGPACK_DLLEXPORT 92 | int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf, 93 | const char* buf, size_t len); 94 | 95 | MSGPACK_DLLEXPORT 96 | int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to); 97 | 98 | MSGPACK_DLLEXPORT 99 | void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vref); 100 | 101 | /** @} */ 102 | 103 | 104 | static inline msgpack_vrefbuffer* msgpack_vrefbuffer_new(size_t ref_size, size_t chunk_size) 105 | { 106 | msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)malloc(sizeof(msgpack_vrefbuffer)); 107 | if (vbuf == NULL) return NULL; 108 | if(!msgpack_vrefbuffer_init(vbuf, ref_size, chunk_size)) { 109 | free(vbuf); 110 | return NULL; 111 | } 112 | return vbuf; 113 | } 114 | 115 | static inline void msgpack_vrefbuffer_free(msgpack_vrefbuffer* vbuf) 116 | { 117 | if(vbuf == NULL) { return; } 118 | msgpack_vrefbuffer_destroy(vbuf); 119 | free(vbuf); 120 | } 121 | 122 | static inline int msgpack_vrefbuffer_write(void* data, const char* buf, size_t len) 123 | { 124 | msgpack_vrefbuffer* vbuf = (msgpack_vrefbuffer*)data; 125 | 126 | if(len < vbuf->ref_size) { 127 | return msgpack_vrefbuffer_append_copy(vbuf, buf, len); 128 | } else { 129 | return msgpack_vrefbuffer_append_ref(vbuf, buf, len); 130 | } 131 | } 132 | 133 | static inline const struct iovec* msgpack_vrefbuffer_vec(const msgpack_vrefbuffer* vref) 134 | { 135 | return vref->array; 136 | } 137 | 138 | static inline size_t msgpack_vrefbuffer_veclen(const msgpack_vrefbuffer* vref) 139 | { 140 | return (size_t)(vref->tail - vref->array); 141 | } 142 | 143 | 144 | #ifdef __cplusplus 145 | } 146 | #endif 147 | 148 | #endif /* msgpack/vrefbuffer.h */ 149 | 150 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/zbuffer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C deflate buffer implementation 3 | * 4 | * Copyright (C) 2010 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_ZBUFFER_H 19 | #define MSGPACK_ZBUFFER_H 20 | 21 | #include "sysdep.h" 22 | #include 23 | #include 24 | #include 25 | 26 | #ifdef __cplusplus 27 | extern "C" { 28 | #endif 29 | 30 | 31 | /** 32 | * @defgroup msgpack_zbuffer Compressed buffer 33 | * @ingroup msgpack_buffer 34 | * @{ 35 | */ 36 | 37 | typedef struct msgpack_zbuffer { 38 | z_stream stream; 39 | char* data; 40 | size_t init_size; 41 | } msgpack_zbuffer; 42 | 43 | #ifndef MSGPACK_ZBUFFER_INIT_SIZE 44 | #define MSGPACK_ZBUFFER_INIT_SIZE 8192 45 | #endif 46 | 47 | static inline bool msgpack_zbuffer_init( 48 | msgpack_zbuffer* zbuf, int level, size_t init_size); 49 | static inline void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf); 50 | 51 | static inline msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size); 52 | static inline void msgpack_zbuffer_free(msgpack_zbuffer* zbuf); 53 | 54 | static inline char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf); 55 | 56 | static inline const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf); 57 | static inline size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf); 58 | 59 | static inline bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf); 60 | static inline void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf); 61 | static inline char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf); 62 | 63 | 64 | #ifndef MSGPACK_ZBUFFER_RESERVE_SIZE 65 | #define MSGPACK_ZBUFFER_RESERVE_SIZE 512 66 | #endif 67 | 68 | static inline int msgpack_zbuffer_write(void* data, const char* buf, size_t len); 69 | 70 | static inline bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf); 71 | 72 | 73 | bool msgpack_zbuffer_init(msgpack_zbuffer* zbuf, 74 | int level, size_t init_size) 75 | { 76 | memset(zbuf, 0, sizeof(msgpack_zbuffer)); 77 | zbuf->init_size = init_size; 78 | if(deflateInit(&zbuf->stream, level) != Z_OK) { 79 | free(zbuf->data); 80 | return false; 81 | } 82 | return true; 83 | } 84 | 85 | void msgpack_zbuffer_destroy(msgpack_zbuffer* zbuf) 86 | { 87 | deflateEnd(&zbuf->stream); 88 | free(zbuf->data); 89 | } 90 | 91 | msgpack_zbuffer* msgpack_zbuffer_new(int level, size_t init_size) 92 | { 93 | msgpack_zbuffer* zbuf = (msgpack_zbuffer*)malloc(sizeof(msgpack_zbuffer)); 94 | if (zbuf == NULL) return NULL; 95 | if(!msgpack_zbuffer_init(zbuf, level, init_size)) { 96 | free(zbuf); 97 | return NULL; 98 | } 99 | return zbuf; 100 | } 101 | 102 | void msgpack_zbuffer_free(msgpack_zbuffer* zbuf) 103 | { 104 | if(zbuf == NULL) { return; } 105 | msgpack_zbuffer_destroy(zbuf); 106 | free(zbuf); 107 | } 108 | 109 | bool msgpack_zbuffer_expand(msgpack_zbuffer* zbuf) 110 | { 111 | size_t used = (char*)zbuf->stream.next_out - zbuf->data; 112 | size_t csize = used + zbuf->stream.avail_out; 113 | size_t nsize = (csize == 0) ? zbuf->init_size : csize * 2; 114 | 115 | char* tmp = (char*)realloc(zbuf->data, nsize); 116 | if(tmp == NULL) { 117 | return false; 118 | } 119 | 120 | zbuf->data = tmp; 121 | zbuf->stream.next_out = (Bytef*)(tmp + used); 122 | zbuf->stream.avail_out = nsize - used; 123 | 124 | return true; 125 | } 126 | 127 | int msgpack_zbuffer_write(void* data, const char* buf, size_t len) 128 | { 129 | msgpack_zbuffer* zbuf = (msgpack_zbuffer*)data; 130 | 131 | zbuf->stream.next_in = (Bytef*)buf; 132 | zbuf->stream.avail_in = len; 133 | 134 | do { 135 | if(zbuf->stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { 136 | if(!msgpack_zbuffer_expand(zbuf)) { 137 | return -1; 138 | } 139 | } 140 | 141 | if(deflate(&zbuf->stream, Z_NO_FLUSH) != Z_OK) { 142 | return -1; 143 | } 144 | } while(zbuf->stream.avail_in > 0); 145 | 146 | return 0; 147 | } 148 | 149 | char* msgpack_zbuffer_flush(msgpack_zbuffer* zbuf) 150 | { 151 | while(true) { 152 | switch(deflate(&zbuf->stream, Z_FINISH)) { 153 | case Z_STREAM_END: 154 | return zbuf->data; 155 | case Z_OK: 156 | if(!msgpack_zbuffer_expand(zbuf)) { 157 | return NULL; 158 | } 159 | break; 160 | default: 161 | return NULL; 162 | } 163 | } 164 | } 165 | 166 | const char* msgpack_zbuffer_data(const msgpack_zbuffer* zbuf) 167 | { 168 | return zbuf->data; 169 | } 170 | 171 | size_t msgpack_zbuffer_size(const msgpack_zbuffer* zbuf) 172 | { 173 | return (char*)zbuf->stream.next_out - zbuf->data; 174 | } 175 | 176 | void msgpack_zbuffer_reset_buffer(msgpack_zbuffer* zbuf) 177 | { 178 | zbuf->stream.avail_out += (char*)zbuf->stream.next_out - zbuf->data; 179 | zbuf->stream.next_out = (Bytef*)zbuf->data; 180 | } 181 | 182 | bool msgpack_zbuffer_reset(msgpack_zbuffer* zbuf) 183 | { 184 | if(deflateReset(&zbuf->stream) != Z_OK) { 185 | return false; 186 | } 187 | msgpack_zbuffer_reset_buffer(zbuf); 188 | return true; 189 | } 190 | 191 | char* msgpack_zbuffer_release_buffer(msgpack_zbuffer* zbuf) 192 | { 193 | char* tmp = zbuf->data; 194 | zbuf->data = NULL; 195 | zbuf->stream.next_out = NULL; 196 | zbuf->stream.avail_out = 0; 197 | return tmp; 198 | } 199 | 200 | /** @} */ 201 | 202 | 203 | #ifdef __cplusplus 204 | } 205 | #endif 206 | 207 | #endif /* msgpack/zbuffer.h */ 208 | 209 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/zbuffer.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ deflate buffer implementation 3 | // 4 | // Copyright (C) 2010-2013 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_ZBUFFER_HPP 19 | #define MSGPACK_ZBUFFER_HPP 20 | 21 | #include "msgpack/versioning.hpp" 22 | 23 | #include 24 | #include 25 | 26 | #ifndef MSGPACK_ZBUFFER_RESERVE_SIZE 27 | #define MSGPACK_ZBUFFER_RESERVE_SIZE 512 28 | #endif 29 | 30 | #ifndef MSGPACK_ZBUFFER_INIT_SIZE 31 | #define MSGPACK_ZBUFFER_INIT_SIZE 8192 32 | #endif 33 | 34 | namespace msgpack { 35 | 36 | /// @cond 37 | MSGPACK_API_VERSION_NAMESPACE(v1) { 38 | /// @endcond 39 | 40 | class zbuffer { 41 | public: 42 | zbuffer(int level = Z_DEFAULT_COMPRESSION, 43 | size_t init_size = MSGPACK_ZBUFFER_INIT_SIZE) 44 | : m_data(nullptr), m_init_size(init_size) 45 | { 46 | m_stream.zalloc = Z_NULL; 47 | m_stream.zfree = Z_NULL; 48 | m_stream.opaque = Z_NULL; 49 | m_stream.next_out = Z_NULL; 50 | m_stream.avail_out = 0; 51 | if(deflateInit(&m_stream, level) != Z_OK) { 52 | throw std::bad_alloc(); 53 | } 54 | } 55 | 56 | ~zbuffer() 57 | { 58 | deflateEnd(&m_stream); 59 | ::free(m_data); 60 | } 61 | 62 | public: 63 | void write(const char* buf, size_t len) 64 | { 65 | m_stream.next_in = reinterpret_cast(const_cast(buf)); 66 | m_stream.avail_in = len; 67 | 68 | do { 69 | if(m_stream.avail_out < MSGPACK_ZBUFFER_RESERVE_SIZE) { 70 | if(!expand()) { 71 | throw std::bad_alloc(); 72 | } 73 | } 74 | 75 | if(deflate(&m_stream, Z_NO_FLUSH) != Z_OK) { 76 | throw std::bad_alloc(); 77 | } 78 | } while(m_stream.avail_in > 0); 79 | } 80 | 81 | char* flush() 82 | { 83 | while(true) { 84 | switch(deflate(&m_stream, Z_FINISH)) { 85 | case Z_STREAM_END: 86 | return m_data; 87 | case Z_OK: 88 | if(!expand()) { 89 | throw std::bad_alloc(); 90 | } 91 | break; 92 | default: 93 | throw std::bad_alloc(); 94 | } 95 | } 96 | } 97 | 98 | char* data() 99 | { 100 | return m_data; 101 | } 102 | 103 | const char* data() const 104 | { 105 | return m_data; 106 | } 107 | 108 | size_t size() const 109 | { 110 | return reinterpret_cast(m_stream.next_out) - m_data; 111 | } 112 | 113 | void reset() 114 | { 115 | if(deflateReset(&m_stream) != Z_OK) { 116 | throw std::bad_alloc(); 117 | } 118 | reset_buffer(); 119 | } 120 | 121 | void reset_buffer() 122 | { 123 | m_stream.avail_out += reinterpret_cast(m_stream.next_out) - m_data; 124 | m_stream.next_out = reinterpret_cast(m_data); 125 | } 126 | 127 | char* release_buffer() 128 | { 129 | char* tmp = m_data; 130 | m_data = nullptr; 131 | m_stream.next_out = nullptr; 132 | m_stream.avail_out = 0; 133 | return tmp; 134 | } 135 | 136 | private: 137 | bool expand() 138 | { 139 | size_t used = reinterpret_cast(m_stream.next_out) - m_data; 140 | size_t csize = used + m_stream.avail_out; 141 | size_t nsize = (csize == 0) ? m_init_size : csize * 2; 142 | 143 | char* tmp = static_cast(::realloc(m_data, nsize)); 144 | if(tmp == nullptr) { 145 | return false; 146 | } 147 | 148 | m_data = tmp; 149 | m_stream.next_out = reinterpret_cast(tmp + used); 150 | m_stream.avail_out = nsize - used; 151 | 152 | return true; 153 | } 154 | #if defined(MSGPACK_USE_CPP03) 155 | private: 156 | zbuffer(const zbuffer&); 157 | zbuffer& operator=(const zbuffer&); 158 | #else // defined(MSGPACK_USE_CPP03) 159 | zbuffer(const zbuffer&) = delete; 160 | zbuffer& operator=(const zbuffer&) = delete; 161 | #endif // defined(MSGPACK_USE_CPP03) 162 | 163 | private: 164 | z_stream m_stream; 165 | char* m_data; 166 | size_t m_init_size; 167 | }; 168 | 169 | /// @cond 170 | } // MSGPACK_API_VERSION_NAMESPACE(v1) 171 | /// @endcond 172 | 173 | } // namespace msgpack 174 | 175 | #endif /* msgpack/zbuffer.hpp */ 176 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/zone.h: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C memory pool implementation 3 | * 4 | * Copyright (C) 2008-2010 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #ifndef MSGPACK_ZONE_H 19 | #define MSGPACK_ZONE_H 20 | 21 | #include "sysdep.h" 22 | 23 | #ifdef __cplusplus 24 | extern "C" { 25 | #endif 26 | 27 | 28 | /** 29 | * @defgroup msgpack_zone Memory zone 30 | * @ingroup msgpack 31 | * @{ 32 | */ 33 | 34 | typedef struct msgpack_zone_finalizer { 35 | void (*func)(void* data); 36 | void* data; 37 | } msgpack_zone_finalizer; 38 | 39 | typedef struct msgpack_zone_finalizer_array { 40 | msgpack_zone_finalizer* tail; 41 | msgpack_zone_finalizer* end; 42 | msgpack_zone_finalizer* array; 43 | } msgpack_zone_finalizer_array; 44 | 45 | struct msgpack_zone_chunk; 46 | typedef struct msgpack_zone_chunk msgpack_zone_chunk; 47 | 48 | typedef struct msgpack_zone_chunk_list { 49 | size_t free; 50 | char* ptr; 51 | msgpack_zone_chunk* head; 52 | } msgpack_zone_chunk_list; 53 | 54 | typedef struct msgpack_zone { 55 | msgpack_zone_chunk_list chunk_list; 56 | msgpack_zone_finalizer_array finalizer_array; 57 | size_t chunk_size; 58 | } msgpack_zone; 59 | 60 | #ifndef MSGPACK_ZONE_CHUNK_SIZE 61 | #define MSGPACK_ZONE_CHUNK_SIZE 8192 62 | #endif 63 | 64 | MSGPACK_DLLEXPORT 65 | bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size); 66 | MSGPACK_DLLEXPORT 67 | void msgpack_zone_destroy(msgpack_zone* zone); 68 | 69 | MSGPACK_DLLEXPORT 70 | msgpack_zone* msgpack_zone_new(size_t chunk_size); 71 | MSGPACK_DLLEXPORT 72 | void msgpack_zone_free(msgpack_zone* zone); 73 | 74 | static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size); 75 | static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size); 76 | 77 | static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone, 78 | void (*func)(void* data), void* data); 79 | 80 | static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b); 81 | 82 | MSGPACK_DLLEXPORT 83 | bool msgpack_zone_is_empty(msgpack_zone* zone); 84 | 85 | MSGPACK_DLLEXPORT 86 | void msgpack_zone_clear(msgpack_zone* zone); 87 | 88 | /** @} */ 89 | 90 | 91 | #ifndef MSGPACK_ZONE_ALIGN 92 | #define MSGPACK_ZONE_ALIGN sizeof(void*) 93 | #endif 94 | 95 | MSGPACK_DLLEXPORT 96 | void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size); 97 | 98 | static inline void* msgpack_zone_malloc_no_align(msgpack_zone* zone, size_t size) 99 | { 100 | char* ptr; 101 | msgpack_zone_chunk_list* cl = &zone->chunk_list; 102 | 103 | if(zone->chunk_list.free < size) { 104 | return msgpack_zone_malloc_expand(zone, size); 105 | } 106 | 107 | ptr = cl->ptr; 108 | cl->free -= size; 109 | cl->ptr += size; 110 | 111 | return ptr; 112 | } 113 | 114 | static inline void* msgpack_zone_malloc(msgpack_zone* zone, size_t size) 115 | { 116 | char* aligned = 117 | (char*)( 118 | (size_t)( 119 | zone->chunk_list.ptr + (MSGPACK_ZONE_ALIGN - 1) 120 | ) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN 121 | ); 122 | size_t adjusted_size = size + (aligned - zone->chunk_list.ptr); 123 | if(zone->chunk_list.free >= adjusted_size) { 124 | zone->chunk_list.free -= adjusted_size; 125 | zone->chunk_list.ptr += adjusted_size; 126 | return aligned; 127 | } 128 | { 129 | void* ptr = msgpack_zone_malloc_expand(zone, size + (MSGPACK_ZONE_ALIGN - 1)); 130 | if (ptr) { 131 | return (char*)((size_t)(ptr) / MSGPACK_ZONE_ALIGN * MSGPACK_ZONE_ALIGN); 132 | } 133 | } 134 | return NULL; 135 | } 136 | 137 | 138 | bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone, 139 | void (*func)(void* data), void* data); 140 | 141 | static inline bool msgpack_zone_push_finalizer(msgpack_zone* zone, 142 | void (*func)(void* data), void* data) 143 | { 144 | msgpack_zone_finalizer_array* const fa = &zone->finalizer_array; 145 | msgpack_zone_finalizer* fin = fa->tail; 146 | 147 | if(fin == fa->end) { 148 | return msgpack_zone_push_finalizer_expand(zone, func, data); 149 | } 150 | 151 | fin->func = func; 152 | fin->data = data; 153 | 154 | ++fa->tail; 155 | 156 | return true; 157 | } 158 | 159 | static inline void msgpack_zone_swap(msgpack_zone* a, msgpack_zone* b) 160 | { 161 | msgpack_zone tmp = *a; 162 | *a = *b; 163 | *b = tmp; 164 | } 165 | 166 | 167 | #ifdef __cplusplus 168 | } 169 | #endif 170 | 171 | #endif /* msgpack/zone.h */ 172 | -------------------------------------------------------------------------------- /deps/msgpack/msgpack/zone.hpp: -------------------------------------------------------------------------------- 1 | // 2 | // MessagePack for C++ memory pool 3 | // 4 | // Copyright (C) 2008-2014 FURUHASHI Sadayuki and KONDO Takatoshi 5 | // 6 | // Licensed under the Apache License, Version 2.0 (the "License"); 7 | // you may not use this file except in compliance with the License. 8 | // You may obtain a copy of the License at 9 | // 10 | // http://www.apache.org/licenses/LICENSE-2.0 11 | // 12 | // Unless required by applicable law or agreed to in writing, software 13 | // distributed under the License is distributed on an "AS IS" BASIS, 14 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | // See the License for the specific language governing permissions and 16 | // limitations under the License. 17 | // 18 | #ifndef MSGPACK_ZONE_HPP 19 | #define MSGPACK_ZONE_HPP 20 | 21 | #include "msgpack/cpp_config.hpp" 22 | 23 | #if defined(MSGPACK_USE_CPP03) 24 | #include "detail/cpp03_zone.hpp" 25 | #else // MSGPACK_USE_CPP03 26 | #include "detail/cpp11_zone.hpp" 27 | #endif // MSGPACK_USE_CPP03 28 | 29 | #endif // MSGPACK_ZONE_HPP 30 | -------------------------------------------------------------------------------- /deps/msgpack/version.c: -------------------------------------------------------------------------------- 1 | #include "msgpack.h" 2 | 3 | const char* msgpack_version(void) 4 | { 5 | return MSGPACK_VERSION; 6 | } 7 | 8 | int msgpack_version_major(void) 9 | { 10 | return MSGPACK_VERSION_MAJOR; 11 | } 12 | 13 | int msgpack_version_minor(void) 14 | { 15 | return MSGPACK_VERSION_MINOR; 16 | } 17 | 18 | int msgpack_version_revision(void) 19 | { 20 | return MSGPACK_VERSION_REVISION; 21 | } 22 | 23 | -------------------------------------------------------------------------------- /deps/msgpack/vrefbuffer.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C zero-copy buffer implementation 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #include "msgpack/vrefbuffer.h" 19 | #include 20 | #include 21 | 22 | #define MSGPACK_PACKER_MAX_BUFFER_SIZE 9 23 | 24 | struct msgpack_vrefbuffer_chunk { 25 | struct msgpack_vrefbuffer_chunk* next; 26 | /* data ... */ 27 | }; 28 | 29 | bool msgpack_vrefbuffer_init(msgpack_vrefbuffer* vbuf, 30 | size_t ref_size, size_t chunk_size) 31 | { 32 | size_t nfirst; 33 | struct iovec* array; 34 | msgpack_vrefbuffer_chunk* chunk; 35 | 36 | vbuf->chunk_size = chunk_size; 37 | vbuf->ref_size = 38 | ref_size > MSGPACK_PACKER_MAX_BUFFER_SIZE + 1 ? 39 | ref_size : MSGPACK_PACKER_MAX_BUFFER_SIZE + 1 ; 40 | 41 | nfirst = (sizeof(struct iovec) < 72/2) ? 42 | 72 / sizeof(struct iovec) : 8; 43 | 44 | array = (struct iovec*)malloc( 45 | sizeof(struct iovec) * nfirst); 46 | if(array == NULL) { 47 | return false; 48 | } 49 | 50 | vbuf->tail = array; 51 | vbuf->end = array + nfirst; 52 | vbuf->array = array; 53 | 54 | chunk = (msgpack_vrefbuffer_chunk*)malloc( 55 | sizeof(msgpack_vrefbuffer_chunk) + chunk_size); 56 | if(chunk == NULL) { 57 | free(array); 58 | return false; 59 | } 60 | else { 61 | msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; 62 | 63 | ib->free = chunk_size; 64 | ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk); 65 | ib->head = chunk; 66 | chunk->next = NULL; 67 | 68 | return true; 69 | } 70 | } 71 | 72 | void msgpack_vrefbuffer_destroy(msgpack_vrefbuffer* vbuf) 73 | { 74 | msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head; 75 | while(true) { 76 | msgpack_vrefbuffer_chunk* n = c->next; 77 | free(c); 78 | if(n != NULL) { 79 | c = n; 80 | } else { 81 | break; 82 | } 83 | } 84 | free(vbuf->array); 85 | } 86 | 87 | void msgpack_vrefbuffer_clear(msgpack_vrefbuffer* vbuf) 88 | { 89 | msgpack_vrefbuffer_chunk* c = vbuf->inner_buffer.head->next; 90 | msgpack_vrefbuffer_chunk* n; 91 | while(c != NULL) { 92 | n = c->next; 93 | free(c); 94 | c = n; 95 | } 96 | 97 | { 98 | msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; 99 | msgpack_vrefbuffer_chunk* chunk = ib->head; 100 | chunk->next = NULL; 101 | ib->free = vbuf->chunk_size; 102 | ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk); 103 | 104 | vbuf->tail = vbuf->array; 105 | } 106 | } 107 | 108 | int msgpack_vrefbuffer_append_ref(msgpack_vrefbuffer* vbuf, 109 | const char* buf, size_t len) 110 | { 111 | if(vbuf->tail == vbuf->end) { 112 | const size_t nused = (size_t)(vbuf->tail - vbuf->array); 113 | const size_t nnext = nused * 2; 114 | 115 | struct iovec* nvec = (struct iovec*)realloc( 116 | vbuf->array, sizeof(struct iovec)*nnext); 117 | if(nvec == NULL) { 118 | return -1; 119 | } 120 | 121 | vbuf->array = nvec; 122 | vbuf->end = nvec + nnext; 123 | vbuf->tail = nvec + nused; 124 | } 125 | 126 | vbuf->tail->iov_base = (char*)buf; 127 | vbuf->tail->iov_len = len; 128 | ++vbuf->tail; 129 | 130 | return 0; 131 | } 132 | 133 | int msgpack_vrefbuffer_append_copy(msgpack_vrefbuffer* vbuf, 134 | const char* buf, size_t len) 135 | { 136 | msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; 137 | char* m; 138 | 139 | if(ib->free < len) { 140 | msgpack_vrefbuffer_chunk* chunk; 141 | size_t sz = vbuf->chunk_size; 142 | if(sz < len) { 143 | sz = len; 144 | } 145 | 146 | chunk = (msgpack_vrefbuffer_chunk*)malloc( 147 | sizeof(msgpack_vrefbuffer_chunk) + sz); 148 | if(chunk == NULL) { 149 | return -1; 150 | } 151 | 152 | chunk->next = ib->head; 153 | ib->head = chunk; 154 | ib->free = sz; 155 | ib->ptr = ((char*)chunk) + sizeof(msgpack_vrefbuffer_chunk); 156 | } 157 | 158 | m = ib->ptr; 159 | memcpy(m, buf, len); 160 | ib->free -= len; 161 | ib->ptr += len; 162 | 163 | if(vbuf->tail != vbuf->array && m == 164 | (const char*)((vbuf->tail-1)->iov_base) + (vbuf->tail-1)->iov_len) { 165 | (vbuf->tail-1)->iov_len += len; 166 | return 0; 167 | } else { 168 | return msgpack_vrefbuffer_append_ref(vbuf, m, len); 169 | } 170 | } 171 | 172 | int msgpack_vrefbuffer_migrate(msgpack_vrefbuffer* vbuf, msgpack_vrefbuffer* to) 173 | { 174 | size_t sz = vbuf->chunk_size; 175 | 176 | msgpack_vrefbuffer_chunk* empty = (msgpack_vrefbuffer_chunk*)malloc( 177 | sizeof(msgpack_vrefbuffer_chunk) + sz); 178 | if(empty == NULL) { 179 | return -1; 180 | } 181 | 182 | empty->next = NULL; 183 | 184 | { 185 | const size_t nused = (size_t)(vbuf->tail - vbuf->array); 186 | if(to->tail + nused < vbuf->end) { 187 | struct iovec* nvec; 188 | const size_t tosize = (size_t)(to->tail - to->array); 189 | const size_t reqsize = nused + tosize; 190 | size_t nnext = (size_t)(to->end - to->array) * 2; 191 | while(nnext < reqsize) { 192 | size_t tmp_nnext = nnext * 2; 193 | if (tmp_nnext <= nnext) { 194 | nnext = reqsize; 195 | break; 196 | } 197 | nnext = tmp_nnext; 198 | } 199 | 200 | nvec = (struct iovec*)realloc( 201 | to->array, sizeof(struct iovec)*nnext); 202 | if(nvec == NULL) { 203 | free(empty); 204 | return -1; 205 | } 206 | 207 | to->array = nvec; 208 | to->end = nvec + nnext; 209 | to->tail = nvec + tosize; 210 | } 211 | 212 | memcpy(to->tail, vbuf->array, sizeof(struct iovec)*nused); 213 | 214 | to->tail += nused; 215 | vbuf->tail = vbuf->array; 216 | 217 | { 218 | msgpack_vrefbuffer_inner_buffer* const ib = &vbuf->inner_buffer; 219 | msgpack_vrefbuffer_inner_buffer* const toib = &to->inner_buffer; 220 | 221 | msgpack_vrefbuffer_chunk* last = ib->head; 222 | while(last->next != NULL) { 223 | last = last->next; 224 | } 225 | last->next = toib->head; 226 | toib->head = ib->head; 227 | 228 | if(toib->free < ib->free) { 229 | toib->free = ib->free; 230 | toib->ptr = ib->ptr; 231 | } 232 | 233 | ib->head = empty; 234 | ib->free = sz; 235 | ib->ptr = ((char*)empty) + sizeof(msgpack_vrefbuffer_chunk); 236 | } 237 | } 238 | 239 | return 0; 240 | } 241 | -------------------------------------------------------------------------------- /deps/msgpack/zone.c: -------------------------------------------------------------------------------- 1 | /* 2 | * MessagePack for C memory pool implementation 3 | * 4 | * Copyright (C) 2008-2009 FURUHASHI Sadayuki 5 | * 6 | * Licensed under the Apache License, Version 2.0 (the "License"); 7 | * you may not use this file except in compliance with the License. 8 | * You may obtain a copy of the License at 9 | * 10 | * http://www.apache.org/licenses/LICENSE-2.0 11 | * 12 | * Unless required by applicable law or agreed to in writing, software 13 | * distributed under the License is distributed on an "AS IS" BASIS, 14 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | * See the License for the specific language governing permissions and 16 | * limitations under the License. 17 | */ 18 | #include "msgpack/zone.h" 19 | #include 20 | #include 21 | 22 | struct msgpack_zone_chunk { 23 | struct msgpack_zone_chunk* next; 24 | /* data ... */ 25 | }; 26 | 27 | static inline bool init_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size) 28 | { 29 | msgpack_zone_chunk* chunk = (msgpack_zone_chunk*)malloc( 30 | sizeof(msgpack_zone_chunk) + chunk_size); 31 | if(chunk == NULL) { 32 | return false; 33 | } 34 | 35 | cl->head = chunk; 36 | cl->free = chunk_size; 37 | cl->ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk); 38 | chunk->next = NULL; 39 | 40 | return true; 41 | } 42 | 43 | static inline void destroy_chunk_list(msgpack_zone_chunk_list* cl) 44 | { 45 | msgpack_zone_chunk* c = cl->head; 46 | while(true) { 47 | msgpack_zone_chunk* n = c->next; 48 | free(c); 49 | if(n != NULL) { 50 | c = n; 51 | } else { 52 | break; 53 | } 54 | } 55 | } 56 | 57 | static inline void clear_chunk_list(msgpack_zone_chunk_list* cl, size_t chunk_size) 58 | { 59 | msgpack_zone_chunk* c = cl->head; 60 | while(true) { 61 | msgpack_zone_chunk* n = c->next; 62 | if(n != NULL) { 63 | free(c); 64 | c = n; 65 | } else { 66 | cl->head = c; 67 | break; 68 | } 69 | } 70 | cl->head->next = NULL; 71 | cl->free = chunk_size; 72 | cl->ptr = ((char*)cl->head) + sizeof(msgpack_zone_chunk); 73 | } 74 | 75 | void* msgpack_zone_malloc_expand(msgpack_zone* zone, size_t size) 76 | { 77 | msgpack_zone_chunk_list* const cl = &zone->chunk_list; 78 | msgpack_zone_chunk* chunk; 79 | 80 | size_t sz = zone->chunk_size; 81 | 82 | while(sz < size) { 83 | size_t tmp_sz = sz * 2; 84 | if (tmp_sz <= sz) { 85 | tmp_sz = size; 86 | break; 87 | } 88 | sz = tmp_sz; 89 | } 90 | 91 | chunk = (msgpack_zone_chunk*)malloc( 92 | sizeof(msgpack_zone_chunk) + sz); 93 | if (chunk == NULL) { 94 | return NULL; 95 | } 96 | else { 97 | char* ptr = ((char*)chunk) + sizeof(msgpack_zone_chunk); 98 | chunk->next = cl->head; 99 | cl->head = chunk; 100 | cl->free = sz - size; 101 | cl->ptr = ptr + size; 102 | 103 | return ptr; 104 | } 105 | } 106 | 107 | 108 | static inline void init_finalizer_array(msgpack_zone_finalizer_array* fa) 109 | { 110 | fa->tail = NULL; 111 | fa->end = NULL; 112 | fa->array = NULL; 113 | } 114 | 115 | static inline void call_finalizer_array(msgpack_zone_finalizer_array* fa) 116 | { 117 | msgpack_zone_finalizer* fin = fa->tail; 118 | for(; fin != fa->array; --fin) { 119 | (*(fin-1)->func)((fin-1)->data); 120 | } 121 | } 122 | 123 | static inline void destroy_finalizer_array(msgpack_zone_finalizer_array* fa) 124 | { 125 | call_finalizer_array(fa); 126 | free(fa->array); 127 | } 128 | 129 | static inline void clear_finalizer_array(msgpack_zone_finalizer_array* fa) 130 | { 131 | call_finalizer_array(fa); 132 | fa->tail = fa->array; 133 | } 134 | 135 | bool msgpack_zone_push_finalizer_expand(msgpack_zone* zone, 136 | void (*func)(void* data), void* data) 137 | { 138 | msgpack_zone_finalizer_array* const fa = &zone->finalizer_array; 139 | msgpack_zone_finalizer* tmp; 140 | 141 | const size_t nused = (size_t)(fa->end - fa->array); 142 | 143 | size_t nnext; 144 | if(nused == 0) { 145 | nnext = (sizeof(msgpack_zone_finalizer) < 72/2) ? 146 | 72 / sizeof(msgpack_zone_finalizer) : 8; 147 | 148 | } else { 149 | nnext = nused * 2; 150 | } 151 | 152 | tmp = (msgpack_zone_finalizer*)realloc(fa->array, 153 | sizeof(msgpack_zone_finalizer) * nnext); 154 | if(tmp == NULL) { 155 | return false; 156 | } 157 | 158 | fa->array = tmp; 159 | fa->end = tmp + nnext; 160 | fa->tail = tmp + nused; 161 | 162 | fa->tail->func = func; 163 | fa->tail->data = data; 164 | 165 | ++fa->tail; 166 | 167 | return true; 168 | } 169 | 170 | 171 | bool msgpack_zone_is_empty(msgpack_zone* zone) 172 | { 173 | msgpack_zone_chunk_list* const cl = &zone->chunk_list; 174 | msgpack_zone_finalizer_array* const fa = &zone->finalizer_array; 175 | return cl->free == zone->chunk_size && cl->head->next == NULL && 176 | fa->tail == fa->array; 177 | } 178 | 179 | 180 | void msgpack_zone_destroy(msgpack_zone* zone) 181 | { 182 | destroy_finalizer_array(&zone->finalizer_array); 183 | destroy_chunk_list(&zone->chunk_list); 184 | } 185 | 186 | void msgpack_zone_clear(msgpack_zone* zone) 187 | { 188 | clear_finalizer_array(&zone->finalizer_array); 189 | clear_chunk_list(&zone->chunk_list, zone->chunk_size); 190 | } 191 | 192 | bool msgpack_zone_init(msgpack_zone* zone, size_t chunk_size) 193 | { 194 | zone->chunk_size = chunk_size; 195 | 196 | if(!init_chunk_list(&zone->chunk_list, chunk_size)) { 197 | return false; 198 | } 199 | 200 | init_finalizer_array(&zone->finalizer_array); 201 | 202 | return true; 203 | } 204 | 205 | msgpack_zone* msgpack_zone_new(size_t chunk_size) 206 | { 207 | msgpack_zone* zone = (msgpack_zone*)malloc( 208 | sizeof(msgpack_zone)); 209 | if(zone == NULL) { 210 | return NULL; 211 | } 212 | 213 | zone->chunk_size = chunk_size; 214 | 215 | if(!init_chunk_list(&zone->chunk_list, chunk_size)) { 216 | free(zone); 217 | return NULL; 218 | } 219 | 220 | init_finalizer_array(&zone->finalizer_array); 221 | 222 | return zone; 223 | } 224 | 225 | void msgpack_zone_free(msgpack_zone* zone) 226 | { 227 | if(zone == NULL) { return; } 228 | msgpack_zone_destroy(zone); 229 | free(zone); 230 | } 231 | -------------------------------------------------------------------------------- /lib/msgpack.js: -------------------------------------------------------------------------------- 1 | // Wrap a nicer JavaScript API that wraps the direct MessagePack bindings. 2 | 3 | var buffer = require('buffer'); 4 | var events = require('events'); 5 | var mpBindings; 6 | mpBindings = require(__dirname + "/../build/Release/msgpackBinding"); 7 | 8 | var sys; 9 | try { 10 | sys = require('util'); 11 | } catch (e) { 12 | sys = require('sys'); 13 | } 14 | 15 | var bpack = mpBindings.pack; 16 | var unpack = mpBindings.unpack; 17 | 18 | exports.pack = pack; 19 | exports.unpack = unpack; 20 | 21 | function pack() { 22 | var args = arguments, that, i; 23 | for (i = 0; i < arguments.length; i++) { 24 | that = args[i]; 25 | if (that && typeof that === 'object' && 26 | typeof that.toJSON === 'function') { 27 | args[i] = that.toJSON(); 28 | } 29 | } 30 | return bpack.apply(null, args); 31 | } 32 | 33 | var Stream = function(s) { 34 | var self = this; 35 | 36 | events.EventEmitter.call(self); 37 | 38 | // Buffer of incomplete stream data 39 | self.buf = null; 40 | 41 | // Send a message down the stream 42 | // 43 | // Allows the caller to pass additional arguments, which are passed 44 | // faithfully down to the write() method of the underlying stream. 45 | self.send = function(m) { 46 | // Sigh, no arguments.slice() method 47 | var args = [pack(m)]; 48 | for (i = 1; i < arguments.length; i++) { 49 | args.push(arguments[i]); 50 | } 51 | 52 | return s.write.apply(s, args); 53 | }; 54 | 55 | // Listen for data from the underlying stream, consuming it and emitting 56 | // 'msg' events as we find whole messages. 57 | s.addListener('data', function(d) { 58 | // Make sure that self.buf reflects the entirety of the unread stream 59 | // of bytes; it needs to be a single buffer 60 | if (self.buf) { 61 | var b = new buffer.Buffer(self.buf.length + d.length); 62 | self.buf.copy(b, 0, 0, self.buf.length); 63 | d.copy(b, self.buf.length, 0, d.length); 64 | 65 | self.buf = b; 66 | } else { 67 | self.buf = d; 68 | } 69 | 70 | // Consume messages from the stream, one by one 71 | while (self.buf && self.buf.length > 0) { 72 | var msg = unpack(self.buf); 73 | if (!msg) { 74 | break; 75 | } 76 | 77 | self.emit('msg', msg); 78 | if (unpack.bytes_remaining > 0) { 79 | self.buf = self.buf.slice( 80 | self.buf.length - unpack.bytes_remaining, 81 | self.buf.length 82 | ); 83 | } else { 84 | self.buf = null; 85 | } 86 | } 87 | }); 88 | }; 89 | 90 | sys.inherits(Stream, events.EventEmitter); 91 | exports.Stream = Stream; 92 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "msgpack", 3 | "description": "A space-efficient object serialization library for node.js", 4 | "version": "1.0.3", 5 | "homepage": "https://github.com/msgpack/msgpack-node", 6 | "contributors": [ 7 | { 8 | "name": "Amos Barreto", 9 | "url": "https://github.com/squamos" 10 | }, 11 | { 12 | "name": "Peter Griess", 13 | "url": "https://github.com/pgriess", 14 | "email": "pg@std.in" 15 | }, 16 | { 17 | "name": "Maxwell Krohn", 18 | "url": "https://github.com/maxtaco" 19 | }, 20 | { 21 | "name": "Jaye Marshall", 22 | "url": "https://github.com/jmars" 23 | }, 24 | { 25 | "name": "matthiasg", 26 | "url": "https://github.com/matthiasg" 27 | }, 28 | { 29 | "name": "Christopher Mooney", 30 | "url": "https://github.com/godsflaw", 31 | "email": "chris@dod.net" 32 | }, 33 | { 34 | "name": "Michael Phan-Ba", 35 | "url": "https://github.com/mikepb" 36 | }, 37 | { 38 | "name": "Bob Potter", 39 | "url": "https://github.com/bpot" 40 | }, 41 | { 42 | "name": "rashfael", 43 | "url": "https://github.com/rashfael" 44 | }, 45 | { 46 | "name": "Tom Taylor", 47 | "email": "tom@tomtaylor.co.uk", 48 | "url": "https://github.com/tomtaylor" 49 | }, 50 | { 51 | "name": "Brian White", 52 | "url": "https://github.com/mscdex" 53 | }, 54 | { 55 | "name": "Keiji Yoshimi", 56 | "url": "https://github.com/walf443" 57 | } 58 | ], 59 | "repository": { 60 | "type": "git", 61 | "url": "https://github.com/msgpack/msgpack-node.git" 62 | }, 63 | "main": "./lib/msgpack", 64 | "directories": { 65 | "lib": "lib" 66 | }, 67 | "dependencies": { 68 | "nan": "^2.14.0" 69 | }, 70 | "devDependencies": { 71 | "nodeunit": "https://github.com/godsflaw/nodeunit/archive/master.tar.gz" 72 | }, 73 | "engines": { 74 | "node": ">=0.12.7" 75 | }, 76 | "bin": { 77 | "json2msgpack": "./bin/json2msgpack", 78 | "msgpack2json": "./bin/msgpack2json" 79 | }, 80 | "scripts": { 81 | "test": "./run_tests" 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /run_tests: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | 3 | "use strict"; 4 | 5 | try { 6 | var reporter = require('nodeunit').reporters.default; 7 | } 8 | catch(e) { 9 | console.log("Error: " + e.message); 10 | console.log(""); 11 | console.log("Cannot find required modules."); 12 | console.log("You can intall modules for this project by doing:"); 13 | console.log(""); 14 | console.log(" npm install"); 15 | console.log(""); 16 | process.exit(); 17 | } 18 | 19 | process.chdir(__dirname); 20 | 21 | if (process.argv[2]) { 22 | reporter.run(process.argv.slice(2, process.argv.length)); 23 | } else { 24 | reporter.run(['test', 'test/lib'], undefined, function () { 25 | process.exit(); 26 | }); 27 | } 28 | -------------------------------------------------------------------------------- /test/benchmark/benchmark.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | msgpack = require("../../lib/msgpack"), 3 | stub = require("../fixtures/stub"); 4 | 5 | var DATA_TEMPLATE = {'abcdef' : 1, 'qqq' : 13, '19' : [1, 2, 3, 4]}; 6 | var DATA = []; 7 | 8 | for (var i = 0; i < 1000000; i++) { 9 | DATA.push(JSON.parse(JSON.stringify(DATA_TEMPLATE))); 10 | } 11 | 12 | function _set_up(callback) { 13 | this.backup = {}; 14 | callback(); 15 | } 16 | 17 | function _tear_down(callback) { 18 | callback(); 19 | } 20 | 21 | exports.benchmark = { 22 | setUp : _set_up, 23 | tearDown : _tear_down, 24 | 'JSON.stringify faster than msgpack.pack with array of 1m objects' : function (test) { 25 | console.log(); 26 | var jsonStr; 27 | var now = Date.now(); 28 | jsonStr = JSON.stringify(DATA); 29 | var stringifyTime = (Date.now() - now); 30 | 31 | var mpBuf; 32 | now = Date.now(); 33 | mpBuf = msgpack.pack(DATA); 34 | var packTime = (Date.now() - now); 35 | 36 | console.log( 37 | "msgpack.pack: "+packTime+"ms, JSON.stringify: "+stringifyTime+"ms" 38 | ); 39 | console.log( 40 | "ratio of JSON.stringify/msgpack.pack: " + stringifyTime/packTime 41 | ); 42 | test.expect(1); 43 | test.ok( 44 | packTime > stringifyTime, 45 | "msgpack.pack: "+packTime+"ms, JSON.stringify: "+stringifyTime+"ms" 46 | ); 47 | test.done(); 48 | }, 49 | // 'JSON.parse faster than msgpack.unpack with array of 1m objects' : function (test) { 50 | // console.log(); 51 | // var jsonStr; 52 | // jsonStr = JSON.stringify(DATA); 53 | // 54 | // var mpBuf; 55 | // mpBuf = msgpack.pack(DATA); 56 | // 57 | // var now = Date.now(); 58 | // JSON.parse(jsonStr); 59 | // var parseTime = (Date.now() - now); 60 | // 61 | // now = Date.now(); 62 | // msgpack.unpack(mpBuf); 63 | // var unpackTime = (Date.now() - now); 64 | // 65 | // console.log( 66 | // "msgpack.unpack: "+unpackTime+"ms, JSON.parse: "+parseTime+"ms" 67 | // ); 68 | // console.log("ratio of parseTime/msgpack.unpack: " + parseTime/unpackTime); 69 | // test.expect(1); 70 | // test.ok( 71 | // unpackTime > parseTime, 72 | // "msgpack.unpack: "+unpackTime+"ms, JSON.parse: "+parseTime+"ms" 73 | // ); 74 | // test.done(); 75 | // }, 76 | 'JSON.stringify faster than msgpack.pack over 1m calls' : function (test) { 77 | console.log(); 78 | 79 | var jsonStr; 80 | var now = Date.now(); 81 | DATA.forEach(function(d) { 82 | jsonStr = JSON.stringify(d); 83 | }); 84 | var stringifyTime = (Date.now() - now); 85 | 86 | var mpBuf; 87 | now = Date.now(); 88 | DATA.forEach(function(d) { 89 | mpBuf = msgpack.pack(d); 90 | }); 91 | var packTime = (Date.now() - now); 92 | 93 | console.log( 94 | "msgpack.pack: "+packTime+"ms, JSON.stringify: "+stringifyTime+"ms" 95 | ); 96 | console.log( 97 | "ratio of msgpack.pack/JSON.stringify: " + packTime/stringifyTime 98 | ); 99 | test.expect(1); 100 | test.ok( 101 | stringifyTime < packTime && packTime/stringifyTime < 6, 102 | "msgpack.pack: "+packTime+"ms, JSON.stringify: "+stringifyTime+"ms" 103 | ); 104 | test.done(); 105 | }, 106 | 'JSON.parse faster than msgpack.unpack over 1m calls' : function (test) { 107 | console.log(); 108 | var jsonStr; 109 | 110 | DATA.forEach(function(d) { 111 | jsonStr = JSON.stringify(d); 112 | }); 113 | 114 | var mpBuf; 115 | DATA.forEach(function(d) { 116 | mpBuf = msgpack.pack(d); 117 | }); 118 | 119 | var now = Date.now(); 120 | DATA.forEach(function(d) { 121 | JSON.parse(jsonStr); 122 | }); 123 | var parseTime = (Date.now() - now); 124 | 125 | now = Date.now(); 126 | DATA.forEach(function(d) { 127 | msgpack.unpack(mpBuf); 128 | }); 129 | var unpackTime = (Date.now() - now); 130 | 131 | console.log( 132 | "msgpack.unpack: "+unpackTime+"ms, JSON.parse: "+parseTime+"ms" 133 | ); 134 | console.log("ratio of JSON.parse/msgpack.unpack: " + unpackTime/parseTime); 135 | test.expect(1); 136 | test.ok( 137 | parseTime < unpackTime && unpackTime/parseTime < 5, 138 | "msgpack.unpack: "+unpackTime+"ms, JSON.parse: "+parseTime+"ms" 139 | ); 140 | test.done(); 141 | }, 142 | 'output above is from three runs on a 1m element array of objects' : function (test) { 143 | console.log(); 144 | for (var i = 0; i < 3; i++) { 145 | var mpBuf; 146 | var now = Date.now(); 147 | mpBuf = msgpack.pack(DATA); 148 | console.log('msgpack pack: ' + (Date.now() - now) + ' ms'); 149 | 150 | now = Date.now(); 151 | msgpack.unpack(mpBuf); 152 | console.log('msgpack unpack: ' + (Date.now() - now) + ' ms'); 153 | 154 | var jsonStr; 155 | now = Date.now(); 156 | jsonStr = JSON.stringify(DATA); 157 | console.log('json pack: ' + (Date.now() - now) + ' ms'); 158 | 159 | now = Date.now(); 160 | JSON.parse(jsonStr); 161 | console.log('json unpack: ' + (Date.now() - now) + ' ms'); 162 | console.log(); 163 | } 164 | 165 | test.expect(1); 166 | test.ok(1); 167 | test.done(); 168 | }, 169 | 'output above is from three runs of 1m individual calls' : function (test) { 170 | console.log(); 171 | for (var i = 0; i < 3; i++) { 172 | var mpBuf; 173 | var now = Date.now(); 174 | DATA.forEach(function(d) { 175 | mpBuf = msgpack.pack(d); 176 | }); 177 | console.log('msgpack pack: ' + (Date.now() - now) + ' ms'); 178 | 179 | now = Date.now(); 180 | DATA.forEach(function(d) { 181 | msgpack.unpack(mpBuf); 182 | }); 183 | console.log('msgpack unpack: ' + (Date.now() - now) + ' ms'); 184 | 185 | var jsonStr; 186 | now = Date.now(); 187 | DATA.forEach(function(d) { 188 | jsonStr = JSON.stringify(d); 189 | }); 190 | console.log('json pack: ' + (Date.now() - now) + ' ms'); 191 | 192 | now = Date.now(); 193 | DATA.forEach(function(d) { 194 | JSON.parse(jsonStr); 195 | }); 196 | console.log('json unpack: ' + (Date.now() - now) + ' ms'); 197 | console.log(); 198 | } 199 | 200 | test.expect(1); 201 | test.ok(1); 202 | test.done(); 203 | } 204 | }; 205 | -------------------------------------------------------------------------------- /test/fixtures/stub.js: -------------------------------------------------------------------------------- 1 | module.exports = function (returnValue) { 2 | function stub() { 3 | stub.called = true; 4 | stub.args = arguments; 5 | stub.thisArg = this; 6 | return returnValue; 7 | } 8 | 9 | stub.called = false; 10 | 11 | return stub; 12 | }; 13 | -------------------------------------------------------------------------------- /test/regression.js: -------------------------------------------------------------------------------- 1 | var fs = require('fs'), 2 | msgpack = require("../lib/msgpack"), 3 | stub = require("./fixtures/stub"); 4 | 5 | function _set_up(callback) { 6 | this.backup = {}; 7 | callback(); 8 | } 9 | 10 | function _tear_down(callback) { 11 | callback(); 12 | } 13 | 14 | exports.regression = { 15 | setUp : _set_up, 16 | tearDown : _tear_down, 17 | 'https://github.com/pgriess/node-msgpack/issues/15' : function (test) { 18 | var obj = {a:123}; 19 | var fileName = './packed-data'; 20 | var packedObj = msgpack.pack(obj); 21 | test.expect(2); 22 | fs.writeFileSync(fileName, packedObj); 23 | packedObj2 = fs.readFileSync(fileName); 24 | test.deepEqual(packedObj, packedObj2); 25 | var unpackedObj = msgpack.unpack(packedObj2); // crash 26 | test.deepEqual(obj, unpackedObj); 27 | fs.unlinkSync(fileName); 28 | test.done(); 29 | }, 30 | 'https://github.com/msgpack/msgpack-node/issues/5' : function (test) { 31 | var originalArray = ['one', 'two']; 32 | var packedArray = msgpack.pack(originalArray); 33 | var buffer = new Buffer(packedArray.toString('binary'), 'binary'); 34 | test.expect(3); 35 | unpackedArray = msgpack.unpack(buffer); 36 | test.isArray(originalArray); 37 | test.isArray(unpackedArray); 38 | test.deepEqual(originalArray, unpackedArray); 39 | test.done(); 40 | } 41 | }; 42 | --------------------------------------------------------------------------------