Skip to content

Commit aee3c4e

Browse files
author
pfeatherstone
committed
- removed (de)serialize_all(). They will be misused.
- you can serialize a custom struct using std::tuple, provided you want to serialize as array, not map
1 parent e410ae6 commit aee3c4e

File tree

2 files changed

+4
-31
lines changed

2 files changed

+4
-31
lines changed

include/msgpack.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -696,22 +696,4 @@ namespace msgpackcpp
696696
(deserialize(in, std::forward<decltype(args)>(args)),...);
697697
}, tpl);
698698
}
699-
700-
/////////////////////////////////////////////////////////////////////////////////
701-
/// Helpers
702-
/////////////////////////////////////////////////////////////////////////////////
703-
704-
template<class Stream, class... Args>
705-
inline void serialize_all(Stream& out, const Args&... args)
706-
{
707-
using msgpackcpp::serialize;
708-
(serialize(out, args),...);
709-
}
710-
711-
template<class Source, class... Args>
712-
inline void deserialize_all(Source& in, Args&... args)
713-
{
714-
using msgpackcpp::deserialize;
715-
(deserialize(in, args),...);
716-
}
717699
}

test.cpp

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,18 +99,14 @@ namespace custom_namespace
9999
template<class Stream>
100100
void serialize(Stream& out, const custom_struct3& obj)
101101
{
102-
serialize_array_size(out, 5);
103-
serialize_all(out, obj.my_int, obj.my_float, obj.my_str, obj.my_vec, obj.my_struct);
102+
serialize(out, std::tie(obj.my_int, obj.my_float, obj.my_str, obj.my_vec, obj.my_struct));
104103
}
105104

106105
template<class Source>
107106
void deserialize(Source& in, custom_struct3& obj)
108107
{
109-
uint32_t size{};
110-
deserialize_array_size(in, size);
111-
if (size != 5)
112-
throw std::system_error(msgpackcpp::BAD_SIZE);
113-
deserialize_all(in, obj.my_int, obj.my_float, obj.my_str, obj.my_vec, obj.my_struct);
108+
auto members = std::tie(obj.my_int, obj.my_float, obj.my_str, obj.my_vec, obj.my_struct);
109+
deserialize(in, members);
114110
}
115111

116112
bool operator==(const custom_struct3& a, const custom_struct3& b)
@@ -127,7 +123,7 @@ namespace custom_namespace
127123
BOOST_AUTO_TEST_CASE(test_basic_types)
128124
{
129125
std::mt19937 eng(std::random_device{}());
130-
std::vector<uint8_t> buf1, buf2, buf3;
126+
std::vector<uint8_t> buf1, buf2;
131127

132128
for (int repeat = 0 ; repeat < 100000 ; ++repeat)
133129
{
@@ -176,13 +172,9 @@ BOOST_AUTO_TEST_CASE(test_basic_types)
176172
serialize(out, h);
177173
serialize(out, i);
178174
serialize(out, j);
179-
180-
auto out3 = sink(buf3);
181-
serialize_all(out3, b_, a, b, c, d, e, f, g, h, i, j);
182175
}
183176

184177
BOOST_TEST_REQUIRE(num_errors(buf1, buf2) == 0);
185-
BOOST_TEST_REQUIRE(num_errors(buf1, buf3) == 0);
186178

187179
// Test deserialization
188180
{
@@ -225,7 +217,6 @@ BOOST_AUTO_TEST_CASE(test_basic_types)
225217

226218
buf1.clear();
227219
buf2.clear();
228-
buf3.clear();
229220
}
230221
}
231222

0 commit comments

Comments
 (0)