Skip to content

Commit 1ca0760

Browse files
Added deserialization support for custom structs
1 parent 3c77720 commit 1ca0760

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

include/msgpack_describe.h

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,36 @@ namespace msgpackcpp
3030
});
3131
}
3232
}
33+
34+
template <
35+
class Source,
36+
class T,
37+
class D1 = boost::describe::describe_members<T, boost::describe::mod_any_access>
38+
>
39+
inline void deserialize(Source& in, T& obj, bool as_map = false)
40+
{
41+
if (as_map)
42+
{
43+
uint32_t size{};
44+
deserialize_map_size(in, size);
45+
if (size != boost::mp11::mp_size<D1>::value)
46+
throw std::system_error(BAD_SIZE);
47+
48+
boost::mp11::mp_for_each<D1>([&](auto D) {
49+
deserialize(in, D.name);
50+
deserialize(in, obj.*D.pointer);
51+
});
52+
}
53+
else
54+
{
55+
uint32_t size{};
56+
deserialize_array_size(in, size);
57+
if (size != boost::mp11::mp_size<D1>::value)
58+
throw std::system_error(BAD_SIZE);
59+
60+
boost::mp11::mp_for_each<D1>([&](auto D) {
61+
deserialize(in, obj.*D.pointer);
62+
});
63+
}
64+
}
3365
}

0 commit comments

Comments
 (0)