mirror of
https://github.com/msgpack/msgpack-c.git
synced 2025-10-17 11:05:05 +02:00
@@ -200,6 +200,8 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/adaptor/raw.hpp
|
||||
include/msgpack/adaptor/raw_decl.hpp
|
||||
include/msgpack/adaptor/set.hpp
|
||||
include/msgpack/adaptor/size_equal_only.hpp
|
||||
include/msgpack/adaptor/size_equal_only_decl.hpp
|
||||
include/msgpack/adaptor/string.hpp
|
||||
include/msgpack/adaptor/tr1/unordered_map.hpp
|
||||
include/msgpack/adaptor/tr1/unordered_set.hpp
|
||||
@@ -555,6 +557,8 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/v1/adaptor/raw.hpp
|
||||
include/msgpack/v1/adaptor/raw_decl.hpp
|
||||
include/msgpack/v1/adaptor/set.hpp
|
||||
include/msgpack/v1/adaptor/size_equal_only.hpp
|
||||
include/msgpack/v1/adaptor/size_equal_only_decl.hpp
|
||||
include/msgpack/v1/adaptor/string.hpp
|
||||
include/msgpack/v1/adaptor/tr1/unordered_map.hpp
|
||||
include/msgpack/v1/adaptor/tr1/unordered_set.hpp
|
||||
@@ -614,6 +618,7 @@ IF (MSGPACK_ENABLE_CXX)
|
||||
include/msgpack/v2/adaptor/msgpack_tuple_decl.hpp
|
||||
include/msgpack/v2/adaptor/nil_decl.hpp
|
||||
include/msgpack/v2/adaptor/raw_decl.hpp
|
||||
include/msgpack/v2/adaptor/size_equal_only_decl.hpp
|
||||
include/msgpack/v2/adaptor/v4raw_decl.hpp
|
||||
include/msgpack/v2/cpp_config_decl.hpp
|
||||
include/msgpack/v2/detail/cpp03_zone_decl.hpp
|
||||
|
@@ -83,6 +83,7 @@ struct tuple<> {
|
||||
tuple() {}
|
||||
tuple(msgpack::object const& o) { o.convert(*this); }
|
||||
typedef tuple<> value_type;
|
||||
std::size_t size() const { return 0; }
|
||||
};
|
||||
|
||||
/// @cond
|
||||
@@ -90,6 +91,7 @@ struct tuple<> {
|
||||
template <typename A0<%1.upto(i) {|j|%>, typename A<%=j%><%}%>>
|
||||
struct tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> {
|
||||
typedef tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> value_type;
|
||||
std::size_t size() const { return <%=i+1%>; }
|
||||
tuple() {}
|
||||
tuple(typename tuple_type<A0>::transparent_reference _a0<%1.upto(i) {|j|%>, typename tuple_type<A<%=j%>>::transparent_reference _a<%=j%><%}%>) :
|
||||
a0(_a0)<%1.upto(i) {|j|%>, a<%=j%>(_a<%=j%>)<%}%> {}
|
||||
@@ -148,10 +150,10 @@ struct convert<type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>> > {
|
||||
msgpack::object const& o,
|
||||
type::tuple<A0<%1.upto(i) {|j|%>, A<%=j%><%}%>>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < <%=i+1%>) { throw msgpack::type_error(); }
|
||||
<%0.upto(i) {|j|%>
|
||||
// In order to avoid clang++'s invalid warning, msgpack::object:: has been added.
|
||||
o.via.array.ptr[<%=j%>].msgpack::object::convert<typename type::tuple_type<A<%=j%>>::type>(v.template get<<%=j%>>());<%}%>
|
||||
if(o.via.array.size > <%=j%>)
|
||||
o.via.array.ptr[<%=j%>].msgpack::object::convert<typename type::tuple_type<A<%=j%>>::type>(v.template get<<%=j%>>());<%}%>
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
17
include/msgpack/adaptor/size_equal_only.hpp
Normal file
17
include/msgpack/adaptor/size_equal_only.hpp
Normal file
@@ -0,0 +1,17 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution 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_TYPE_SIZE_EQUAL_ONLY_HPP
|
||||
#define MSGPACK_TYPE_SIZE_EQUAL_ONLY_HPP
|
||||
|
||||
#include "msgpack/adaptor/size_equal_only_decl.hpp"
|
||||
|
||||
#include "msgpack/v1/adaptor/size_equal_only.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_SIZE_EQUAL_ONLYL_HPP
|
16
include/msgpack/adaptor/size_equal_only_decl.hpp
Normal file
16
include/msgpack/adaptor/size_equal_only_decl.hpp
Normal file
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution 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_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
||||
#define MSGPACK_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/size_equal_only_decl.hpp"
|
||||
#include "msgpack/v2/adaptor/size_equal_only_decl.hpp"
|
||||
|
||||
#endif // MSGPACK_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
@@ -15,6 +15,7 @@
|
||||
#include "adaptor/raw.hpp"
|
||||
#include "adaptor/v4raw.hpp"
|
||||
#include "adaptor/set.hpp"
|
||||
#include "adaptor/size_equal_only.hpp"
|
||||
#include "adaptor/string.hpp"
|
||||
#include "adaptor/vector.hpp"
|
||||
#include "adaptor/vector_bool.hpp"
|
||||
|
@@ -75,7 +75,7 @@ template <typename T, std::size_t N>
|
||||
struct as<std::array<T, N>, typename std::enable_if<msgpack::has_as<T>::value>::type> {
|
||||
std::array<T, N> operator()(msgpack::object const& o) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size > N) { throw msgpack::type_error(); }
|
||||
return detail::array::as_impl<T, N>::as(o);
|
||||
}
|
||||
};
|
||||
@@ -84,7 +84,7 @@ template <typename T, std::size_t N>
|
||||
struct convert<std::array<T, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<T, N>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size > N) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size > 0) {
|
||||
msgpack::object* p = o.via.array.ptr;
|
||||
msgpack::object* const pend = o.via.array.ptr + o.via.array.size;
|
||||
|
@@ -30,11 +30,11 @@ struct convert<std::array<char, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<char, N>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
if(o.via.bin.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.bin.size > N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
if(o.via.str.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.str.size > N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
|
@@ -30,11 +30,11 @@ struct convert<std::array<unsigned char, N>> {
|
||||
msgpack::object const& operator()(msgpack::object const& o, std::array<unsigned char, N>& v) const {
|
||||
switch (o.type) {
|
||||
case msgpack::type::BIN:
|
||||
if(o.via.bin.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.bin.size > N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.bin.ptr, o.via.bin.size);
|
||||
break;
|
||||
case msgpack::type::STR:
|
||||
if(o.via.str.size != N) { throw msgpack::type_error(); }
|
||||
if(o.via.str.size > N) { throw msgpack::type_error(); }
|
||||
std::memcpy(v.data(), o.via.str.ptr, N);
|
||||
break;
|
||||
default:
|
||||
|
@@ -93,7 +93,8 @@ struct StdTupleConverter {
|
||||
msgpack::object const& o,
|
||||
Tuple& v) {
|
||||
StdTupleConverter<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(std::get<N-1>(v))>::type>(std::get<N-1>(v));
|
||||
if (o.via.array.size >= N)
|
||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(std::get<N-1>(v))>::type>(std::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -112,7 +113,6 @@ struct as<std::tuple<Args...>, typename std::enable_if<msgpack::all_of<msgpack::
|
||||
std::tuple<Args...> operator()(
|
||||
msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
return StdTupleAs<Args...>::as(o);
|
||||
}
|
||||
};
|
||||
@@ -123,7 +123,6 @@ struct convert<std::tuple<Args...>> {
|
||||
msgpack::object const& o,
|
||||
std::tuple<Args...>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
StdTupleConverter<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
return o;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@@ -121,7 +121,8 @@ struct MsgpackTupleConverter {
|
||||
msgpack::object const& o,
|
||||
Tuple& v) {
|
||||
MsgpackTupleConverter<Tuple, N-1>::convert(o, v);
|
||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(type::get<N-1>(v))>::type>(type::get<N-1>(v));
|
||||
if (o.via.array.size >= N)
|
||||
o.via.array.ptr[N-1].convert<typename std::remove_reference<decltype(type::get<N-1>(v))>::type>(type::get<N-1>(v));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -149,7 +150,6 @@ struct as<msgpack::type::tuple<Args...>, typename std::enable_if<msgpack::all_of
|
||||
msgpack::type::tuple<Args...> operator()(
|
||||
msgpack::object const& o) const {
|
||||
if (o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if (o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
return MsgpackTupleAs<Args...>::as(o);
|
||||
}
|
||||
};
|
||||
@@ -160,7 +160,6 @@ struct convert<msgpack::type::tuple<Args...>> {
|
||||
msgpack::object const& o,
|
||||
msgpack::type::tuple<Args...>& v) const {
|
||||
if(o.type != msgpack::type::ARRAY) { throw msgpack::type_error(); }
|
||||
if(o.via.array.size < sizeof...(Args)) { throw msgpack::type_error(); }
|
||||
MsgpackTupleConverter<decltype(v), sizeof...(Args)>::convert(o, v);
|
||||
return o;
|
||||
}
|
||||
|
@@ -72,6 +72,8 @@ namespace type {
|
||||
template< std::size_t I>
|
||||
typename tuple_element<I, base >::type&&
|
||||
get() && { return std::get<I>(*this); }
|
||||
|
||||
std::size_t size() const { return sizeof...(Types); }
|
||||
};
|
||||
|
||||
template <class... Args>
|
||||
|
118
include/msgpack/v1/adaptor/size_equal_only.hpp
Normal file
118
include/msgpack/v1/adaptor/size_equal_only.hpp
Normal file
@@ -0,0 +1,118 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution 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_V1_TYPE_SIZE_EQUAL_ONLY_HPP
|
||||
#define MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/size_equal_only_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename T>
|
||||
inline std::size_t size(T const& t) {
|
||||
return t.size();
|
||||
}
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
inline std::size_t size(const T(&)[N]) {
|
||||
return N;
|
||||
}
|
||||
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename... T>
|
||||
inline std::size_t size(std::tuple<T...> const&) {
|
||||
return sizeof...(T);
|
||||
}
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct size_equal_only {
|
||||
size_equal_only(T& t):m_t(t) {}
|
||||
T& m_t;
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline size_equal_only<T> make_size_equal_only(T& t) {
|
||||
return size_equal_only<T>(t);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator<(size_equal_only<T> const& lhs, size_equal_only<T> const& rhs) {
|
||||
return lhs.m_t < rhs.m_t;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool operator==(size_equal_only<T> const& lhs, size_equal_only<T> const& rhs) {
|
||||
return lhs.m_t == &rhs.m_t;
|
||||
}
|
||||
|
||||
} // namespace type
|
||||
|
||||
namespace adaptor {
|
||||
|
||||
template <typename T>
|
||||
struct convert<type::size_equal_only<T> > {
|
||||
msgpack::object const& operator()(msgpack::object const& o, type::size_equal_only<T>& v) const {
|
||||
switch(o.type) {
|
||||
case msgpack::type::ARRAY:
|
||||
if (o.via.array.size != msgpack::type::size(v.m_t)) throw msgpack::type_error();
|
||||
break;
|
||||
case msgpack::type::MAP:
|
||||
if (o.via.map.size != msgpack::type::size(v.m_t)) throw msgpack::type_error();
|
||||
break;
|
||||
default:
|
||||
throw msgpack::type_error();
|
||||
}
|
||||
o >> v.m_t;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct pack<type::size_equal_only<T> > {
|
||||
template <typename Stream>
|
||||
msgpack::packer<Stream>& operator()(msgpack::packer<Stream>& o, const type::size_equal_only<T>& v) const {
|
||||
o << v.m_t;
|
||||
return o;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object<type::size_equal_only<T> > {
|
||||
void operator()(msgpack::object& o, type::size_equal_only<T> const& v) const {
|
||||
o << v.m_t;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
struct object_with_zone<type::size_equal_only<T> > {
|
||||
void operator()(msgpack::object::with_zone& o, type::size_equal_only<T> v) const {
|
||||
o << v.m_t;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace adaptor
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_HPP
|
52
include/msgpack/v1/adaptor/size_equal_only_decl.hpp
Normal file
52
include/msgpack/v1/adaptor/size_equal_only_decl.hpp
Normal file
@@ -0,0 +1,52 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution 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_V1_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
||||
#define MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
||||
|
||||
#include "msgpack/versioning.hpp"
|
||||
#include "msgpack/adaptor/adaptor_base.hpp"
|
||||
#include "msgpack/adaptor/msgpack_tuple.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v1) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
template <typename T>
|
||||
struct size_equal_only;
|
||||
|
||||
template <typename T>
|
||||
size_equal_only<T> make_size_equal_only(T& t);
|
||||
|
||||
template <typename T>
|
||||
std::size_t size(T const& t);
|
||||
|
||||
template <typename T, std::size_t N>
|
||||
std::size_t size(const T(&)[N]);
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
template <typename... T>
|
||||
std::size_t size(std::tuple<T...> const&);
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
} // namespace type
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v1)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V1_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
35
include/msgpack/v2/adaptor/size_equal_only_decl.hpp
Normal file
35
include/msgpack/v2/adaptor/size_equal_only_decl.hpp
Normal file
@@ -0,0 +1,35 @@
|
||||
//
|
||||
// MessagePack for C++ static resolution 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_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
||||
#define MSGPACK_V2_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
||||
|
||||
#include "msgpack/v1/adaptor/size_equal_only_decl.hpp"
|
||||
|
||||
namespace msgpack {
|
||||
|
||||
/// @cond
|
||||
MSGPACK_API_VERSION_NAMESPACE(v2) {
|
||||
/// @endcond
|
||||
|
||||
namespace type {
|
||||
|
||||
using v1::type::size_equal_only;
|
||||
using v1::type::make_size_equal_only;
|
||||
using v1::type::size;
|
||||
|
||||
} // namespace type
|
||||
|
||||
/// @cond
|
||||
} // MSGPACK_API_VERSION_NAMESPACE(v2)
|
||||
/// @endcond
|
||||
|
||||
} // namespace msgpack
|
||||
|
||||
#endif // MSGPACK_V2_TYPE_SIZE_EQUAL_ONLY_DECL_HPP
|
@@ -30,6 +30,7 @@ LIST (APPEND check_PROGRAMS
|
||||
pack_unpack_c.cpp
|
||||
raw.cpp
|
||||
reference.cpp
|
||||
size_equal_only.cpp
|
||||
streaming.cpp
|
||||
streaming_c.cpp
|
||||
user_class.cpp
|
||||
|
@@ -1,3 +1,4 @@
|
||||
#include <iostream>
|
||||
#include <msgpack.hpp>
|
||||
|
||||
#include <cmath>
|
||||
@@ -469,6 +470,63 @@ TEST(MSGPACK_TUPLE, simple_tuple_empty)
|
||||
EXPECT_EQ(oh.get().via.array.size, 0u);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_TUPLE, simple_tuple_grater_than_as)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::type::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
msgpack::type::tuple<bool, std::string, int, int> val2
|
||||
= oh.get().as<msgpack::type::tuple<bool, std::string, int, int> >();
|
||||
EXPECT_EQ(oh.get().via.array.size, 3u);
|
||||
EXPECT_EQ(val1.get<0>(), val2.get<0>());
|
||||
EXPECT_EQ(val1.get<1>(), val2.get<1>());
|
||||
EXPECT_EQ(val1.get<2>(), val2.get<2>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_TUPLE, simple_tuple_grater_than_convert)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::type::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
msgpack::type::tuple<bool, std::string, int, int> val2;
|
||||
oh.get().convert(val2);
|
||||
EXPECT_EQ(oh.get().via.array.size, 3u);
|
||||
EXPECT_EQ(val1.get<0>(), val2.get<0>());
|
||||
EXPECT_EQ(val1.get<1>(), val2.get<1>());
|
||||
EXPECT_EQ(val1.get<2>(), val2.get<2>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_TUPLE, simple_tuple_less_than_as)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::type::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
msgpack::type::tuple<bool, std::string> val2
|
||||
= oh.get().as<msgpack::type::tuple<bool, std::string> >();
|
||||
EXPECT_EQ(oh.get().via.array.size, 3u);
|
||||
EXPECT_EQ(val1.get<0>(), val2.get<0>());
|
||||
EXPECT_EQ(val1.get<1>(), val2.get<1>());
|
||||
}
|
||||
|
||||
TEST(MSGPACK_TUPLE, simple_tuple_less_than_convert)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::type::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
msgpack::type::tuple<bool, std::string> val2;
|
||||
oh.get().convert(val2);
|
||||
EXPECT_EQ(oh.get().via.array.size, 3u);
|
||||
EXPECT_EQ(val1.get<0>(), val2.get<0>());
|
||||
EXPECT_EQ(val1.get<1>(), val2.get<1>());
|
||||
}
|
||||
|
||||
// TR1
|
||||
|
||||
|
@@ -59,6 +59,58 @@ TEST(MSGPACK_CPP11, simple_tuple_empty)
|
||||
EXPECT_EQ(val1, val2);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_tuple_size_greater_than_as)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
std::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
std::tuple<bool, std::string, double, int> val2 = oh.get().as<std::tuple<bool, std::string, double, int> >();
|
||||
EXPECT_EQ(std::get<0>(val1), std::get<0>(val2));
|
||||
EXPECT_EQ(std::get<1>(val1), std::get<1>(val2));
|
||||
EXPECT_EQ(std::get<2>(val1), std::get<2>(val2));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_tuple_size_greater_than_convert)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
std::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
std::tuple<bool, std::string, double, int> val2;
|
||||
oh.get().convert(val2);
|
||||
EXPECT_EQ(std::get<0>(val1), std::get<0>(val2));
|
||||
EXPECT_EQ(std::get<1>(val1), std::get<1>(val2));
|
||||
EXPECT_EQ(std::get<2>(val1), std::get<2>(val2));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_tuple_size_less_than_as)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
std::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
std::tuple<bool, std::string> val2 = oh.get().as<std::tuple<bool, std::string> >();
|
||||
EXPECT_EQ(std::get<0>(val1), std::get<0>(val2));
|
||||
EXPECT_EQ(std::get<1>(val1), std::get<1>(val2));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_tuple_size_less_than_convert)
|
||||
{
|
||||
msgpack::sbuffer sbuf;
|
||||
std::tuple<bool, std::string, int> val1(true, "kzk", 42);
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
std::tuple<bool, std::string> val2;
|
||||
oh.get().convert(val2);
|
||||
EXPECT_EQ(std::get<0>(val1), std::get<0>(val2));
|
||||
EXPECT_EQ(std::get<1>(val1), std::get<1>(val2));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_array)
|
||||
{
|
||||
for (unsigned int k = 0; k < kLoop; k++) {
|
||||
@@ -89,6 +141,38 @@ TEST(MSGPACK_CPP11, simple_array_empty)
|
||||
EXPECT_TRUE(equal(val1.begin(), val1.end(), val2.begin()));
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_array_size_less_than)
|
||||
{
|
||||
array<int, 2> val1 { {1 , 2} };
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
EXPECT_EQ(oh.get().type, msgpack::type::ARRAY);
|
||||
array<int, 1> val2;
|
||||
try {
|
||||
oh.get().convert(val2);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_array_size_greater_than)
|
||||
{
|
||||
array<int, 2> val1 { {1 , 2} };
|
||||
msgpack::sbuffer sbuf;
|
||||
msgpack::pack(sbuf, val1);
|
||||
msgpack::object_handle oh =
|
||||
msgpack::unpack(sbuf.data(), sbuf.size());
|
||||
EXPECT_EQ(oh.get().type, msgpack::type::ARRAY);
|
||||
array<int, 3> val2;
|
||||
oh.get().convert(val2);
|
||||
EXPECT_EQ(val1[0], val2[0]);
|
||||
EXPECT_EQ(val1[1], val2[1]);
|
||||
}
|
||||
|
||||
TEST(MSGPACK_CPP11, simple_buffer_array_char)
|
||||
{
|
||||
for (unsigned int k = 0; k < kLoop; k++) {
|
||||
|
221
test/size_equal_only.cpp
Normal file
221
test/size_equal_only.cpp
Normal file
@@ -0,0 +1,221 @@
|
||||
#include <sstream>
|
||||
#include <msgpack.hpp>
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
TEST(size_equal_only, array)
|
||||
{
|
||||
std::stringstream ss;
|
||||
int buf[3] = { 1, 2, 3 };
|
||||
msgpack::type::size_equal_only<int[3]> seo(buf);
|
||||
|
||||
msgpack::pack(ss, seo);
|
||||
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
|
||||
int ret_buf1[3];
|
||||
oh.get().convert(ret_buf1);
|
||||
EXPECT_EQ(buf[0], ret_buf1[0]);
|
||||
EXPECT_EQ(buf[1], ret_buf1[1]);
|
||||
EXPECT_EQ(buf[2], ret_buf1[2]);
|
||||
|
||||
int ret_buf2[4];
|
||||
oh.get().convert(ret_buf2);
|
||||
EXPECT_EQ(buf[0], ret_buf2[0]);
|
||||
EXPECT_EQ(buf[1], ret_buf2[1]);
|
||||
EXPECT_EQ(buf[2], ret_buf2[2]);
|
||||
|
||||
int ret_buf3[3];
|
||||
msgpack::type::size_equal_only<int[3]> ret_seo3(ret_buf3);
|
||||
oh.get().convert(ret_seo3);
|
||||
EXPECT_EQ(buf[0], ret_buf3[0]);
|
||||
EXPECT_EQ(buf[1], ret_buf3[1]);
|
||||
EXPECT_EQ(buf[2], ret_buf3[2]);
|
||||
|
||||
int ret_buf4[4];
|
||||
msgpack::type::size_equal_only<int[4]> ret_seo4(ret_buf4);
|
||||
try {
|
||||
oh.get().convert(ret_seo4);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(size_equal_only, vector)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::vector<int> buf;
|
||||
buf.push_back(1);
|
||||
buf.push_back(2);
|
||||
buf.push_back(3);
|
||||
|
||||
msgpack::type::size_equal_only<std::vector<int> > seo(buf);
|
||||
|
||||
msgpack::pack(ss, seo);
|
||||
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
|
||||
std::vector<int> ret_buf1;
|
||||
oh.get().convert(ret_buf1);
|
||||
EXPECT_EQ(buf, ret_buf1);
|
||||
|
||||
|
||||
std::vector<int> ret_buf2;
|
||||
ret_buf2.resize(3);
|
||||
msgpack::type::size_equal_only<std::vector<int> > ret_seo2(ret_buf2);
|
||||
oh.get().convert(ret_seo2);
|
||||
EXPECT_EQ(buf, ret_buf2);
|
||||
|
||||
std::vector<int> ret_buf3;
|
||||
ret_buf2.resize(4);
|
||||
msgpack::type::size_equal_only<std::vector<int> > ret_seo3(ret_buf3);
|
||||
try {
|
||||
oh.get().convert(ret_seo3);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(size_equal_only, msgpack_tuple)
|
||||
{
|
||||
std::stringstream ss;
|
||||
msgpack::type::tuple<int, bool, std::string> buf(1, false, "ABC");
|
||||
|
||||
msgpack::type::size_equal_only<msgpack::type::tuple<int, bool, std::string> > seo(buf);
|
||||
|
||||
msgpack::pack(ss, seo);
|
||||
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
|
||||
msgpack::type::tuple<int, bool, std::string> ret_buf1;
|
||||
oh.get().convert(ret_buf1);
|
||||
EXPECT_EQ(buf.get<0>(), ret_buf1.get<0>());
|
||||
EXPECT_EQ(buf.get<1>(), ret_buf1.get<1>());
|
||||
EXPECT_EQ(buf.get<2>(), ret_buf1.get<2>());
|
||||
|
||||
msgpack::type::tuple<int, bool, std::string> ret_buf2;
|
||||
msgpack::type::size_equal_only<msgpack::type::tuple<int, bool, std::string> > ret_seo2(ret_buf2);
|
||||
oh.get().convert(ret_seo2);
|
||||
EXPECT_EQ(buf.get<0>(), ret_buf2.get<0>());
|
||||
EXPECT_EQ(buf.get<1>(), ret_buf2.get<1>());
|
||||
EXPECT_EQ(buf.get<2>(), ret_buf2.get<2>());
|
||||
|
||||
msgpack::type::tuple<int, bool, std::string, int> ret_buf3;
|
||||
oh.get().convert(ret_buf3);
|
||||
EXPECT_EQ(buf.get<0>(), ret_buf3.get<0>());
|
||||
EXPECT_EQ(buf.get<1>(), ret_buf3.get<1>());
|
||||
EXPECT_EQ(buf.get<2>(), ret_buf3.get<2>());
|
||||
|
||||
msgpack::type::tuple<int, bool, std::string, int> ret_buf4;
|
||||
msgpack::type::size_equal_only<msgpack::type::tuple<int, bool, std::string, int> > ret_seo4(ret_buf4);
|
||||
try {
|
||||
oh.get().convert(ret_seo4);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
msgpack::type::tuple<int, bool, std::string> ret_buf5;
|
||||
oh.get().convert(ret_buf5);
|
||||
EXPECT_EQ(buf.get<0>(), ret_buf5.get<0>());
|
||||
EXPECT_EQ(buf.get<1>(), ret_buf5.get<1>());
|
||||
|
||||
msgpack::type::tuple<int, bool, std::string, int> ret_buf6;
|
||||
msgpack::type::size_equal_only<msgpack::type::tuple<int, bool, std::string, int> > ret_seo6(ret_buf6);
|
||||
try {
|
||||
oh.get().convert(ret_seo6);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
}
|
||||
|
||||
#if !defined(MSGPACK_USE_CPP03)
|
||||
|
||||
TEST(size_equal_only, tuple)
|
||||
{
|
||||
std::stringstream ss;
|
||||
std::tuple<int, bool, std::string> buf(1, false, "ABC");
|
||||
|
||||
auto seo = msgpack::type::make_size_equal_only(buf);
|
||||
|
||||
msgpack::pack(ss, seo);
|
||||
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
|
||||
std::tuple<int, bool, std::string> ret_buf1;
|
||||
oh.get().convert(ret_buf1);
|
||||
EXPECT_EQ(buf, ret_buf1);
|
||||
|
||||
std::tuple<int, bool, std::string> ret_buf2;
|
||||
auto ret_seo2 = msgpack::type::make_size_equal_only(ret_buf2);
|
||||
oh.get().convert(ret_seo2);
|
||||
EXPECT_EQ(buf, ret_buf2);
|
||||
|
||||
std::tuple<int, bool, std::string, int> ret_buf3;
|
||||
oh.get().convert(ret_buf3);
|
||||
EXPECT_EQ(std::get<0>(buf), std::get<0>(ret_buf3));
|
||||
EXPECT_EQ(std::get<1>(buf), std::get<1>(ret_buf3));
|
||||
EXPECT_EQ(std::get<2>(buf), std::get<2>(ret_buf3));
|
||||
|
||||
std::tuple<int, bool, std::string, int> ret_buf4;
|
||||
auto ret_seo4 = msgpack::type::make_size_equal_only(ret_buf4);
|
||||
try {
|
||||
oh.get().convert(ret_seo4);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
|
||||
std::tuple<int, bool, std::string> ret_buf5;
|
||||
oh.get().convert(ret_buf5);
|
||||
EXPECT_EQ(std::get<0>(buf), std::get<0>(ret_buf5));
|
||||
EXPECT_EQ(std::get<1>(buf), std::get<1>(ret_buf5));
|
||||
|
||||
std::tuple<int, bool, std::string, int> ret_buf6;
|
||||
auto ret_seo6 = msgpack::type::make_size_equal_only(ret_buf6);
|
||||
try {
|
||||
oh.get().convert(ret_seo6);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
}
|
||||
|
||||
struct foo1 {
|
||||
foo1() = default;
|
||||
foo1(int i, bool b):t(i, b), seo(t) {}
|
||||
std::tuple<int, bool> t;
|
||||
msgpack::type::size_equal_only<std::tuple<int, bool> > seo;
|
||||
MSGPACK_DEFINE(seo);
|
||||
};
|
||||
|
||||
struct foo2 {
|
||||
foo2() = default;
|
||||
foo2(int i, bool b, std::string const& s):t(i, b, s), seo(t) {}
|
||||
std::tuple<int, bool, std::string> t;
|
||||
msgpack::type::size_equal_only<std::tuple<int, bool, std::string> > seo;
|
||||
MSGPACK_DEFINE(seo);
|
||||
};
|
||||
|
||||
TEST(size_equal_only, custom_class)
|
||||
{
|
||||
std::stringstream ss;
|
||||
foo1 f1(42, true);
|
||||
msgpack::pack(ss, f1);
|
||||
msgpack::object_handle oh = msgpack::unpack(ss.str().data(), ss.str().size());
|
||||
|
||||
foo2 f2(123, false, "ABC");
|
||||
try {
|
||||
oh.get().convert(f2);
|
||||
EXPECT_TRUE(false);
|
||||
}
|
||||
catch (msgpack::type_error const&) {
|
||||
EXPECT_TRUE(true);
|
||||
}
|
||||
}
|
||||
|
||||
#endif // !defined(MSGPACK_USE_CPP03)
|
@@ -151,7 +151,14 @@ public:
|
||||
msgpack::type::tuple<bool, msgpack::object> tuple;
|
||||
o.convert(tuple);
|
||||
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic push
|
||||
#pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
is_double = tuple.get<0>();
|
||||
#if (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
#pragma GCC diagnostic pop
|
||||
#endif // (__GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ >= 6)) && !defined(__clang__)
|
||||
if (is_double)
|
||||
tuple.get<1>().convert(value.f);
|
||||
else
|
||||
|
Reference in New Issue
Block a user