Skip to content

Commit

Permalink
mqueue: fix serialization of array types.
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
Peter Soetens committed Sep 9, 2010
1 parent bc44169 commit 3b77b98
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
15 changes: 13 additions & 2 deletions rtt/transports/mqueue/binary_data_archive.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,11 +191,22 @@ namespace RTT
#endif
template<class T>
void load_override(const boost::serialization::nvp<T> & 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<class T>
void load_override(const boost::serialization::array<T> &t, int)
{
boost::serialization::array<T> tmp(t.address(), t.count());
*this >> tmp;
}

/**
* Loading Archive Concept::operator>>
* @param t The type to load.
Expand Down
32 changes: 32 additions & 0 deletions tests/mqueue_archive_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<io::array_sink> 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<io::array_source> inbuf(sink,1000);
binary_data_iarchive in( inbuf );
array<double> 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()

0 comments on commit 3b77b98

Please sign in to comment.