From 885900df398eb8d24a3432003aab8f545e5d4a9f Mon Sep 17 00:00:00 2001 From: Marko Durkovic Date: Mon, 13 Sep 2021 10:49:57 +0200 Subject: [PATCH] Make reader1 API match reader2 --- src/rosbags/rosbag1/reader.py | 15 +++++++++------ src/rosbags/rosbag1/writer.py | 2 +- tests/test_reader1.py | 3 ++- 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/rosbags/rosbag1/reader.py b/src/rosbags/rosbag1/reader.py index 47223d07..31e3e4a0 100644 --- a/src/rosbags/rosbag1/reader.py +++ b/src/rosbags/rosbag1/reader.py @@ -55,8 +55,8 @@ class Connection(NamedTuple): cid: int topic: str msgtype: str - md5sum: str msgdef: str + md5sum: str callerid: Optional[str] latching: Optional[int] indexes: list @@ -487,8 +487,8 @@ class Reader: conn, topic, normalize_msgtype(typ), - md5sum, msgdef, + md5sum, callerid, latching, [], @@ -573,15 +573,15 @@ class Reader: def messages( self, - topics: Optional[Iterable[str]] = None, + connections: Iterable[Connection] = (), start: Optional[int] = None, stop: Optional[int] = None, ) -> Generator[tuple[Connection, int, bytes], None, None]: """Read messages from bag. Args: - topics: Iterable with topic names to filter for. An empty iterable - yields all messages. + connections: Iterable with connections to filter for. An empty + iterable disables filtering on connections. start: Yield only messages at or after this timestamp (ns). stop: Yield only messages before this timestamp (ns). @@ -595,7 +595,10 @@ class Reader: if not self.bio: raise ReaderError('Rosbag is not open.') - indexes = [x.indexes for x in self.connections.values() if not topics or x.topic in topics] + if not connections: + connections = self.connections.values() + + indexes = [x.indexes for x in connections] for entry in heapq.merge(*indexes): if start and entry.time < start: continue diff --git a/src/rosbags/rosbag1/writer.py b/src/rosbags/rosbag1/writer.py index 650d3c52..51a5e6bd 100644 --- a/src/rosbags/rosbag1/writer.py +++ b/src/rosbags/rosbag1/writer.py @@ -245,8 +245,8 @@ class Writer: # pylint: disable=too-many-instance-attributes len(self.connections), topic, denormalize_msgtype(msgtype), - md5sum, msgdef, + md5sum, callerid, latching, [], diff --git a/tests/test_reader1.py b/tests/test_reader1.py index f0a08124..5acbcf5b 100644 --- a/tests/test_reader1.py +++ b/tests/test_reader1.py @@ -254,7 +254,8 @@ def test_reader(tmp_path): # pylint: disable=too-many-statements assert msgs[0][2] == b'MSGCONTENT5' assert msgs[1][2] == b'MSGCONTENT10' - msgs = list(reader.messages(['/topic0'])) + connections = [x for x in reader.connections.values() if x.topic == '/topic0'] + msgs = list(reader.messages(connections)) assert len(msgs) == 1 assert msgs[0][2] == b'MSGCONTENT10'