diff --git a/.travis.yml b/.travis.yml index 2cb82422..7dc6d902 100644 --- a/.travis.yml +++ b/.travis.yml @@ -38,13 +38,13 @@ matrix: include: - os: osx compiler: clang - env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="1" + env: ACTION="ci/build_cmake.sh" CXX17="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="1" - os: osx compiler: clang - env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="signed" API_VERSION="3" + env: ACTION="ci/build_cmake.sh" CXX17="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="signed" API_VERSION="3" - os: osx compiler: clang - env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2" + env: ACTION="ci/build_cmake.sh" CXX17="ON" ARCH="64" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2" - os: osx compiler: clang env: ACTION="ci/build_cmake.sh" ARCH="64" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="2" @@ -89,7 +89,7 @@ matrix: - libc6-dbg - os: linux compiler: clang - env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="signed" API_VERSION="3" X3_PARSE="ON" + env: ACTION="ci/build_cmake.sh" CXX17="ON" ARCH="64" BOOST="ON" SHARED="ON" CHAR_SIGN="signed" API_VERSION="3" X3_PARSE="ON" addons: apt: sources: @@ -106,7 +106,7 @@ matrix: - libc6-dbg - os: linux compiler: clang - env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="32" SHARED="OFF" CHAR_SIGN="unsigned" API_VERSION="2" + env: ACTION="ci/build_cmake.sh" CXX17="ON" ARCH="32" SHARED="OFF" CHAR_SIGN="unsigned" API_VERSION="2" addons: apt: sources: @@ -128,7 +128,7 @@ matrix: - libc6-dbg - os: linux compiler: gcc - env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="64" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2" + env: ACTION="ci/build_cmake.sh" CXX17="ON" ARCH="64" SHARED="ON" CHAR_SIGN="signed" API_VERSION="2" addons: apt: sources: @@ -142,7 +142,7 @@ matrix: - libc6-dbg - os: linux compiler: gcc - env: ACTION="ci/build_cmake.sh" CXX11="ON" ARCH="32" BOOST="ON" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="3" X3_PARSE="ON" + env: ACTION="ci/build_cmake.sh" CXX17="ON" ARCH="32" BOOST="ON" SHARED="ON" CHAR_SIGN="unsigned" API_VERSION="3" X3_PARSE="ON" addons: apt: sources: diff --git a/Files.cmake b/Files.cmake index 70c030f7..c671e6b6 100644 --- a/Files.cmake +++ b/Files.cmake @@ -182,8 +182,11 @@ IF (MSGPACK_ENABLE_CXX) include/msgpack/adaptor/cpp11/unique_ptr.hpp include/msgpack/adaptor/cpp11/unordered_map.hpp include/msgpack/adaptor/cpp11/unordered_set.hpp + include/msgpack/adaptor/cpp17/byte.hpp + include/msgpack/adaptor/cpp17/carray_byte.hpp include/msgpack/adaptor/cpp17/optional.hpp include/msgpack/adaptor/cpp17/string_view.hpp + include/msgpack/adaptor/cpp17/vector_byte.hpp include/msgpack/adaptor/define.hpp include/msgpack/adaptor/define_decl.hpp include/msgpack/adaptor/deque.hpp @@ -539,8 +542,11 @@ IF (MSGPACK_ENABLE_CXX) include/msgpack/v1/adaptor/cpp11/unique_ptr.hpp include/msgpack/v1/adaptor/cpp11/unordered_map.hpp include/msgpack/v1/adaptor/cpp11/unordered_set.hpp + include/msgpack/v1/adaptor/cpp17/byte.hpp + include/msgpack/v1/adaptor/cpp17/carray_byte.hpp include/msgpack/v1/adaptor/cpp17/optional.hpp include/msgpack/v1/adaptor/cpp17/string_view.hpp + include/msgpack/v1/adaptor/cpp17/vector_byte.hpp include/msgpack/v1/adaptor/define.hpp include/msgpack/v1/adaptor/define_decl.hpp include/msgpack/v1/adaptor/deque.hpp diff --git a/ci/build_cmake.sh b/ci/build_cmake.sh index ec56eb1e..820ec543 100755 --- a/ci/build_cmake.sh +++ b/ci/build_cmake.sh @@ -23,7 +23,7 @@ else export BIT32="OFF" fi -cmake -DMSGPACK_CXX11=${CXX11} -DMSGPACK_32BIT=${BIT32} -DMSGPACK_BOOST=${BOOST} -DBUILD_SHARED_LIBS=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DMSGPACK_DEFAULT_API_VERSION=${API_VERSION} -DMSGPACK_USE_X3_PARSE=${X3_PARSE} .. +cmake -DMSGPACK_CXX11=${CXX11} -DMSGPACK_CXX17=${CXX17} -DMSGPACK_32BIT=${BIT32} -DMSGPACK_BOOST=${BOOST} -DBUILD_SHARED_LIBS=${SHARED} -DMSGPACK_CHAR_SIGN=${CHAR_SIGN} -DMSGPACK_DEFAULT_API_VERSION=${API_VERSION} -DMSGPACK_USE_X3_PARSE=${X3_PARSE} .. ret=$? if [ $ret -ne 0 ] @@ -39,7 +39,7 @@ then exit $ret fi -make test +ctest -VV ret=$? if [ $ret -ne 0 ] diff --git a/ci/build_regression.sh b/ci/build_regression.sh index 1cd3f175..fca09afd 100755 --- a/ci/build_regression.sh +++ b/ci/build_regression.sh @@ -22,7 +22,7 @@ then exit 1 fi -cmake -DMSGPACK_FUZZ_REGRESSION="ON" -DMSGPACK_CXX11="ON" -DMSGPACK_BOOST=${BOOST} -DMSGPACK_SAN=${MSGPACK_SAN} -v .. +cmake -DMSGPACK_FUZZ_REGRESSION="ON" -DMSGPACK_CXX17="ON" -DMSGPACK_BOOST=${BOOST} -DMSGPACK_SAN=${MSGPACK_SAN} -v .. ret=$? if [ $ret -ne 0 ] diff --git a/include/msgpack/adaptor/cpp17/byte.hpp b/include/msgpack/adaptor/cpp17/byte.hpp new file mode 100644 index 00000000..eebaa960 --- /dev/null +++ b/include/msgpack/adaptor/cpp17/byte.hpp @@ -0,0 +1,16 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2018 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_CPP17_BYTE_HPP +#define MSGPACK_TYPE_CPP17_BYTE_HPP + +#include "msgpack/v1/adaptor/cpp17/byte.hpp" + +#endif // MSGPACK_TYPE_CPP17_BYTE_HPP diff --git a/include/msgpack/adaptor/cpp17/carray_byte.hpp b/include/msgpack/adaptor/cpp17/carray_byte.hpp new file mode 100644 index 00000000..c41bccac --- /dev/null +++ b/include/msgpack/adaptor/cpp17/carray_byte.hpp @@ -0,0 +1,16 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2018 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_CPP17_CARRAY_BYTE_HPP +#define MSGPACK_TYPE_CPP17_CARRAY_BYTE_HPP + +#include "msgpack/v1/adaptor/cpp17/carray_byte.hpp" + +#endif // MSGPACK_TYPE_CPP17_CARRAY_BYTE_HPP diff --git a/include/msgpack/adaptor/cpp17/vector_byte.hpp b/include/msgpack/adaptor/cpp17/vector_byte.hpp new file mode 100644 index 00000000..8c5e6230 --- /dev/null +++ b/include/msgpack/adaptor/cpp17/vector_byte.hpp @@ -0,0 +1,16 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2018 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_CPP17_VECTOR_BYTE_HPP +#define MSGPACK_TYPE_CPP17_VECTOR_BYTE_HPP + +#include "msgpack/v1/adaptor/cpp17/vector_byte.hpp" + +#endif // MSGPACK_TYPE_CPP17_VECTOR_BYTE_HPP diff --git a/include/msgpack/type.hpp b/include/msgpack/type.hpp index 4248b2f9..1a866c56 100644 --- a/include/msgpack/type.hpp +++ b/include/msgpack/type.hpp @@ -51,6 +51,10 @@ #include "adaptor/cpp17/string_view.hpp" #endif // MSGPACK_HAS_INCLUDE() +#include "adaptor/cpp17/byte.hpp" +#include "adaptor/cpp17/carray_byte.hpp" +#include "adaptor/cpp17/vector_byte.hpp" + #endif // defined(MSGPACK_USE_CPP03) #if defined(MSGPACK_USE_BOOST) diff --git a/include/msgpack/v1/adaptor/cpp17/byte.hpp b/include/msgpack/v1/adaptor/cpp17/byte.hpp new file mode 100644 index 00000000..a1d12047 --- /dev/null +++ b/include/msgpack/v1/adaptor/cpp17/byte.hpp @@ -0,0 +1,74 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2018 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_BYTE_HPP +#define MSGPACK_V1_TYPE_BYTE_HPP + +#if __cplusplus >= 201703 + +#include "msgpack/versioning.hpp" +#include "msgpack/adaptor/adaptor_base.hpp" +#include "msgpack/adaptor/adaptor_base.hpp" +#include "msgpack/adaptor/int_decl.hpp" +#include "msgpack/object.hpp" + +#include + +namespace msgpack { + +/// @cond +MSGPACK_API_VERSION_NAMESPACE(v1) { +/// @endcond + +namespace adaptor { + +template <> +struct convert { + msgpack::object const& operator()(msgpack::object const& o, std::byte& v) const { + v = static_cast(type::detail::convert_integer(o)); + return o; + } +}; + +template <> +struct pack { + template + msgpack::packer& operator()(msgpack::packer& o, std::byte v) const { + o.pack_unsigned_char(static_cast(v)); + return o; + } +}; + +template <> +struct object { + void operator()(msgpack::object& o, std::byte v) const { + o.type = msgpack::type::POSITIVE_INTEGER; + o.via.u64 = static_cast(v); + } +}; + +template <> +struct object_with_zone { + void operator()(msgpack::object::with_zone& o, const std::byte& v) const { + static_cast(o) << v; + } +}; + + +} // namespace adaptor + +/// @cond +} // MSGPACK_API_VERSION_NAMESPACE(v1) +/// @endcond + +} // namespace msgpack + +#endif // __cplusplus >= 201703 + +#endif // MSGPACK_V1_TYPE_BYTE_HPP diff --git a/include/msgpack/v1/adaptor/cpp17/carray_byte.hpp b/include/msgpack/v1/adaptor/cpp17/carray_byte.hpp new file mode 100644 index 00000000..e2be6bc0 --- /dev/null +++ b/include/msgpack/v1/adaptor/cpp17/carray_byte.hpp @@ -0,0 +1,109 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2018 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_CARRAY_BYTE_HPP +#define MSGPACK_V1_TYPE_CARRAY_BYTE_HPP + +#if __cplusplus >= 201703 + +#include "msgpack/versioning.hpp" +#include "msgpack/adaptor/adaptor_base.hpp" +#include "msgpack/adaptor/check_container_size.hpp" + +#include +#include + +namespace msgpack { + +/// @cond +MSGPACK_API_VERSION_NAMESPACE(v1) { +/// @endcond + +namespace adaptor { + +template +struct convert { + msgpack::object const& operator()(msgpack::object const& o, std::byte(&v)[N]) const { + switch (o.type) { + case msgpack::type::BIN: + if (o.via.bin.size > N) { throw msgpack::type_error(); } + std::memcpy(v, o.via.bin.ptr, o.via.bin.size); + break; + case msgpack::type::STR: + if (o.via.str.size > N) { throw msgpack::type_error(); } + std::memcpy(v, o.via.str.ptr, o.via.str.size); + if (o.via.str.size < N) v[o.via.str.size] = std::byte{'\0'}; + break; + default: + throw msgpack::type_error(); + break; + } + return o; + } +}; + +template +struct pack { + template + msgpack::packer& operator()(msgpack::packer& o, const std::byte(&v)[N]) const { + std::byte const* p = v; + uint32_t size = checked_get_container_size(N); + o.pack_bin(size); + o.pack_bin_body(reinterpret_cast(p), size); + return o; + } +}; + +template +struct pack { + template + msgpack::packer& operator()(msgpack::packer& o, const std::byte(&v)[N]) const { + std::byte const* p = v; + uint32_t size = checked_get_container_size(N); + o.pack_bin(size); + o.pack_bin_body(reinterpret_cast(p), size); + return o; + } +}; + +template +struct object_with_zone { + void operator()(msgpack::object::with_zone& o, const std::byte(&v)[N]) const { + uint32_t size = checked_get_container_size(N); + o.type = msgpack::type::BIN; + char* ptr = static_cast(o.zone.allocate_align(size, MSGPACK_ZONE_ALIGNOF(char))); + o.via.bin.ptr = ptr; + o.via.bin.size = size; + std::memcpy(ptr, v, size); + } +}; + +template +struct object_with_zone { + void operator()(msgpack::object::with_zone& o, const std::byte(&v)[N]) const { + uint32_t size = checked_get_container_size(N); + o.type = msgpack::type::BIN; + char* ptr = static_cast(o.zone.allocate_align(size, MSGPACK_ZONE_ALIGNOF(char))); + o.via.bin.ptr = ptr; + o.via.bin.size = size; + std::memcpy(ptr, v, size); + } +}; + +} // namespace adaptor + +/// @cond +} // MSGPACK_API_VERSION_NAMESPACE(v1) +/// @endcond + +} // namespace msgpack + +#endif // __cplusplus >= 201703 + +#endif // MSGPACK_V1_TYPE_CARRAY_BYTE_HPP diff --git a/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp b/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp new file mode 100644 index 00000000..e291667e --- /dev/null +++ b/include/msgpack/v1/adaptor/cpp17/vector_byte.hpp @@ -0,0 +1,119 @@ +// +// MessagePack for C++ static resolution routine +// +// Copyright (C) 2018 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_VECTOR_BYTE_HPP +#define MSGPACK_V1_TYPE_VECTOR_BYTE_HPP + +#if __cplusplus >= 201703 + +#include "msgpack/versioning.hpp" +#include "msgpack/adaptor/adaptor_base.hpp" +#include "msgpack/adaptor/check_container_size.hpp" + +#include +#include +#include + +namespace msgpack { + +/// @cond +MSGPACK_API_VERSION_NAMESPACE(v1) { +/// @endcond + +namespace adaptor { + +template +struct convert > { + msgpack::object const& operator()(msgpack::object const& o, std::vector& v) const { + switch (o.type) { + case msgpack::type::BIN: + v.resize(o.via.bin.size); + if (o.via.bin.size != 0) { +#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) + std::memcpy(&v.front(), o.via.bin.ptr, o.via.bin.size); +#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) + } + break; + case msgpack::type::STR: + v.resize(o.via.str.size); + if (o.via.str.size != 0) { +#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wmaybe-uninitialized" +#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) + std::memcpy(&v.front(), o.via.str.ptr, o.via.str.size); +#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) +#pragma GCC diagnostic pop +#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 7)) && !defined(__clang__) + } + break; + default: + throw msgpack::type_error(); + break; + } + return o; + } +}; + +template +struct pack > { + template + msgpack::packer& operator()(msgpack::packer& o, const std::vector& v) const { + uint32_t size = checked_get_container_size(v.size()); + o.pack_bin(size); + if (size != 0) { + o.pack_bin_body(reinterpret_cast(&v.front()), size); + } + + return o; + } +}; + +template +struct object > { + void operator()(msgpack::object& o, const std::vector& v) const { + uint32_t size = checked_get_container_size(v.size()); + o.type = msgpack::type::BIN; + if (size != 0) { + o.via.bin.ptr = reinterpret_cast(&v.front()); + } + o.via.bin.size = size; + } +}; + +template +struct object_with_zone > { + void operator()(msgpack::object::with_zone& o, const std::vector& v) const { + uint32_t size = checked_get_container_size(v.size()); + o.type = msgpack::type::BIN; + o.via.bin.size = size; + if (size != 0) { + char* ptr = static_cast(o.zone.allocate_align(size, MSGPACK_ZONE_ALIGNOF(char))); + o.via.bin.ptr = ptr; + std::memcpy(ptr, &v.front(), size); + } + } +}; + +} // namespace adaptor + +/// @cond +} // MSGPACK_API_VERSION_NAMESPACE(v1) +/// @endcond + +} // namespace msgpack + +#endif // __cplusplus >= 201703 + +#endif // MSGPACK_V1_TYPE_VECTOR_BYTE_HPP diff --git a/test/msgpack_cpp17.cpp b/test/msgpack_cpp17.cpp index 0da11344..36fa82b8 100644 --- a/test/msgpack_cpp17.cpp +++ b/test/msgpack_cpp17.cpp @@ -10,6 +10,8 @@ // C++17 +#if MSGPACK_HAS_INCLUDE() + TEST(MSGPACK_CPP17, optional_pack_convert_nil) { std::stringstream ss; @@ -171,7 +173,11 @@ TEST(MSGPACK_CPP17, optional_pack_convert_no_def_con) EXPECT_TRUE(val1 == val2); } -TEST(MSGPACK_CPP17, string_view_pack_convert_string_view) +#endif // MSGPACK_HAS_INCLUDE() + +#if MSGPACK_HAS_INCLUDE() + +TEST(MSGPACK_CPP17, string_view_pack_convert) { std::stringstream ss; std::string s = "ABC"; @@ -185,7 +191,7 @@ TEST(MSGPACK_CPP17, string_view_pack_convert_string_view) EXPECT_TRUE(val1 == val2); } -TEST(MSGPACK_CPP17, string_view_object_strinf_view) +TEST(MSGPACK_CPP17, string_view_object) { std::string s = "ABC"; std::string_view val1(s); @@ -194,7 +200,7 @@ TEST(MSGPACK_CPP17, string_view_object_strinf_view) EXPECT_TRUE(val1 == val2); } -TEST(MSGPACK_CPP17, string_view_object_with_zone_string_view) +TEST(MSGPACK_CPP17, string_view_object_with_zone) { msgpack::zone z; std::string s = "ABC"; @@ -204,4 +210,119 @@ TEST(MSGPACK_CPP17, string_view_object_with_zone_string_view) EXPECT_TRUE(val1 == val2); } +#endif // MSGPACK_HAS_INCLUDE() + +TEST(MSGPACK_CPP17, byte_pack_convert) +{ + std::stringstream ss; + std::byte val1{0xff}; + + msgpack::pack(ss, val1); + + msgpack::object_handle oh; + msgpack::unpack(oh, ss.str().data(), ss.str().size()); + std::byte val2 = oh.get().as(); + EXPECT_EQ(val1, val2); +} + +TEST(MSGPACK_CPP17, byte_object) +{ + std::byte val1{0x00}; + msgpack::object obj(val1); + std::byte val2 = obj.as(); + EXPECT_EQ(val1, val2); +} + +TEST(MSGPACK_CPP17, byte_object_with_zone) +{ + msgpack::zone z; + std::byte val1{80}; + msgpack::object obj(val1, z); + std::byte val2 = obj.as(); + EXPECT_EQ(val1, val2); +} + +TEST(MSGPACK_CPP17, vector_byte_pack_convert) +{ + std::stringstream ss; + std::vector val1{ + std::byte{0x01}, std::byte{0x02}, std::byte{0x7f}, std::byte{0x80}, std::byte{0xff} + }; + + msgpack::pack(ss, val1); + + char packed[] = { char(0xc4), char(0x05), char(0x01), char(0x02), char(0x7f), char(0x80), char(0xff) }; + for (size_t i = 0; i != sizeof(packed); ++i) { + EXPECT_EQ(ss.str()[i], packed[i]); + } + + msgpack::object_handle oh; + msgpack::unpack(oh, ss.str().data(), ss.str().size()); + std::vector val2 = oh.get().as>(); + EXPECT_EQ(val1, val2); +} + +TEST(MSGPACK_CPP17, vector_byte_object) +{ + std::vector val1{ + std::byte{0x01}, std::byte{0x02}, std::byte{0x7f}, std::byte{0x80}, std::byte{0xff} + }; + + // Caller need to manage val1's lifetime. The Data is not copied. + msgpack::object obj(val1); + + std::vector val2 = obj.as>(); + EXPECT_EQ(val1, val2); +} + +TEST(MSGPACK_CPP17, vector_byte_object_with_zone) +{ + msgpack::zone z; + std::vector val1{ + std::byte{0x01}, std::byte{0x02}, std::byte{0x7f}, std::byte{0x80}, std::byte{0xff} + }; + msgpack::object obj(val1, z); + + std::vector val2 = obj.as>(); + EXPECT_EQ(val1, val2); +} + +TEST(MSGPACK_CPP17, carray_byte_pack_convert) +{ + std::stringstream ss; + std::byte val1[] = { + std::byte{0x01}, std::byte{0x02}, std::byte{0x7f}, std::byte{0x80}, std::byte{0xff} + }; + + msgpack::pack(ss, val1); + + char packed[] = { char(0xc4), char(0x05), char(0x01), char(0x02), char(0x7f), char(0x80), char(0xff) }; + for (size_t i = 0; i != sizeof(packed); ++i) { + EXPECT_EQ(ss.str()[i], packed[i]); + } + + msgpack::object_handle oh; + msgpack::unpack(oh, ss.str().data(), ss.str().size()); + std::byte val2[sizeof(val1)]; + oh.get().convert(val2); + for (size_t i = 0; i != sizeof(val1); ++i) { + EXPECT_EQ(val1[i], val2[i]); + } +} + +TEST(MSGPACK_CPP17, carray_byte_object_with_zone) +{ + msgpack::zone z; + std::byte val1[] = { + std::byte{0x01}, std::byte{0x02}, std::byte{0x7f}, std::byte{0x80}, std::byte{0xff} + }; + msgpack::object obj(val1, z); + + std::byte val2[sizeof(val1)]; + obj.convert(val2); + for (size_t i = 0; i != sizeof(val1); ++i) { + EXPECT_EQ(val1[i], val2[i]); + } +} + #endif // !defined(MSGPACK_USE_CPP03) && __cplusplus >= 201703