Skip to content

message_registry

Message Registry - Loads and manages ROS2 message definitions from .msg files

MessageRegistry

Registry for loading and managing ROS2 message definitions

Source code in zenoh_ros2_sdk/message_registry.py
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
class MessageRegistry:
    """Registry for loading and managing ROS2 message definitions"""

    def __init__(self, messages_dir: Optional[str] = None):
        """
        Initialize message registry

        Args:
            messages_dir: Directory containing message files (default: SDK messages directory)
        """
        if messages_dir is None:
            # Default to SDK's messages directory
            sdk_dir = Path(__file__).parent.parent
            messages_dir = str(sdk_dir / "messages")

        self.messages_dir = Path(messages_dir)
        # Import at module level (no lazy loading)
        # We use a property to get the session dynamically to ensure we always use the current session
        # (important when singleton is reset in tests)
        from .session import ZenohSession
        self._ZenohSession = ZenohSession  # Store class reference
        self._loaded_types: Set[str] = set()

    @property
    def session(self):
        """Get the current ZenohSession instance (always fresh)"""
        return self._ZenohSession.get_instance()

    def get_msg_file_path(self, msg_type: str) -> Optional[Path]:
        """
        Get the path to a .msg file for a given message type.
        First checks local messages directory, then tries to download from git.

        Args:
            msg_type: ROS2 message type (e.g., "geometry_msgs/msg/Vector3")

        Returns:
            Path to .msg file or None if not found
        """
        parts = msg_type.split("/")
        if len(parts) != 3:
            return None

        namespace, msg, message_name = parts

        # First, check local messages directory
        msg_file = self.messages_dir / namespace / msg / f"{message_name}.msg"
        if msg_file.exists():
            return msg_file

        # If not found locally, try to download from git repository
        try:
            # Find which repository contains this package
            repo_name = get_repository_for_package(namespace)
            if repo_name:
                git_path = get_message_file_path(msg_type, repo_name)
                if git_path and os.path.exists(git_path):
                    return Path(git_path)
        except ImportError as e:
            # GitPython not available - log warning but don't fail
            logger.warning(
                f"GitPython not available. Cannot auto-download message file for {msg_type}. "
                f"Install GitPython with 'pip install GitPython' to enable auto-download. "
                f"Error: {e}"
            )
        except Exception as e:
            # Log the error but don't fail - user can add message manually
            logger.warning(
                f"Failed to auto-download message file for {msg_type} from git repository: {e}. "
                f"You may need to add the message file manually."
            )

        return None

    def get_srv_file_path(self, srv_type: str, is_request: bool = True) -> Optional[Path]:
        """
        Get the path to a .srv file for a given service type.
        First checks local messages directory, then tries to download from git.

        Args:
            srv_type: ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")
            is_request: If True, return path for request part; if False, for response part

        Returns:
            Path to .srv file or None if not found
        """
        parts = srv_type.split("/")
        if len(parts) != 3:
            return None

        namespace, srv, service_name = parts

        # First, check local messages directory
        srv_file = self.messages_dir / namespace / srv / f"{service_name}.srv"
        if srv_file.exists():
            return srv_file

        # If not found locally, try to download from git repository
        try:
            # Find which repository contains this package
            repo_name = get_repository_for_package(namespace)
            if repo_name:
                try:
                    repo_path = clone_to_cache(repo_name)
                    repository = MESSAGE_REPOSITORIES[repo_name]

                    # Construct path to service file using shared helper function
                    srv_file_path = construct_message_path(
                        repo_path, repository, namespace, srv, service_name
                    )

                    if os.path.exists(srv_file_path):
                        return Path(srv_file_path)
                except Exception as e:
                    logger.warning(
                        f"Failed to get service file from cache for {srv_type}: {e}. "
                        f"Trying to clone repository..."
                    )
        except ImportError as e:
            # GitPython not available - log warning but don't fail
            logger.warning(
                f"GitPython not available. Cannot auto-download service file for {srv_type}. "
                f"Install GitPython with 'pip install GitPython' to enable auto-download. "
                f"Error: {e}"
            )
        except Exception as e:
            # Log the error but don't fail - user can add message manually
            logger.warning(
                f"Failed to auto-download service file for {srv_type} from git repository: {e}. "
                f"You may need to add the service file manually."
            )

        return None

    def _load_service_types(self, srv_type: str, visited: Optional[Set[str]] = None):
        """
        Load service request and response types from a .srv file

        Args:
            srv_type: ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")
            visited: Set of already visited types to prevent cycles
        """
        if visited is None:
            visited = set()

        # Parse service type to get request and response types
        parts = srv_type.split("/")
        if len(parts) != 3:
            raise ValueError(f"Invalid service type format: {srv_type}")

        namespace_part, srv, service_name_part = parts
        request_type = f"{namespace_part}/srv/{service_name_part}_Request"
        response_type = f"{namespace_part}/srv/{service_name_part}_Response"

        if request_type in visited or response_type in visited:
            return

        visited.add(request_type)
        visited.add(response_type)

        # Load the service file
        srv_file = self.get_srv_file_path(srv_type)
        if not srv_file:
            raise FileNotFoundError(
                f"Service file not found for type: {srv_type}. "
                f"Please ensure the service type is available in the message registry or provide the service definition manually."
            )

        # Read service definition
        try:
            with open(srv_file, 'r') as f:
                srv_definition = f.read()
        except Exception as e:
            raise IOError(f"Failed to read service file {srv_file}: {e}") from e

        # Split into request and response parts
        parts = srv_definition.split('---')
        if len(parts) != 2:
            raise ValueError(
                f"Invalid service file format for {srv_type}: expected '---' separator. "
                f"Found {len(parts)} parts instead of 2."
            )

        request_definition = parts[0].strip()
        response_definition = parts[1].strip()

        if not request_definition:
            raise ValueError(f"Empty request definition in service file for {srv_type}")
        if not response_definition:
            raise ValueError(f"Empty response definition in service file for {srv_type}")

        # Extract dependencies for request and response
        request_deps = self._extract_dependencies(request_definition, request_type)
        response_deps = self._extract_dependencies(response_definition, response_type)

        # Load dependencies first
        for dep_type in request_deps + response_deps:
            if dep_type not in self._loaded_types and dep_type not in visited:
                try:
                    self._load_dependencies(dep_type, visited.copy())
                except Exception as e:
                    logger.error(
                        f"Failed to load dependency {dep_type} for service {srv_type}: {e}. "
                        f"This may cause service type registration to fail."
                    )
                    # Continue loading other dependencies, but log the error
                    # The registration will fail later if the dependency is truly required

        # Register request and response types
        try:
            if request_type not in self.session._registered_types:
                self.session.register_message_type(request_definition, request_type)
            if response_type not in self.session._registered_types:
                self.session.register_message_type(response_definition, response_type)
        except Exception as e:
            raise RuntimeError(
                f"Failed to register service types for {srv_type}: {e}. "
                f"Request type: {request_type}, Response type: {response_type}"
            ) from e

        self._loaded_types.add(request_type)
        self._loaded_types.add(response_type)

    def load_service_type(self, srv_type: str) -> bool:
        """
        Load a service type (request and response) and their dependencies

        Args:
            srv_type: ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")

        Returns:
            True if loaded successfully, False otherwise
        """
        try:
            self._load_service_types(srv_type)
            return True
        except Exception as e:
            logger.warning(f"Failed to load service type {srv_type}: {e}", exc_info=True)
            return False

    def _load_dependencies(self, msg_type: str, visited: Optional[Set[str]] = None):
        """
        Recursively load message type and its dependencies

        Args:
            msg_type: ROS2 message type to load
            visited: Set of already visited types to prevent cycles
        """
        if visited is None:
            visited = set()

        if msg_type in visited or msg_type in self._loaded_types:
            return

        visited.add(msg_type)

        # Load the message file (checks local first, then downloads from git if needed)
        msg_file = self.get_msg_file_path(msg_type)
        if not msg_file:
            # Try one more time after potential download
            msg_file = self.get_msg_file_path(msg_type)
            if not msg_file:
                # Message file not found - raise exception so it can be caught and logged
                raise FileNotFoundError(f"Message file not found for type: {msg_type}")

        # Read message definition
        with open(msg_file, 'r') as f:
            msg_definition = f.read()

        # Parse dependencies from the message definition
        dependencies = self._extract_dependencies(msg_definition, msg_type)

        # Load dependencies first (recursively)
        for dep_type in dependencies:
            if dep_type not in self._loaded_types:
                self._load_dependencies(dep_type, visited.copy())

        # Register this message type (only if not already registered)
        if msg_type not in self.session._registered_types:
            self.session.register_message_type(msg_definition, msg_type)
        self._loaded_types.add(msg_type)

    def _extract_dependencies(self, msg_definition: str, current_type: str) -> list:
        """
        Extract message type dependencies from a message definition

        Args:
            msg_definition: Message definition text
            current_type: Current message type (for namespace resolution)

        Returns:
            List of dependency message types
        """
        dependencies = []
        parts = current_type.split("/")
        if len(parts) != 3:
            return dependencies

        namespace, _, _ = parts

        # Parse lines to find type references
        for line in msg_definition.split('\n'):
            # Remove comments first
            if '#' in line:
                line = line[:line.index('#')]
            line = line.strip()
            # Skip empty lines
            if not line:
                continue

            # Skip separator lines
            if line.startswith('---'):
                continue

            # Check for type references (format: TypeName field_name)
            words = line.split()
            if len(words) >= 2:
                type_name = words[0]

                # Strip array notation: string[] -> string, geometry_msgs/msg/Vector3[10] -> geometry_msgs/msg/Vector3
                base_type = type_name
                if '[' in type_name:
                    base_type = type_name.split('[')[0]

                # Check if it's a custom type (not a primitive)
                primitives = ['bool', 'int8', 'uint8', 'int16', 'uint16',
                            'int32', 'uint32', 'int64', 'uint64',
                            'float32', 'float64', 'string', 'time', 'duration',
                            'byte', 'char', 'wchar', 'wstring', 'octet']

                if base_type not in primitives and not base_type.startswith('['):
                    # Resolve namespace
                    if '/' in base_type:
                        # Could be: builtin_interfaces/Time or geometry_msgs/msg/Vector3
                        parts = base_type.split('/')
                        if len(parts) == 2:
                            # Format: namespace/TypeName -> convert to namespace/msg/TypeName
                            dep_type = f"{parts[0]}/msg/{parts[1]}"
                        else:
                            # Already full path: namespace/msg/TypeName
                            dep_type = base_type
                    else:
                        # Short name: assume same namespace
                        dep_type = f"{namespace}/msg/{base_type}"

                    if dep_type not in dependencies:
                        dependencies.append(dep_type)

        return dependencies

    def load_message_type(self, msg_type: str) -> bool:
        """
        Load a message type and its dependencies

        Args:
            msg_type: ROS2 message type (e.g., "geometry_msgs/msg/Twist")

        Returns:
            True if loaded successfully, False otherwise
        """
        try:
            self._load_dependencies(msg_type)
            return True
        except Exception as e:
            logger.warning(f"Failed to load message type {msg_type}: {e}")
            return False

    def get_message_class(self, msg_type: str) -> Optional[Type[Any]]:
        """
        Get a message class for a given type (loads if not already loaded)

        Args:
            msg_type: ROS2 message type

        Returns:
            Optional[Type[Any]]: Message class or None if not found
        """
        if msg_type not in self._loaded_types:
            # Service request/response types cannot be loaded from a single .msg file path.
            # They must be loaded from the parent .srv file.
            is_service_req_resp = (
                "/srv/" in msg_type and (msg_type.endswith("_Request") or msg_type.endswith("_Response"))
            )
            if is_service_req_resp:
                # example_interfaces/srv/AddTwoInts_Request -> example_interfaces/srv/AddTwoInts
                if msg_type.endswith("_Request"):
                    base_srv = msg_type[:-8]
                else:
                    base_srv = msg_type[:-9]
                if not self.load_service_type(base_srv):
                    return None
            else:
                if not self.load_message_type(msg_type):
                    return None

        # Check if we have a mapping to the actual store key (for service types)
        actual_key = self.session._registered_types.get(msg_type)
        if actual_key and isinstance(actual_key, str):
            # actual_key is the store key (may be converted name)
            return self.session.store.types.get(actual_key)

        # Try direct lookup
        msg_class = self.session.store.types.get(msg_type)
        if msg_class is not None:
            return msg_class

        # Try with /msg/ inserted (for service types: srv/ -> srv/msg/)
        if '/srv/' in msg_type:
            converted_name = msg_type.replace('/srv/', '/srv/msg/')
            return self.session.store.types.get(converted_name)

        return None

    def is_loaded(self, msg_type: str) -> bool:
        """Check if a message type is already loaded"""
        return msg_type in self._loaded_types

session property

Get the current ZenohSession instance (always fresh)

get_msg_file_path(msg_type: str) -> Optional[Path]

Get the path to a .msg file for a given message type. First checks local messages directory, then tries to download from git.

Parameters:

Name Type Description Default
msg_type str

ROS2 message type (e.g., "geometry_msgs/msg/Vector3")

required

Returns:

Type Description
Optional[Path]

Path to .msg file or None if not found

Source code in zenoh_ros2_sdk/message_registry.py
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
def get_msg_file_path(self, msg_type: str) -> Optional[Path]:
    """
    Get the path to a .msg file for a given message type.
    First checks local messages directory, then tries to download from git.

    Args:
        msg_type: ROS2 message type (e.g., "geometry_msgs/msg/Vector3")

    Returns:
        Path to .msg file or None if not found
    """
    parts = msg_type.split("/")
    if len(parts) != 3:
        return None

    namespace, msg, message_name = parts

    # First, check local messages directory
    msg_file = self.messages_dir / namespace / msg / f"{message_name}.msg"
    if msg_file.exists():
        return msg_file

    # If not found locally, try to download from git repository
    try:
        # Find which repository contains this package
        repo_name = get_repository_for_package(namespace)
        if repo_name:
            git_path = get_message_file_path(msg_type, repo_name)
            if git_path and os.path.exists(git_path):
                return Path(git_path)
    except ImportError as e:
        # GitPython not available - log warning but don't fail
        logger.warning(
            f"GitPython not available. Cannot auto-download message file for {msg_type}. "
            f"Install GitPython with 'pip install GitPython' to enable auto-download. "
            f"Error: {e}"
        )
    except Exception as e:
        # Log the error but don't fail - user can add message manually
        logger.warning(
            f"Failed to auto-download message file for {msg_type} from git repository: {e}. "
            f"You may need to add the message file manually."
        )

    return None

get_srv_file_path(srv_type: str, is_request: bool = True) -> Optional[Path]

Get the path to a .srv file for a given service type. First checks local messages directory, then tries to download from git.

Parameters:

Name Type Description Default
srv_type str

ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")

required
is_request bool

If True, return path for request part; if False, for response part

True

Returns:

Type Description
Optional[Path]

Path to .srv file or None if not found

Source code in zenoh_ros2_sdk/message_registry.py
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
def get_srv_file_path(self, srv_type: str, is_request: bool = True) -> Optional[Path]:
    """
    Get the path to a .srv file for a given service type.
    First checks local messages directory, then tries to download from git.

    Args:
        srv_type: ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")
        is_request: If True, return path for request part; if False, for response part

    Returns:
        Path to .srv file or None if not found
    """
    parts = srv_type.split("/")
    if len(parts) != 3:
        return None

    namespace, srv, service_name = parts

    # First, check local messages directory
    srv_file = self.messages_dir / namespace / srv / f"{service_name}.srv"
    if srv_file.exists():
        return srv_file

    # If not found locally, try to download from git repository
    try:
        # Find which repository contains this package
        repo_name = get_repository_for_package(namespace)
        if repo_name:
            try:
                repo_path = clone_to_cache(repo_name)
                repository = MESSAGE_REPOSITORIES[repo_name]

                # Construct path to service file using shared helper function
                srv_file_path = construct_message_path(
                    repo_path, repository, namespace, srv, service_name
                )

                if os.path.exists(srv_file_path):
                    return Path(srv_file_path)
            except Exception as e:
                logger.warning(
                    f"Failed to get service file from cache for {srv_type}: {e}. "
                    f"Trying to clone repository..."
                )
    except ImportError as e:
        # GitPython not available - log warning but don't fail
        logger.warning(
            f"GitPython not available. Cannot auto-download service file for {srv_type}. "
            f"Install GitPython with 'pip install GitPython' to enable auto-download. "
            f"Error: {e}"
        )
    except Exception as e:
        # Log the error but don't fail - user can add message manually
        logger.warning(
            f"Failed to auto-download service file for {srv_type} from git repository: {e}. "
            f"You may need to add the service file manually."
        )

    return None

load_service_type(srv_type: str) -> bool

Load a service type (request and response) and their dependencies

Parameters:

Name Type Description Default
srv_type str

ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")

required

Returns:

Type Description
bool

True if loaded successfully, False otherwise

Source code in zenoh_ros2_sdk/message_registry.py
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
def load_service_type(self, srv_type: str) -> bool:
    """
    Load a service type (request and response) and their dependencies

    Args:
        srv_type: ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")

    Returns:
        True if loaded successfully, False otherwise
    """
    try:
        self._load_service_types(srv_type)
        return True
    except Exception as e:
        logger.warning(f"Failed to load service type {srv_type}: {e}", exc_info=True)
        return False

load_message_type(msg_type: str) -> bool

Load a message type and its dependencies

Parameters:

Name Type Description Default
msg_type str

ROS2 message type (e.g., "geometry_msgs/msg/Twist")

required

Returns:

Type Description
bool

True if loaded successfully, False otherwise

Source code in zenoh_ros2_sdk/message_registry.py
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
def load_message_type(self, msg_type: str) -> bool:
    """
    Load a message type and its dependencies

    Args:
        msg_type: ROS2 message type (e.g., "geometry_msgs/msg/Twist")

    Returns:
        True if loaded successfully, False otherwise
    """
    try:
        self._load_dependencies(msg_type)
        return True
    except Exception as e:
        logger.warning(f"Failed to load message type {msg_type}: {e}")
        return False

get_message_class(msg_type: str) -> Optional[Type[Any]]

Get a message class for a given type (loads if not already loaded)

Parameters:

Name Type Description Default
msg_type str

ROS2 message type

required

Returns:

Type Description
Optional[Type[Any]]

Optional[Type[Any]]: Message class or None if not found

Source code in zenoh_ros2_sdk/message_registry.py
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
def get_message_class(self, msg_type: str) -> Optional[Type[Any]]:
    """
    Get a message class for a given type (loads if not already loaded)

    Args:
        msg_type: ROS2 message type

    Returns:
        Optional[Type[Any]]: Message class or None if not found
    """
    if msg_type not in self._loaded_types:
        # Service request/response types cannot be loaded from a single .msg file path.
        # They must be loaded from the parent .srv file.
        is_service_req_resp = (
            "/srv/" in msg_type and (msg_type.endswith("_Request") or msg_type.endswith("_Response"))
        )
        if is_service_req_resp:
            # example_interfaces/srv/AddTwoInts_Request -> example_interfaces/srv/AddTwoInts
            if msg_type.endswith("_Request"):
                base_srv = msg_type[:-8]
            else:
                base_srv = msg_type[:-9]
            if not self.load_service_type(base_srv):
                return None
        else:
            if not self.load_message_type(msg_type):
                return None

    # Check if we have a mapping to the actual store key (for service types)
    actual_key = self.session._registered_types.get(msg_type)
    if actual_key and isinstance(actual_key, str):
        # actual_key is the store key (may be converted name)
        return self.session.store.types.get(actual_key)

    # Try direct lookup
    msg_class = self.session.store.types.get(msg_type)
    if msg_class is not None:
        return msg_class

    # Try with /msg/ inserted (for service types: srv/ -> srv/msg/)
    if '/srv/' in msg_type:
        converted_name = msg_type.replace('/srv/', '/srv/msg/')
        return self.session.store.types.get(converted_name)

    return None

is_loaded(msg_type: str) -> bool

Check if a message type is already loaded

Source code in zenoh_ros2_sdk/message_registry.py
433
434
435
def is_loaded(self, msg_type: str) -> bool:
    """Check if a message type is already loaded"""
    return msg_type in self._loaded_types

get_registry(messages_dir: Optional[str] = None) -> MessageRegistry

Get or create the global message registry

Source code in zenoh_ros2_sdk/message_registry.py
442
443
444
445
446
447
def get_registry(messages_dir: Optional[str] = None) -> MessageRegistry:
    """Get or create the global message registry"""
    global _registry
    if _registry is None:
        _registry = MessageRegistry(messages_dir)
    return _registry

load_message_type(msg_type: str, messages_dir: Optional[str] = None) -> bool

Convenience function to load a message type

Parameters:

Name Type Description Default
msg_type str

ROS2 message type (e.g., "geometry_msgs/msg/Twist")

required
messages_dir Optional[str]

Optional custom messages directory

None

Returns:

Type Description
bool

True if loaded successfully

Source code in zenoh_ros2_sdk/message_registry.py
450
451
452
453
454
455
456
457
458
459
460
461
462
def load_message_type(msg_type: str, messages_dir: Optional[str] = None) -> bool:
    """
    Convenience function to load a message type

    Args:
        msg_type: ROS2 message type (e.g., "geometry_msgs/msg/Twist")
        messages_dir: Optional custom messages directory

    Returns:
        True if loaded successfully
    """
    registry = get_registry(messages_dir)
    return registry.load_message_type(msg_type)

get_message_class(msg_type: str, messages_dir: Optional[str] = None) -> Optional[Type[Any]]

Convenience function to get a message class

Parameters:

Name Type Description Default
msg_type str

ROS2 message type

required
messages_dir Optional[str]

Optional custom messages directory

None

Returns:

Type Description
Optional[Type[Any]]

Optional[Type[Any]]: Message class or None

Source code in zenoh_ros2_sdk/message_registry.py
465
466
467
468
469
470
471
472
473
474
475
476
477
def get_message_class(msg_type: str, messages_dir: Optional[str] = None) -> Optional[Type[Any]]:
    """
    Convenience function to get a message class

    Args:
        msg_type: ROS2 message type
        messages_dir: Optional custom messages directory

    Returns:
        Optional[Type[Any]]: Message class or None
    """
    registry = get_registry(messages_dir)
    return registry.get_message_class(msg_type)

load_service_type(srv_type: str, messages_dir: Optional[str] = None) -> bool

Convenience function to load a service type

Parameters:

Name Type Description Default
srv_type str

ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")

required
messages_dir Optional[str]

Optional custom messages directory

None

Returns:

Type Description
bool

True if loaded successfully

Source code in zenoh_ros2_sdk/message_registry.py
480
481
482
483
484
485
486
487
488
489
490
491
492
def load_service_type(srv_type: str, messages_dir: Optional[str] = None) -> bool:
    """
    Convenience function to load a service type

    Args:
        srv_type: ROS2 service type (e.g., "example_interfaces/srv/AddTwoInts")
        messages_dir: Optional custom messages directory

    Returns:
        True if loaded successfully
    """
    registry = get_registry(messages_dir)
    return registry.load_service_type(srv_type)