rosros 0.2.5
Simple unified interface to ROS1 / ROS2 Python API
Loading...
Searching...
No Matches
msg.py
Go to the documentation of this file.
1"""
2Stand-ins for `rospy.msg` in ROS2.
3
4------------------------------------------------------------------------------
5This file is part of rosros - simple unified interface to ROS1 / ROS2.
6Released under the BSD License.
7
8@author Erki Suurjaak
9@created 30.05.2022
10@modified 23.10.2022
11------------------------------------------------------------------------------
12"""
13## @namespace rosros.rospify.msg
14import std_msgs.msg
15
16from . import exceptions
17from . topics import Message
18
19
20Header = std_msgs.msg.Header
21
22
23class AnyMsg(Message):
24 """
25 Stand-in for `rospy.AnyMsg`.
26
27 Message class to use for subscribing to any topic regardless of type.
28 Incoming messages are not deserialized. Instead, the raw serialized data
29 can be accessed via the buff property.
30
31 Caveat in ROS2: subscription will be made with the first available published type
32 on this topic, creation will fail if no publisher is available. Will not provide
33 messages of different types.
34 """
35 _md5sum = "*"
36 _type = "*"
37 _has_header = False
38 _full_text = ""
39 __slots__ = ["_buff"]
40
41 def __init__(self, *args):
42 """
43 Constructor. Does not accept any arguments.
44 """
45 if len(args) != 0:
46 raise exceptions.ROSException("AnyMsg does not accept arguments")
47 self._buff = None
48
49 def serialize(self, buff):
50 """AnyMsg provides an implementation so that a node can forward messages w/o (de)serialization."""
51 if self._buff is None:
52 raise exceptions.ROSException("AnyMsg is not initialized")
53 buff.write(self._buff)
54
55 def deserialize(self, str):
56 """Copies raw buffer into self._buff, returns self."""
57 self._buff = str
58 return self
60 @classmethod
61 def __subclasshook__(cls, C):
62 """Returns true if C is AnyMsg or descendant, else `NotImplemented`."""
63 if getattr(C, "_type", None) == cls._type: return True
64 return NotImplemented
65
66
67__all__ = [
68 "AnyMsg", "Header"
69]
Base exception class for ROS clients.
Definition exceptions.py:54
__init__(self, *args)
Constructor.
Definition msg.py:56
serialize(self, buff)
AnyMsg provides an implementation so that a node can forward messages w/o (de)serialization.
Definition msg.py:61
deserialize(self, str)
Copies raw buffer into self._buff, returns self.
Definition msg.py:67
__subclasshook__(cls, C)
Returns true if C is AnyMsg or descendant, else `NotImplemented`.
Definition msg.py:73