ROS Resources: Documentation | Support | Discussion Forum | Service Status | Q&A
Ask Your Question

Can not write an instance of `rosbag::MessageInstance` to a `rosbag::Stream`

asked 2014-10-23 20:30:45 -0500

abarbarosie gravatar image

updated 2014-10-23 22:46:28 -0500

Consider the following peace of code:

for (rosbag::View::iterator m=view.begin(); m!=view.end(); m++){

Where stream is a variable of type rosbag::Stream. When I run the code I get the error:

In file included from *.cpp:6:0:
  /opt/ros/indigo/include/rosbag/bag.h: In instantiation of ‘void rosbag::Bag::readMessageDataIntoStream(const rosbag::IndexEntry&, Stream&) const [with Stream = rosbag::BZ2Stream]’:
  /opt/ros/indigo/include/rosbag/message_instance.h:170:5:   required from ‘void rosbag::MessageInstance::write(Stream&) const [with Stream = rosbag::BZ2Stream]’
  *.cpp:194:21:   required from here
  /opt/ros/indigo/include/rosbag/bag.h:367:118: error: ‘class rosbag::BZ2Stream’ has no member named ‘advance’
               memcpy(stream.advance(data_size), current_buffer_->getData() + index_entry.offset + bytes_read, data_size);

As you can see, internally ros library tries to call a method named .advance() on type rosbag::Stream. Now if we check the class reference for rosbag::Stream we can see that there is no method named advance() but rather advanceOffset(uint64_t nbytes) which looks like exactly what the library tries to call internally (at least the signature implies that this is what the library needs)

None of the derived classes rosbag::UncompressedStream nor rosbag::BZ2Stream have a method named advance().

Why do I get the above mentioned error and how can I fix it?

edit retag flag offensive close merge delete

1 Answer

Sort by » oldest newest most voted

answered 2014-10-24 02:43:50 -0500

ahendrix gravatar image

I'm not sure that's the appropriate way to use the rosbag API to read messages from one bag file and write them to another.

The last time I did this, my code looked something like:

rosbag::Bag output("output.bag", rosbag::bagmode::Write);

rosbag::Bag input("input.bag");
rosbag::View view(input, rosbag::TopicQuery("numbers"));

BOOST_FOREACH(rosbag::MessageInstance const m, view)
    output.write(m.getTopic(), m.getTime(), m, m.getConnectionHeader());

edit flag offensive delete link more


But that's just copying from one bag file to another... What if you need to interpret the message in your program?

abarbarosie gravatar imageabarbarosie ( 2014-10-24 05:14:05 -0500 )edit

I assumed that you were working with MessageInstances because you didn't need to interpret the data, or were doing so elsewhere.

ahendrix gravatar imageahendrix ( 2014-10-24 12:00:49 -0500 )edit

The rosbag API and the rosbag_storage API provide an rich API for extracting messages from bag files.

ahendrix gravatar imageahendrix ( 2014-10-24 12:01:49 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2014-10-23 20:30:45 -0500

Seen: 628 times

Last updated: Oct 24 '14