Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(set_message): encode strings if field is bytes #30

Open
wants to merge 3 commits into
base: rolling
Choose a base branch
from
Open
Changes from 1 commit
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
6 changes: 4 additions & 2 deletions rosidl_runtime_py/set_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@


def set_message_fields(
msg: Any, values: Dict[str, str], expand_header_auto: bool = False,
msg: Any, values: Dict[str, Any], expand_header_auto: bool = False,
expand_time_now: bool = False) -> List[Any]:
"""
Set the fields of a ROS message.
Expand All @@ -52,7 +52,7 @@ def set_message_fields(
timestamp_fields = []

def set_message_fields_internal(
msg: Any, values: Dict[str, str],
msg: Any, values: Dict[str, Any],
timestamp_fields: List[Any]) -> List[Any]:
try:
items = values.items()
Expand All @@ -70,6 +70,8 @@ def set_message_fields_internal(
value = numpy.array(field_value, dtype=field.dtype)
elif type(field_value) is field_type:
value = field_value
elif field_type is bytes and type(field_value) is str:
value = field_value.encode()
# We can't import these types directly, so we use the qualified class name to
# distinguish them from other fields
elif qualified_class_name == 'std_msgs.msg._header.Header' and \
Expand Down