Skip to content

Commit

Permalink
Decode ROS2 raw byte data using rclpy.serialization.deserialize_message
Browse files Browse the repository at this point in the history
  ros2/rclpy#1273

Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya committed May 3, 2024
1 parent 886f1da commit 81f587f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions prover_rclpy/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@
'rclpy_1163_pub = src.rclpy_1163_pub:main',
'rclpy_1163_sub = src.rclpy_1163_sub:main',
'rclpy_1199 = src.rclpy_1199:main',
'rclpy_1273 = src.rclpy_1273:main',
'ros2cli_818 = src.ros2cli_818:main',
'ros2cli_862 = src.ros2cli_862:main',
'ros2cli_885 = src.ros2cli_885:main',
Expand Down
20 changes: 20 additions & 0 deletions prover_rclpy/src/rclpy_1273.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from std_msgs.msg import String
from rclpy.serialization import deserialize_message, serialize_message

# Serialized message data
#serialized_data = b'\x01\x03\x00\x00\x00\xb3\xa8\xbfFb\x89\xc8\x17\x00\x01\x00\x00I\x00\x00\x00Hello, world! Time(nanoseconds=1713770713401001821, clock_type=ROS_TIME)\x00\x00\x00\x00'

def main():
msg = String()
msg.data = 'Hello, world!'
msg_serialized = serialize_message(msg)
print(msg_serialized)
msg_deserialized = deserialize_message(msg_serialized, String)
print(msg_deserialized)

#message_type = String()
#decoded_data = deserialize_message(serialized_data, String)
#print(decoded_data)

if __name__ == "__main__":
main()

0 comments on commit 81f587f

Please sign in to comment.