deserialize_cdr throws assertion error when deserializing a custom message with fixed size arrays
Your Environment
-
Your operating system: Ubuntu 22.04
-
Version of python you are running (
python --version
): Python 3.10.12 -
How did you install rosbags? Did you use pip to install from PyPI or a repository checkout or something else? PyPI
-
Version of rosbags you have installed (
pip show rosbags | grep Version
): Version: 0.9.19
The Issue
Hi, I want to read a rosbag2 file, which contains a custom message with fixed size arrays:
float64 period
float64[4] duty_factor
float64[4] phase_offset
bool[4] contact
float64[4] phase
I register the type using this function:
def register_costom_message_types():
for path in glob.glob(f"{WS_DIR}/src/interfaces/msg/*.msg"):
msg_def = Path(path).read_text(encoding='utf-8')
register_types(get_types_from_msg(msg_def,"interfaces/msg/" + Path(path).stem))
and read the file with
from rosbags.rosbag2.reader import Reader
with Reader(path) as reader:
connections = [x for x in reader.connections if x.topic in {'/my_msg'}]
for connection, timestamp, rawdata in reader.messages(connections=connections):
msg = deserialize_cdr(rawdata, connection.msgtype)
This throws an assertion error:
File "file.py", line xx, in fkt
msg = reader.deserialize(rawdata, connection.msgtype)
File "~/.local/lib/python3.10/site-packages/rosbags/highlevel/anyreader.py", line 113, in deserialize
return self._deser_ros2(rawdata, typ) if self.is2 else self._deser_ros1(rawdata, typ)
File "~/.local/lib/python3.10/site-packages/rosbags/highlevel/anyreader.py", line 109, in _deser_ros2
return deserialize_cdr(rawdata, typ, self.typestore)
File "~/.local/lib/python3.10/site-packages/rosbags/serde/serdes.py", line 42, in deserialize_cdr
assert pos + 4 + 3 >= len(rawdata)
AssertionError
The bytes of the message are e.g.:
b'\x00\x01\x00\x00h\xce:\x8b\x1e\x9f\x02@\x02\xea\x10\x85\x18\xf0\xed?\x02\xea\x10\x85\x18\xf0\xed?\x02\xea\x10\x85\x18\xf0\xed?\x02\xea\x10\x85\x18\xf0\xed?\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\xe0?\x00\x00\x00\x00\x00\x00\xe8?\x00\x00\x00\x00\x00\x00\xd0?\x01\x01\x01\x01\x00\x00\x00\x00?jh\xeb\xfd\xe2\xd6? 5\xb4\xf5~q\xeb? 5\xb4\xf5~q\xe3?\xf9\xa8\xa1\xad\xf7\x8b\xbb?'
This error happens only when I use the fixed size arrays in the custom msg. When I remove the size, e.g.
float64 period
float64[] duty_factor
float64[] phase_offset
bool[] contact
float64[] phase
Everything works as expected (with a new rosbag file where I send this type obviously