Open fzimmerm opened 6 years ago
auto msg = message_instance.instantiate<topic_tools::ShapeShifter>()
You should be able to then write that to another bag without having the c++ message type.
Unfortunately, the message instance only has when the message was written "bag write time" and not the "message time". For that, if you want to handle arbitrary types, you might want to look into something like ros_type_introspection
.
Thanks a lot for the hint, this should solve my problem! I'll post more feedback as soon as I have the time to try it out.
I've tried writing all messages to a new bag using topic_tools::ShapeShifter
. The resulting bag looks fine (same size, rosbag info
output looks correct), but when iterating over it using a rosbag::View
it will suddenly throw a ros::serialization::StreamOverrunException
. This isn't the case with the original bag. The same thing happened when using python to rewrite the bag.
@fzimmerm could you provide a minimal example of your code and a (ideally small) rosbag which reproduce this issue?
@fzimmerm Could you post a sample code here for writing all messages to a bag using topic_tools::ShapeShifter?
@cwecht @karthiknit Sorry but since I created this issue I've changed position, don't have access to the code in question anymore and am working on a topic unrelated to ROS. Thank you anyway!
for(rosbag::MessageInstance const mi : view)
{
out_bag.write(mi.getTopic(), mi.getTime(), mi);
}
Just found this will do the job.
I think this does the job only when you are reading from one bag and writting data to other bag
Yes, and I guess this will meet the requirement of fzimmerm.
I can confirm that solution by @shaozu works. I am able to ready a bag separate topics between the ones I want the ones I dont want and then write to the new bag only the ones I desire.
Hi,
I'm using the C++ rosbag API, and want to delete a single message from a bag. For this, I was thinking of opening the bag in
Read
mode, opening another bag inWrite
mode, and then iterate over allMessageInstance
in aView
of the original bag and write them to the new bag, except for messages with the same topic, type and time as the message I want to delete. But since the bag may contain messages of unknown types, I cannot instantiate theMessageInstance
. I saw thatMessageInstance
has a method for writing it into aStream
, and thatBag
has a private methodvoid Bag::write(char const* s, std::streamsize n)
, so in theory it should be possible to serialize allMessageInstance
into aStream
and writing it into the new bag, without knowing the individual message types, if thewrite
method weren't private.Long story short, it would be very useful to have a method to transfer messages between bags without knowing each message's type, in C++ (I think in python this doesn't pose a problem).