mirror of
				https://github.com/msgpack/msgpack-c.git
				synced 2025-10-22 08:02:08 +02:00 
			
		
		
		
	Compare commits
	
		
			14 Commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|   | c6e6dbc608 | ||
|   | e271cf2aed | ||
|   | 53e4bb92fe | ||
|   | 303c1000c2 | ||
|   | 088ce946b9 | ||
|   | dc86adbf8e | ||
|   | ad0cae30ad | ||
|   | bf3e2abc9e | ||
|   | b7543e1386 | ||
|   | 1f515b3ae7 | ||
|   | a933fa5892 | ||
|   | a07622c276 | ||
|   | c955727d8c | ||
|   | 094b70213a | 
| @@ -1,3 +1,10 @@ | ||||
| # 2017-02-04 version 2.1.1 | ||||
|  | ||||
|   * Fix unpacker's buffer management bug (#561) | ||||
|   * Add boost string_view adaptor (#558) | ||||
|   * Remove some warnings (#557, #559) | ||||
|   * Improve coding style (#556) | ||||
|  | ||||
| # 2017-01-10 version 2.1.0 | ||||
|  | ||||
| ## << breaking changes >> | ||||
|   | ||||
| @@ -165,6 +165,7 @@ IF (MSGPACK_ENABLE_CXX) | ||||
|         include/msgpack/adaptor/boost/msgpack_variant_decl.hpp | ||||
|         include/msgpack/adaptor/boost/optional.hpp | ||||
|         include/msgpack/adaptor/boost/string_ref.hpp | ||||
|         include/msgpack/adaptor/boost/string_view.hpp | ||||
|         include/msgpack/adaptor/carray.hpp | ||||
|         include/msgpack/adaptor/char_ptr.hpp | ||||
|         include/msgpack/adaptor/check_container_size.hpp | ||||
| @@ -512,6 +513,7 @@ IF (MSGPACK_ENABLE_CXX) | ||||
|         include/msgpack/v1/adaptor/boost/msgpack_variant_decl.hpp | ||||
|         include/msgpack/v1/adaptor/boost/optional.hpp | ||||
|         include/msgpack/v1/adaptor/boost/string_ref.hpp | ||||
|         include/msgpack/v1/adaptor/boost/string_view.hpp | ||||
|         include/msgpack/v1/adaptor/carray.hpp | ||||
|         include/msgpack/v1/adaptor/char_ptr.hpp | ||||
|         include/msgpack/v1/adaptor/check_container_size.hpp | ||||
|   | ||||
| @@ -1,7 +1,7 @@ | ||||
| `msgpack` for C/C++ | ||||
| =================== | ||||
|  | ||||
| Version 2.1.0 [](https://travis-ci.org/msgpack/msgpack-c) [](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master) | ||||
| Version 2.1.1 [](https://travis-ci.org/msgpack/msgpack-c) [](https://ci.appveyor.com/project/redboltz/msgpack-c/branch/master) | ||||
|  | ||||
| It's like JSON but small and fast. | ||||
|  | ||||
|   | ||||
							
								
								
									
										12
									
								
								appveyor.yml
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								appveyor.yml
									
									
									
									
									
								
							| @@ -33,10 +33,10 @@ build_script: | ||||
| - cmake --build . --config Release | ||||
| - cd .. | ||||
| - cd .. | ||||
| - appveyor DownloadFile http://zlib.net/zlib-1.2.10.tar.gz -FileName zlib-1.2.10.tar.gz | ||||
| - 7z x zlib-1.2.10.tar.gz > NUL | ||||
| - 7z x zlib-1.2.10.tar > NUL | ||||
| - cd zlib-1.2.10 | ||||
| - appveyor DownloadFile http://zlib.net/zlib-1.2.11.tar.gz -FileName zlib-1.2.11.tar.gz | ||||
| - 7z x zlib-1.2.11.tar.gz > NUL | ||||
| - 7z x zlib-1.2.11.tar > NUL | ||||
| - cd zlib-1.2.11 | ||||
| - md build | ||||
| - cd build | ||||
| - cmake -G %msvc% .. | ||||
| @@ -46,9 +46,9 @@ build_script: | ||||
| - cd .. | ||||
| - md build | ||||
| - cd build | ||||
| - cmake -G %msvc% %cpp11% %boost% %x3_parse%  -DMSGPACK_BOOST_DIR=C:\Libraries\\boost_1_60_0 -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.10\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.10 -DCMAKE_CXX_FLAGS='"/D_VARIADIC_MAX=10 /EHsc"' .. | ||||
| - cmake -G %msvc% %cpp11% %boost% %x3_parse%  -DMSGPACK_BOOST_DIR=C:\Libraries\\boost_1_60_0 -DGTEST_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest.lib -DGTEST_MAIN_LIBRARY=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release\gtest_main.lib -DGTEST_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\include -DZLIB_LIBRARY=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.11\build\Release\zlib.lib -DZLIB_INCLUDE_DIR=%APPVEYOR_BUILD_FOLDER%\zlib-1.2.11 -DCMAKE_CXX_FLAGS='"/D_VARIADIC_MAX=10 /EHsc"' .. | ||||
| - cmake --build . --config Release | ||||
|  | ||||
| test_script: | ||||
| - set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.10\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release | ||||
| - set PATH=%PATH%;%APPVEYOR_BUILD_FOLDER%\googletest-release-1.7.0\build\Release;%APPVEYOR_BUILD_FOLDER%\zlib-1.2.11\build\Release;%APPVEYOR_BUILD_FOLDER%\build\release | ||||
| - ctest -V | ||||
|   | ||||
							
								
								
									
										15
									
								
								include/msgpack/adaptor/boost/string_view.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								include/msgpack/adaptor/boost/string_view.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | ||||
| // | ||||
| // MessagePack for C++ static resolution routine | ||||
| // | ||||
| // Copyright (C) 2017 KONDO Takatoshi | ||||
| // | ||||
| //    Distributed under the Boost Software License, Version 1.0. | ||||
| //    (See accompanying file LICENSE_1_0.txt or copy at | ||||
| //    http://www.boost.org/LICENSE_1_0.txt) | ||||
| // | ||||
| #ifndef MSGPACK_TYPE_BOOST_STRING_VIEW_HPP | ||||
| #define MSGPACK_TYPE_BOOST_STRING_VIEW_HPP | ||||
|  | ||||
| #include "msgpack/v1/adaptor/boost/string_view.hpp" | ||||
|  | ||||
| #endif // MSGPACK_TYPE_BOOST_STRING_VIEW_HPP | ||||
| @@ -50,5 +50,6 @@ | ||||
| #include "adaptor/boost/msgpack_variant.hpp" | ||||
| #include "adaptor/boost/optional.hpp" | ||||
| #include "adaptor/boost/string_ref.hpp" | ||||
| #include "adaptor/boost/string_view.hpp" | ||||
|  | ||||
| #endif // defined(MSGPACK_USE_BOOST) | ||||
|   | ||||
							
								
								
									
										87
									
								
								include/msgpack/v1/adaptor/boost/string_view.hpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										87
									
								
								include/msgpack/v1/adaptor/boost/string_view.hpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,87 @@ | ||||
| // | ||||
| // MessagePack for C++ static resolution routine | ||||
| // | ||||
| // Copyright (C) 2017 KONDO Takatoshi | ||||
| // | ||||
| //    Distributed under the Boost Software License, Version 1.0. | ||||
| //    (See accompanying file LICENSE_1_0.txt or copy at | ||||
| //    http://www.boost.org/LICENSE_1_0.txt) | ||||
| // | ||||
| #ifndef MSGPACK_V1_TYPE_BOOST_STRING_VIEW_HPP | ||||
| #define MSGPACK_V1_TYPE_BOOST_STRING_VIEW_HPP | ||||
|  | ||||
| #include <boost/version.hpp> | ||||
| #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 61 | ||||
|  | ||||
| #include "msgpack/versioning.hpp" | ||||
| #include "msgpack/adaptor/adaptor_base.hpp" | ||||
| #include "msgpack/adaptor/check_container_size.hpp" | ||||
|  | ||||
| #include <boost/utility/string_view.hpp> | ||||
|  | ||||
| namespace msgpack { | ||||
|  | ||||
| /// @cond | ||||
| MSGPACK_API_VERSION_NAMESPACE(v1) { | ||||
| /// @endcond | ||||
|  | ||||
| namespace adaptor { | ||||
|  | ||||
| template <> | ||||
| struct convert<boost::string_view> { | ||||
|     msgpack::object const& operator()(msgpack::object const& o, boost::string_view& v) const { | ||||
|         switch (o.type) { | ||||
|         case msgpack::type::BIN: | ||||
|             v = boost::string_view(o.via.bin.ptr, o.via.bin.size); | ||||
|             break; | ||||
|         case msgpack::type::STR: | ||||
|             v = boost::string_view(o.via.str.ptr, o.via.str.size); | ||||
|             break; | ||||
|         default: | ||||
|             throw msgpack::type_error(); | ||||
|             break; | ||||
|         } | ||||
|         return o; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct pack<boost::string_view> { | ||||
|     template <typename Stream> | ||||
|     msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const boost::string_view& v) const { | ||||
|         uint32_t size = checked_get_container_size(v.size()); | ||||
|         o.pack_str(size); | ||||
|         o.pack_str_body(v.data(), size); | ||||
|         return o; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct object<boost::string_view> { | ||||
|     void operator()(msgpack::object& o, const boost::string_view& v) const { | ||||
|         uint32_t size = checked_get_container_size(v.size()); | ||||
|         o.type = msgpack::type::STR; | ||||
|         o.via.str.ptr = v.data(); | ||||
|         o.via.str.size = size; | ||||
|     } | ||||
| }; | ||||
|  | ||||
| template <> | ||||
| struct object_with_zone<boost::string_view> { | ||||
|     void operator()(msgpack::object::with_zone& o, const boost::string_view& v) const { | ||||
|         static_cast<msgpack::object&>(o) << v; | ||||
|     } | ||||
| }; | ||||
|  | ||||
|  | ||||
| } // namespace adaptor | ||||
|  | ||||
| /// @cond | ||||
| } // MSGPACK_API_VERSION_NAMESPACE(v1) | ||||
| /// @endcond | ||||
|  | ||||
| } // namespace msgpack | ||||
|  | ||||
| #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 53 | ||||
|  | ||||
| #endif // MSGPACK_V1_TYPE_BOOST_STRING_VIEW_HPP | ||||
| @@ -101,7 +101,7 @@ struct pack<char[N]> { | ||||
|         char const* p = v; | ||||
|         uint32_t size = checked_get_container_size(N); | ||||
|         char const* p2 = static_cast<char const*>(std::memchr(p, '\0', size)); | ||||
|         uint32_t adjusted_size = p2 ? p2 - p : size; | ||||
|         uint32_t adjusted_size = p2 ? static_cast<uint32_t>(p2 - p) : size; | ||||
|         o.pack_str(adjusted_size); | ||||
|         o.pack_str_body(p, adjusted_size); | ||||
|         return o; | ||||
| @@ -115,7 +115,7 @@ struct pack<const char[N]> { | ||||
|         uint32_t size = checked_get_container_size(N); | ||||
|         char const* p = v; | ||||
|         char const* p2 = static_cast<char const*>(std::memchr(p, '\0', size)); | ||||
|         uint32_t adjusted_size = p2 ? p2 - p : size; | ||||
|         uint32_t adjusted_size = p2 ? static_cast<uint32_t>(p2 - p) : size; | ||||
|         o.pack_str(adjusted_size); | ||||
|         o.pack_str_body(p, adjusted_size); | ||||
|         return o; | ||||
| @@ -167,7 +167,7 @@ struct object_with_zone<char[N]> { | ||||
|         char const* p = v; | ||||
|         uint32_t size = checked_get_container_size(N); | ||||
|         char const* p2 = static_cast<char const*>(std::memchr(p, '\0', size)); | ||||
|         uint32_t adjusted_size = p2 ? p2 - p : size; | ||||
|         uint32_t adjusted_size = p2 ? static_cast<uint32_t>(p2 - p) : size; | ||||
|         o.type = msgpack::type::STR; | ||||
|         char* ptr = static_cast<char*>(o.zone.allocate_align(adjusted_size)); | ||||
|         o.via.str.ptr = ptr; | ||||
| @@ -182,7 +182,7 @@ struct object_with_zone<const char[N]> { | ||||
|         char const* p = v; | ||||
|         uint32_t size = checked_get_container_size(N); | ||||
|         char const* p2 = static_cast<char const*>(std::memchr(p, '\0', size)); | ||||
|         uint32_t adjusted_size = p2 ? p2 - p : size; | ||||
|         uint32_t adjusted_size = p2 ? static_cast<uint32_t>(p2 - p) : size; | ||||
|         o.type = msgpack::type::STR; | ||||
|         char* ptr = static_cast<char*>(o.zone.allocate_align(adjusted_size)); | ||||
|         o.via.str.ptr = ptr; | ||||
| @@ -221,7 +221,7 @@ struct object<char[N]> { | ||||
|         char const* p = v; | ||||
|         uint32_t size = checked_get_container_size(N); | ||||
|         char const* p2 = static_cast<char const*>(std::memchr(p, '\0', size)); | ||||
|         uint32_t adjusted_size = p2 ? p2 - p : size; | ||||
|         uint32_t adjusted_size = p2 ? static_cast<uint32_t>(p2 - p) : size; | ||||
|         o.type = msgpack::type::STR; | ||||
|         o.via.str.ptr = p; | ||||
|         o.via.str.size = adjusted_size; | ||||
| @@ -234,7 +234,7 @@ struct object<const char[N]> { | ||||
|         char const* p = v; | ||||
|         uint32_t size = checked_get_container_size(N); | ||||
|         char const* p2 = static_cast<char const*>(std::memchr(p, '\0', size)); | ||||
|         uint32_t adjusted_size = p2 ? p2 - p : size; | ||||
|         uint32_t adjusted_size = p2 ? static_cast<uint32_t>(p2 - p) : size; | ||||
|         o.type = msgpack::type::STR; | ||||
|         o.via.str.ptr = p; | ||||
|         o.via.str.size = adjusted_size; | ||||
|   | ||||
| @@ -459,7 +459,7 @@ inline parse_return context<VisitorHolder>::execute(const char* data, std::size_ | ||||
|                 load<uint8_t>(tmp, n); | ||||
|                 m_trail = tmp + 1; | ||||
|                 if(m_trail == 0) { | ||||
|                     bool visret = holder().visitor().visit_ext(n, m_trail); | ||||
|                     bool visret = holder().visitor().visit_ext(n, static_cast<uint32_t>(m_trail)); | ||||
|                     parse_return upr = after_visit_proc(visret, off); | ||||
|                     if (upr != PARSE_CONTINUE) return upr; | ||||
|                 } | ||||
| @@ -501,7 +501,7 @@ inline parse_return context<VisitorHolder>::execute(const char* data, std::size_ | ||||
|                 load<uint16_t>(tmp, n); | ||||
|                 m_trail = tmp + 1; | ||||
|                 if(m_trail == 0) { | ||||
|                     bool visret = holder().visitor().visit_ext(n, m_trail); | ||||
|                     bool visret = holder().visitor().visit_ext(n, static_cast<uint32_t>(m_trail)); | ||||
|                     parse_return upr = after_visit_proc(visret, off); | ||||
|                     if (upr != PARSE_CONTINUE) return upr; | ||||
|                 } | ||||
| @@ -545,7 +545,7 @@ inline parse_return context<VisitorHolder>::execute(const char* data, std::size_ | ||||
|                 m_trail = tmp; | ||||
|                 ++m_trail; | ||||
|                 if(m_trail == 0) { | ||||
|                     bool visret = holder().visitor().visit_ext(n, m_trail); | ||||
|                     bool visret = holder().visitor().visit_ext(n, static_cast<uint32_t>(m_trail)); | ||||
|                     parse_return upr = after_visit_proc(visret, off); | ||||
|                     if (upr != PARSE_CONTINUE) return upr; | ||||
|                 } | ||||
| @@ -555,7 +555,7 @@ inline parse_return context<VisitorHolder>::execute(const char* data, std::size_ | ||||
|                 } | ||||
|             } break; | ||||
|             case MSGPACK_ACS_STR_VALUE: { | ||||
|                 bool visret = holder().visitor().visit_str(n, m_trail); | ||||
|                 bool visret = holder().visitor().visit_str(n, static_cast<uint32_t>(m_trail)); | ||||
|                 parse_return upr = after_visit_proc(visret, off); | ||||
|                 if (upr != PARSE_CONTINUE) return upr; | ||||
|             } break; | ||||
| @@ -565,7 +565,7 @@ inline parse_return context<VisitorHolder>::execute(const char* data, std::size_ | ||||
|                 if (upr != PARSE_CONTINUE) return upr; | ||||
|             } break; | ||||
|             case MSGPACK_ACS_EXT_VALUE: { | ||||
|                 bool visret = holder().visitor().visit_ext(n, m_trail); | ||||
|                 bool visret = holder().visitor().visit_ext(n, static_cast<uint32_t>(m_trail)); | ||||
|                 parse_return upr = after_visit_proc(visret, off); | ||||
|                 if (upr != PARSE_CONTINUE) return upr; | ||||
|             } break; | ||||
| @@ -839,7 +839,7 @@ template <typename VisitorHolder, typename ReferencedBufferHook> | ||||
| inline void parser<VisitorHolder, ReferencedBufferHook>::expand_buffer(std::size_t size) | ||||
| { | ||||
|     if(m_used == m_off && detail::get_count(m_buffer) == 1 | ||||
|        && static_cast<VisitorHolder&>(*this).visitor().referenced()) { | ||||
|        && !static_cast<VisitorHolder&>(*this).visitor().referenced()) { | ||||
|         // rewind buffer | ||||
|         m_free += m_used - COUNTER_SIZE; | ||||
|         m_used = COUNTER_SIZE; | ||||
|   | ||||
| @@ -1,3 +1,3 @@ | ||||
| #define MSGPACK_VERSION_MAJOR    2 | ||||
| #define MSGPACK_VERSION_MINOR    1 | ||||
| #define MSGPACK_VERSION_REVISION 0 | ||||
| #define MSGPACK_VERSION_REVISION 1 | ||||
|   | ||||
| @@ -122,7 +122,7 @@ static void msgpack_object_bin_print(FILE* out, const char *ptr, size_t size) | ||||
|     for (i = 0; i < size; ++i) { | ||||
|         if (ptr[i] == '"') { | ||||
|             fputs("\\\"", out); | ||||
|         } else if (isprint(ptr[i])) { | ||||
|         } else if (isprint((unsigned char)ptr[i])) { | ||||
|             fputc(ptr[i], out); | ||||
|         } else { | ||||
|             fprintf(out, "\\x%02x", (unsigned char)ptr[i]); | ||||
| @@ -142,7 +142,7 @@ static int msgpack_object_bin_print_buffer(char *buffer, size_t buffer_size, con | ||||
|             ret = snprintf(aux_buffer, aux_buffer_size, "\\\""); | ||||
|             aux_buffer = aux_buffer + ret; | ||||
|             aux_buffer_size = aux_buffer_size - ret; | ||||
|         } else if (isprint(ptr[i])) { | ||||
|         } else if (isprint((unsigned char)ptr[i])) { | ||||
|             if (aux_buffer_size > 0) { | ||||
|                 memcpy(aux_buffer, ptr + i, 1); | ||||
|                 aux_buffer = aux_buffer + 1; | ||||
|   | ||||
| @@ -45,6 +45,7 @@ IF (MSGPACK_BOOST) | ||||
|         boost_variant.cpp | ||||
|         boost_optional.cpp | ||||
|         boost_string_ref.cpp | ||||
|         boost_string_view.cpp | ||||
|     ) | ||||
| ENDIF () | ||||
|  | ||||
|   | ||||
							
								
								
									
										47
									
								
								test/boost_string_view.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										47
									
								
								test/boost_string_view.cpp
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,47 @@ | ||||
| #include <msgpack.hpp> | ||||
| #include <sstream> | ||||
| #include <iterator> | ||||
| #include <gtest/gtest.h> | ||||
|  | ||||
| #ifdef HAVE_CONFIG_H | ||||
| #include "config.h" | ||||
| #endif | ||||
|  | ||||
| #if defined(MSGPACK_USE_BOOST) | ||||
| #if (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 61 | ||||
|  | ||||
| TEST(MSGPACK_BOOST, pack_convert_string_view) | ||||
| { | ||||
|     std::stringstream ss; | ||||
|     std::string s = "ABC"; | ||||
|     boost::string_view val1(s); | ||||
|  | ||||
|     msgpack::pack(ss, val1); | ||||
|  | ||||
|     msgpack::object_handle oh; | ||||
|     msgpack::unpack(oh, ss.str().data(), ss.str().size()); | ||||
|     boost::string_view val2 = oh.get().as<boost::string_view>(); | ||||
|     EXPECT_TRUE(val1 == val2); | ||||
| } | ||||
|  | ||||
| TEST(MSGPACK_BOOST, object_strinf_view) | ||||
| { | ||||
|     std::string s = "ABC"; | ||||
|     boost::string_view val1(s); | ||||
|     msgpack::object obj(val1); | ||||
|     boost::string_view val2 = obj.as<boost::string_view>(); | ||||
|     EXPECT_TRUE(val1 == val2); | ||||
| } | ||||
|  | ||||
| TEST(MSGPACK_BOOST, object_with_zone_string_view) | ||||
| { | ||||
|     msgpack::zone z; | ||||
|     std::string s = "ABC"; | ||||
|     boost::string_view val1(s); | ||||
|     msgpack::object obj(val1, z); | ||||
|     boost::string_view val2 = obj.as<boost::string_view>(); | ||||
|     EXPECT_TRUE(val1 == val2); | ||||
| } | ||||
|  | ||||
| #endif // (BOOST_VERSION / 100000) >= 1 && ((BOOST_VERSION / 100) % 1000) >= 61 | ||||
| #endif // defined(MSGPACK_USE_BOOST) | ||||
		Reference in New Issue
	
	Block a user