From 3b77b98c473395f82945250681b3208788731fac Mon Sep 17 00:00:00 2001 From: Peter Soetens Date: Thu, 9 Sep 2010 13:44:52 +0200 Subject: [PATCH] mqueue: fix serialization of array types. make_array() returns a const& to a boost::serialization::array object, which is unusable for loading (due to the const). A specialisation catches this case and forwards it with a &boost::serialization::array object. Signed-off-by: Peter Soetens --- rtt/transports/mqueue/binary_data_archive.hpp | 15 +++++++-- tests/mqueue_archive_test.cpp | 32 +++++++++++++++++++ 2 files changed, 45 insertions(+), 2 deletions(-) diff --git a/rtt/transports/mqueue/binary_data_archive.hpp b/rtt/transports/mqueue/binary_data_archive.hpp index e621a67ce..d16787ad7 100644 --- a/rtt/transports/mqueue/binary_data_archive.hpp +++ b/rtt/transports/mqueue/binary_data_archive.hpp @@ -191,11 +191,22 @@ namespace RTT #endif template void load_override(const boost::serialization::nvp & t, int){ - T x; + T& x(t.value()); * this >> x; - t.value() = x; } + /** + * Specialisation that covers a boost serialization array created with make_array() + * @param t + * @return *this + */ + template + void load_override(const boost::serialization::array &t, int) + { + boost::serialization::array tmp(t.address(), t.count()); + *this >> tmp; + } + /** * Loading Archive Concept::operator>> * @param t The type to load. diff --git a/tests/mqueue_archive_test.cpp b/tests/mqueue_archive_test.cpp index 8f4ccb35a..df41c12ce 100644 --- a/tests/mqueue_archive_test.cpp +++ b/tests/mqueue_archive_test.cpp @@ -116,5 +116,37 @@ BOOST_AUTO_TEST_CASE( testFixedStringBinaryDataArchive ) rtos_disable_rt_warning(); } +/** + * For serializing C-Style arrays created with make_nvp("array", make_array() ) + */ +BOOST_AUTO_TEST_CASE( testMakeArrayBinaryDataArchive ) +{ + char sink[1000]; + memset( sink, 0, 1000); + double c[10] = {-1,1,2,3,4,5,6,7,8,9}; + double r[10] = {0,0,0,0,0,0,0,0,0,0}; + + rtos_enable_rt_warning(); + io::stream outbuf(sink,1000); + binary_data_oarchive out( outbuf ); + out & make_nvp("array", make_array(c, 10) ); + + unsigned int stored = out.getArchiveSize(); + BOOST_CHECK( stored >= 10*sizeof(double) ); + rtos_disable_rt_warning(); + + rtos_enable_rt_warning(); + io::stream inbuf(sink,1000); + binary_data_iarchive in( inbuf ); + array ma = make_array(r, 10); + in & make_nvp("array", make_array(r, 10) ); + + BOOST_CHECK_EQUAL(r[0], c[0]); + BOOST_CHECK_EQUAL(r[4], c[4]); + BOOST_CHECK_EQUAL(r[9], c[9]); + BOOST_CHECK_EQUAL( stored, in.getArchiveSize() ); + rtos_disable_rt_warning(); +} + BOOST_AUTO_TEST_SUITE_END()