Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions ros2topic/ros2topic/api/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,17 @@ def set_msg_fields(msg, values):
except ValueError as e:
raise SetFieldError(field_name, e)
try:
f_type = msg.get_slot_types()['_' + field_name]
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks pretty weird see ros2/rosidl_python#30 (comment) for more context and suggestion for stripping the leading underscores

# Check if field is an array of ROS message types
if f_type.find('/') != -1:
if isinstance(field_type(), list):
f_type = f_type[:f_type.rfind('[')]
field_elem_type = import_message_type('', f_type)
for n in range(len(value)):
submsg = field_elem_type()
set_msg_fields(submsg, value[n])
value[n] = submsg

setattr(msg, field_name, value)
except Exception as e:
raise SetFieldError(field_name, e)
Expand Down