Robotics StackExchange | Archived questions

Is it possible to parse the fields and values of a custom ros msg binary file in python without knowing the message definition?

I have stored several files which contain the serialized binary data from custom ros messages. Now I'm attempting to parse the data in those files from a python script that knows nothing about the message definition or ros's messaging system at all, is this possible?

Asked by jrgnicho on 2017-02-16 11:05:44 UTC

Comments

Do you have just the binary stream (ie: exchanged by two nodes after negotiation), or also the topic/service negotiation data?

Asked by gvdhoorn on 2017-02-16 11:19:51 UTC

I have is the binary stream which was generated with ros::serialization::serialize from the message object, as well as .msg file definition.

Asked by jrgnicho on 2017-02-16 14:15:50 UTC

You mean you want to do the de-serialization yourself, without having to import custom_msg.msg? If yes you would be re-doing what genpy does. look at https://github.com/ros/genpy/blob/kinetic-devel/src/genpy/generator.py

Asked by afakih on 2017-02-16 14:49:41 UTC

afakih yes that's what I meant, thanks for the link. It isn't obvious to me from looking at that genpy code how I would de-serialize binary data from a custom message.

Asked by jrgnicho on 2017-02-16 15:20:17 UTC

You would need to do something similar to what's is in 'msg_generator` function which generates python code from the .msg. To load the .msg into a MsgSpec you would need something similar to https://github.com/ros/genmsg/blob/indigo-devel/src/genmsg/msg_loader.py

Asked by afakih on 2017-02-16 16:28:45 UTC

I do have the definition message file (an MyMsg.msg file) and several other files with serialized data generated from instances of my custom message. The libraries you pointed to allow you to create a MsgSpec instance but it doesn't look like there's a way of filling it with the serialized data.

Asked by jrgnicho on 2017-02-17 14:07:07 UTC

Answers