genpy icon indicating copy to clipboard operation
genpy copied to clipboard

Problems with Message definitions containing backslashes in comments

Open benjaminsoellner opened this issue 3 years ago • 0 comments

Given you have some message definition like the following (SomeMessage.msg):

# \brief Some description
# \note Something I really want to stress
float64 x

... genpy will not escape the slashes when writing the _full_text member for the message serialization / deserialization classes.

In fact, a bagfile will contain the invalid message definition:

Header header
#rief Some description
# 
ote Something I really want to stress
float64 x

... invalidating the stored message and md5hash.

For the given example you can try this out with:

from your_package.msg import SomeMessage
constructed_msg = SomeMessage()
# output the message definition: without the fix you should see \b and especially \n screwing up the message definition,
# introducing a weird new "ote" field for the "# \note" comment
print(constructed_msg._full_text)
with rosbag.Bag("/tmp/test.bag", "w") as bag:
  bag.write("/some_topic", constructed_msg, genpy.Time.from_sec(0))
with rosbag.Bag("/tmp/test.bag") as bag:
  # attempt to read the message again. You will get an empty message and a md5sum-error without the fix
  next(bag.read_messages(topics=["/some_topic"])

benjaminsoellner avatar Apr 09 '21 15:04 benjaminsoellner