Skip to content

Commit 960962a

Browse files
achim-kclalancette
andauthored
Add marshalling functions for rclpy.type_hash.TypeHash (rep2011) (#816)
* Add marshalling functions for rclpy.type_hash.TypeHash Signed-off-by: Hans-Joachim Krauch <[email protected]> Co-authored-by: Chris Lalancette <[email protected]>
1 parent 1079f84 commit 960962a

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

ros2cli/ros2cli/xmlrpc/marshal/rclpy.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import rclpy.duration
2020
import rclpy.qos
2121
import rclpy.topic_endpoint_info
22+
import rclpy.type_hash
2223

2324
from .generic import dump_any_enum
2425
from .generic import dump_any_with_slots
@@ -75,3 +76,16 @@ def dump_duration(marshaller, value, write):
7576
functools.partial(end_any_enum, enum_=rclpy.topic_endpoint_info.TopicEndpointTypeEnum)
7677

7778
Marshaller.dispatch[rclpy.topic_endpoint_info.TopicEndpointTypeEnum] = dump_any_enum
79+
80+
81+
def end_type_hash(unmarshaller, data):
82+
values = unmarshaller._stack[-1]
83+
unmarshaller._stack[-1] = rclpy.type_hash.TypeHash(
84+
version=int(values['version']), value=values['value'].data)
85+
unmarshaller._value = 0
86+
87+
88+
Unmarshaller.dispatch[fullname(rclpy.type_hash.TypeHash)] = end_type_hash
89+
90+
Marshaller.dispatch[rclpy.type_hash.TypeHash] = \
91+
functools.partial(dump_any_with_slots, transform=lambda slot: slot.lstrip('_'))

ros2topic/ros2topic/verb/info.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ def add_arguments(self, parser, cli_name):
3232
'-v',
3333
action='store_true',
3434
help='Prints detailed information like the node name, node namespace, topic type, '
35-
'GUID and QoS Profile of the publishers and subscribers to this topic')
35+
'topic type hash, GUID, and QoS Profile of the publishers and subscribers to '
36+
'this topic')
3637
arg.completer = TopicNameCompleter(
3738
include_hidden_topics_key='include_hidden_topics')
3839

ros2topic/test/test_cli.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,10 @@ def test_topic_endpoint_info(self):
305305

306306
@launch_testing.markers.retry_on_failure(times=5)
307307
def test_topic_endpoint_info_verbose(self):
308+
# Hash value below can be found in std_msgs/msg/String.json
309+
STD_MSGS_STRING_TYPE_HASH_STR = 'RIHS01_' \
310+
'df668c740482bbd48fb39d76a70dfd4bd59db1288021743503259e948f6b1a18'
311+
308312
with self.launch_topic_command(arguments=['info', '-v', '/chatter']) as topic_command:
309313
assert topic_command.wait_for_shutdown(timeout=10)
310314
assert topic_command.exit_code == launch_testing.asserts.EXIT_OK
@@ -317,7 +321,7 @@ def test_topic_endpoint_info_verbose(self):
317321
re.compile(r'Node name: \w+'),
318322
'Node namespace: /',
319323
'Topic type: std_msgs/msg/String',
320-
'Topic type hash: UNKNOWN',
324+
f'Topic type hash: {STD_MSGS_STRING_TYPE_HASH_STR}',
321325
re.compile(r'Endpoint type: (INVALID|PUBLISHER|SUBSCRIPTION)'),
322326
re.compile(r'GID: [\w\.]+'),
323327
'QoS profile:',

0 commit comments

Comments
 (0)