Skip to content

Commit

Permalink
move dict construction to rosidl_runtime_py
Browse files Browse the repository at this point in the history
Signed-off-by: Mikael Arguedas <[email protected]>
  • Loading branch information
mikaelarguedas committed Mar 28, 2019
1 parent a523cee commit ed01243
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 10 deletions.
6 changes: 0 additions & 6 deletions rosidl_generator_py/resource/_idl.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ msg_required_import_imported = False
@[for message in content.get_elements_of_type(Message)]@
@[ if not msg_required_import_imported]@
@{msg_required_import_imported = True}@
from collections import OrderedDict

import rosidl_parser.definition
@[ end if]@
@{
Expand All @@ -45,8 +43,6 @@ from rosidl_parser.definition import Service
@[for service in content.get_elements_of_type(Service)]@
@[ if not msg_required_import_imported]@
@{msg_required_import_imported = True}@
from collections import OrderedDict

import rosidl_parser.definition
@[ end if]@
@{
Expand All @@ -66,8 +62,6 @@ from rosidl_parser.definition import Action
@[for action in content.get_elements_of_type(Action)]@
@[ if not msg_required_import_imported]@
@{msg_required_import_imported = True}@
from collections import OrderedDict

import rosidl_parser.definition
@[ end if]@
@{
Expand Down
4 changes: 0 additions & 4 deletions rosidl_generator_py/resource/_msg.py.em
Original file line number Diff line number Diff line change
Expand Up @@ -299,10 +299,6 @@ if isinstance(type_, NestedType):
return False
@[end for]@
return True

@@classmethod
def get_slot_types(cls):
return OrderedDict(zip([s[1:] for s in cls.__slots__], cls.SLOT_TYPES))
@[for member in message.structure.members]@

@{
Expand Down
1 change: 1 addition & 0 deletions rosidl_runtime_py/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<exec_depend>python3-numpy</exec_depend>
<exec_depend>python3-yaml</exec_depend>
<exec_depend>rosidl_parser</exec_depend>

<test_depend>ament_copyright</test_depend>
<test_depend>ament_flake8</test_depend>
Expand Down
4 changes: 4 additions & 0 deletions rosidl_runtime_py/rosidl_runtime_py/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,16 @@
from .convert import message_to_csv
from .convert import message_to_ordereddict
from .convert import message_to_yaml
from .convert import slot_types_dict_from_message
from .import_message import import_message_from_namespaced_type
from .set_message import set_message_fields


__all__ = [
'import_message_from_namespaced_type',
'message_to_csv',
'message_to_ordereddict',
'message_to_yaml',
'set_message_fields',
'slot_types_dict_from_message',
]
11 changes: 11 additions & 0 deletions rosidl_runtime_py/rosidl_runtime_py/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,14 @@ def _convert_value(value, truncate_length=None):
# Assuming value is a message since it is neither a collection nor a primitive type
value = message_to_ordereddict(value, truncate_length=truncate_length)
return value


def slot_types_dict_from_message(msg: Any) -> OrderedDict:
"""
Return an OrderedDict of the slot types of a message.
:param msg: The ROS message to convert.
This does not truncate the list of message fields.
:returns: An OrderedDict with message member names as keys and slot types as values.
"""
return OrderedDict(zip([s[1:] for s in msg.__slots__], msg.SLOT_TYPES))

0 comments on commit ed01243

Please sign in to comment.