File: register_types_string.py

package info (click to toggle)
rosbags 0.11.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,940 kB
  • sloc: python: 19,988; makefile: 4
file content (21 lines) | stat: -rw-r--r-- 576 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""Example: Register type from definition string."""

from __future__ import annotations

from rosbags.typesys import Stores, get_types_from_msg, get_typestore

# Your custom message definition
STRIDX_MSG = """
string string
uint32 index
"""

typestore = get_typestore(Stores.ROS2_FOXY)
typestore.register(get_types_from_msg(STRIDX_MSG, 'custom_msgs/msg/StrIdx'))

StrIdx = typestore.types['custom_msgs/msg/StrIdx']

message = StrIdx(string='foo', index=42)

# Rawdata that can be passed to rosbag2.Writer.write
rawdata = typestore.serialize_cdr(message, message.__msgtype__)