@@ -74,6 +74,8 @@ def add_arguments(self, parser, cli_name):
7474 '--no-str' , action = 'store_true' , help = "Don't print string fields of messages" )
7575 parser .add_argument (
7676 '--lost-messages' , action = 'store_true' , help = 'Report when a message is lost' )
77+ parser .add_argument (
78+ '--raw' , action = 'store_true' , help = 'Echo the raw binary representation' )
7779
7880 def main (self , * , args ):
7981 return main (args )
@@ -101,7 +103,13 @@ def main(args):
101103 'Could not determine the type for the passed topic' )
102104
103105 subscriber (
104- node , args .topic_name , message_type , callback , qos_profile , args .lost_messages )
106+ node ,
107+ args .topic_name ,
108+ message_type ,
109+ callback ,
110+ qos_profile ,
111+ args .lost_messages ,
112+ args .raw )
105113
106114
107115def subscriber (
@@ -110,7 +118,8 @@ def subscriber(
110118 message_type : MsgType ,
111119 callback : Callable [[MsgType ], Any ],
112120 qos_profile : QoSProfile ,
113- report_lost_messages : bool
121+ report_lost_messages : bool ,
122+ raw : bool
114123) -> Optional [str ]:
115124 """Initialize a node with a single subscription and spin."""
116125 event_callbacks = None
@@ -119,7 +128,12 @@ def subscriber(
119128 message_lost = message_lost_event_callback )
120129 try :
121130 node .create_subscription (
122- message_type , topic_name , callback , qos_profile , event_callbacks = event_callbacks )
131+ message_type ,
132+ topic_name ,
133+ callback ,
134+ qos_profile ,
135+ event_callbacks = event_callbacks ,
136+ raw = raw )
123137 except UnsupportedEventTypeError :
124138 assert report_lost_messages
125139 print (
@@ -132,18 +146,23 @@ def subscriber(
132146def subscriber_cb (truncate_length , noarr , nostr ):
133147 def cb (msg ):
134148 nonlocal truncate_length , noarr , nostr
135- print (
136- message_to_yaml (
137- msg , truncate_length = truncate_length , no_arr = noarr , no_str = nostr ),
138- end = '---\n ' )
149+ if isinstance (msg , bytes ):
150+ print (msg , end = '\n ---\n ' )
151+ else :
152+ print (
153+ message_to_yaml (
154+ msg , truncate_length = truncate_length , no_arr = noarr , no_str = nostr ),
155+ end = '---\n ' )
139156 return cb
140157
141158
142159def subscriber_cb_csv (truncate_length , noarr , nostr ):
143160 def cb (msg ):
144161 nonlocal truncate_length , noarr , nostr
145- print (message_to_csv (msg , truncate_length = truncate_length ,
146- no_arr = noarr , no_str = nostr ))
162+ if isinstance (msg , bytes ):
163+ print (msg )
164+ else :
165+ print (message_to_csv (msg , truncate_length = truncate_length , no_arr = noarr , no_str = nostr ))
147166 return cb
148167
149168
0 commit comments