Hi
you can dump the message into a binary buffer. Attached you can see how I did it with a sensor_msgs::LaserScan.
void LaserLineFilterNode::callback (const sensor_msgs::LaserScan::ConstPtr& _msg) {
{
// Write to File
std::ofstream ofs("/tmp/filename.txt", std::ios::out|std::ios::binary);
uint32_t serial_size = ros::serialization::serializationLength(*_msg);
boost::shared_array<uint8_t> obuffer(new uint8_t[serial_size]);
ros::serialization::OStream ostream(obuffer.get(), serial_size);
ros::serialization::serialize(ostream, *_msg);
ofs.write((char*) obuffer.get(), serial_size);
ofs.close();
}
{
// Read from File to msg_scan_
//sensor_msgs::LaserScan msg_scan_ --> is a class variable
std::ifstream ifs("/tmp/filename.txt", std::ios::in|std::ios::binary);
ifs.seekg (0, std::ios::end);
std::streampos end = ifs.tellg();
ifs.seekg (0, std::ios::beg);
std::streampos begin = ifs.tellg();
uint32_t file_size = end-begin;
boost::shared_array<uint8_t> ibuffer(new uint8_t[file_size]);
ifs.read((char*) ibuffer.get(), file_size);
ros::serialization::IStream istream(ibuffer.get(), file_size);
ros::serialization::deserialize(istream, msg_scan_);
ifs.close();
}
....
More details on http://wiki.ros.org/roscpp/Overview/M...
But I there is still an issue, I had to create a memory buffer fist, it would be nice to see how one can create a ros::serialization::OStream to stream directly into a file.
Hmm... I will post a separate question for that :-)
Greetings
Markus
This is similar to http://answers.ros.org/question/10330...