diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a026e4a..48886af3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -374,6 +374,7 @@ IF (MSGPACK_ENABLE_CXX) include/msgpack/v2/object_fwd_decl.hpp include/msgpack/v2/pack_decl.hpp include/msgpack/v2/sbuffer_decl.hpp + include/msgpack/v2/unpack.hpp include/msgpack/v2/unpack_decl.hpp include/msgpack/v2/vrefbuffer_decl.hpp include/msgpack/v2/zbuffer_decl.hpp diff --git a/include/msgpack/unpack.hpp b/include/msgpack/unpack.hpp index 743d2227..8cd02602 100644 --- a/include/msgpack/unpack.hpp +++ b/include/msgpack/unpack.hpp @@ -13,5 +13,6 @@ #include "msgpack/unpack_decl.hpp" #include "msgpack/v1/unpack.hpp" +#include "msgpack/v2/unpack.hpp" #endif // MSGPACK_UNPACK_HPP diff --git a/include/msgpack/v2/unpack.hpp b/include/msgpack/v2/unpack.hpp new file mode 100644 index 00000000..4d31bae0 --- /dev/null +++ b/include/msgpack/v2/unpack.hpp @@ -0,0 +1,134 @@ +// +// MessagePack for C++ deserializing routine +// +// Copyright (C) 2016 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_V2_UNPACK_HPP +#define MSGPACK_V2_UNPACK_HPP + +#include "msgpack/unpack_decl.hpp" + +namespace msgpack { + +/// @cond +MSGPACK_API_VERSION_NAMESPACE(v2) { +/// @endcond + +inline msgpack::object_handle unpack( + const char* data, std::size_t len, std::size_t& off, bool& referenced, + unpack_reference_func f, void* user_data, + unpack_limit const& limit +) +{ + return v1::unpack(data, len, off, referenced, f, user_data, limit); +} + +inline msgpack::object_handle unpack( + const char* data, std::size_t len, std::size_t& off, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + return v1::unpack(data, len, off, f, user_data, limit); +} + +inline msgpack::object_handle unpack( + const char* data, std::size_t len, bool& referenced, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + return v1::unpack(data, len, referenced, f, user_data, limit); +} + +inline msgpack::object_handle unpack( + const char* data, std::size_t len, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + return v1::unpack(data, len, f, user_data, limit); +} + +inline void unpack( + msgpack::object_handle& result, + const char* data, std::size_t len, std::size_t& off, bool& referenced, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + v1::unpack(result, data, len, off, referenced, f, user_data, limit); +} + +inline void unpack( + msgpack::object_handle& result, + const char* data, std::size_t len, std::size_t& off, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + v1::unpack(result, data, len, off, f, user_data, limit); +} + +inline void unpack( + msgpack::object_handle& result, + const char* data, std::size_t len, bool& referenced, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + v1::unpack(result, data, len, referenced, f, user_data, limit); +} + +inline void unpack( + msgpack::object_handle& result, + const char* data, std::size_t len, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + v1::unpack(result, data, len, f, user_data, limit); +} + + +inline msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, std::size_t& off, bool& referenced, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + return v1::unpack(z, data, len, off, referenced, f, user_data, limit); +} + +inline msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, std::size_t& off, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + return v1::unpack(z, data, len, off, f, user_data, limit); +} + +inline msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, bool& referenced, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + return v1::unpack(z, data, len, referenced, f, user_data, limit); +} + +inline msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, + unpack_reference_func f, void* user_data, + unpack_limit const& limit) +{ + return v1::unpack(z, data, len, f, user_data, limit); +} + +/// @cond +} // MSGPACK_API_VERSION_NAMESPACE(v2) +/// @endcond + +} // namespace msgpack + + +#endif // MSGPACK_V2_UNPACK_HPP diff --git a/include/msgpack/v2/unpack_decl.hpp b/include/msgpack/v2/unpack_decl.hpp index 69275d68..1190317f 100644 --- a/include/msgpack/v2/unpack_decl.hpp +++ b/include/msgpack/v2/unpack_decl.hpp @@ -85,10 +85,214 @@ using v1::unpacked; using v1::unpacker; -using v1::unpack; - using v1::unpack_return; + +/// Unpack msgpack::object from a buffer. +/** + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param off The offset position of the buffer. It is read and overwritten. + * @param referenced If the unpacked object contains reference of the buffer, then set as true, otherwise false. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return object_handle that contains unpacked data. + * + */ +object_handle unpack( + const char* data, std::size_t len, std::size_t& off, bool& referenced, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param off The offset position of the buffer. It is read and overwritten. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return object_handle that contains unpacked data. + * + */ +object_handle unpack( + const char* data, std::size_t len, std::size_t& off, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param referenced If the unpacked object contains reference of the buffer, then set as true, otherwise false. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return object_handle that contains unpacked data. + * + */ +object_handle unpack( + const char* data, std::size_t len, bool& referenced, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return object_handle that contains unpacked data. + * + */ +object_handle unpack( + const char* data, std::size_t len, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + + +/// Unpack msgpack::object from a buffer. +/** + * @param result The object_handle that contains unpacked data. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param off The offset position of the buffer. It is read and overwritten. + * @param referenced If the unpacked object contains reference of the buffer, then set as true, otherwise false. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * + */ +void unpack( + object_handle& result, + const char* data, std::size_t len, std::size_t& off, bool& referenced, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param result The object_handle that contains unpacked data. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param off The offset position of the buffer. It is read and overwritten. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * + */ +void unpack( + object_handle& result, + const char* data, std::size_t len, std::size_t& off, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param result The object_handle that contains unpacked data. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param referenced If the unpacked object contains reference of the buffer, then set as true, otherwise false. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * + */ +void unpack( + object_handle& result, + const char* data, std::size_t len, bool& referenced, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param result The object_handle that contains unpacked data. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * + */ +void unpack( + object_handle& result, + const char* data, std::size_t len, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param z The msgpack::zone that is used as a memory of unpacked msgpack objects. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param off The offset position of the buffer. It is read and overwritten. + * @param referenced If the unpacked object contains reference of the buffer, then set as true, otherwise false. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return msgpack::object that contains unpacked data. + * + */ +msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, std::size_t& off, bool& referenced, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param z The msgpack::zone that is used as a memory of unpacked msgpack objects. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param off The offset position of the buffer. It is read and overwritten. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return msgpack::object that contains unpacked data. + * + */ +msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, std::size_t& off, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param z The msgpack::zone that is used as a memory of unpacked msgpack objects. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param referenced If the unpacked object contains reference of the buffer, then set as true, otherwise false. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return msgpack::object that contains unpacked data. + * + */ +msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, bool& referenced, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + +/// Unpack msgpack::object from a buffer. +/** + * @param z The msgpack::zone that is used as a memory of unpacked msgpack objects. + * @param data The pointer to the buffer. + * @param len The length of the buffer. + * @param f A judging function that msgpack::object refer to the buffer. + * @param user_data This parameter is passed to f. + * @param limit The size limit information of msgpack::object. + * + * @return msgpack::object that contains unpacked data. + * + */ +msgpack::object unpack( + msgpack::zone& z, + const char* data, std::size_t len, + unpack_reference_func f = nullptr, void* user_data = nullptr, unpack_limit const& limit = unpack_limit()); + namespace detail { using v1::detail::unpack_imp; diff --git a/src/Makefile.am b/src/Makefile.am index 5c8f77c7..f4510079 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -363,6 +363,7 @@ nobase_include_HEADERS += \ ../include/msgpack/v2/object_fwd_decl.hpp \ ../include/msgpack/v2/pack_decl.hpp \ ../include/msgpack/v2/sbuffer_decl.hpp \ + ../include/msgpack/v2/unpack.hpp \ ../include/msgpack/v2/unpack_decl.hpp \ ../include/msgpack/v2/vrefbuffer_decl.hpp \ ../include/msgpack/v2/zbuffer_decl.hpp \ diff --git a/test/limit.cpp b/test/limit.cpp index 178f3255..8ae61996 100644 --- a/test/limit.cpp +++ b/test/limit.cpp @@ -504,6 +504,8 @@ TEST(limit, unpack_array_over_off_ref) } // obsolete +#if MSGPACK_DEFAULT_API_VERSION == 1 + TEST(limit, unpack_array_over_off_ref_pointer) { std::stringstream ss; @@ -528,6 +530,8 @@ TEST(limit, unpack_array_over_off_ref_pointer) } } +#endif // MSGPACK_DEFAULT_API_VERSION == 1 + TEST(limit, unpacker_array_over) { std::stringstream ss; diff --git a/test/pack_unpack.cpp b/test/pack_unpack.cpp index 243c1cc2..0af1e962 100644 --- a/test/pack_unpack.cpp +++ b/test/pack_unpack.cpp @@ -145,6 +145,7 @@ TEST(unpack, int_offset_ref) EXPECT_EQ(off, sbuf.size()); } +#if MSGPACK_DEFAULT_API_VERSION == 1 TEST(unpack, int_pointer_off_no_ref) { @@ -214,6 +215,8 @@ TEST(unpack, int_default_null_pointer) EXPECT_EQ(1, oh.get().as()); } +#endif // MSGPACK_DEFAULT_API_VERSION == 1 + TEST(unpack, int_zone_no_offset_no_ref) { msgpack::sbuffer sbuf;