diff --git a/src/rosbags/convert/converter.py b/src/rosbags/convert/converter.py index 65c3a5f9..03af6168 100644 --- a/src/rosbags/convert/converter.py +++ b/src/rosbags/convert/converter.py @@ -106,13 +106,13 @@ def convert_1to2(src: Path, dst: Path) -> None: candidate = upgrade_connection(rconn) existing = next((x for x in writer.connections.values() if x == candidate), None) wconn = existing if existing else writer.add_connection(**asdict(candidate)) - connmap[rconn.cid] = wconn + connmap[rconn.id] = wconn typs.update(get_types_from_msg(rconn.msgdef, rconn.msgtype)) register_types(typs) for rconn, timestamp, data in reader.messages(): data = ros1_to_cdr(data, rconn.msgtype) - writer.write(connmap[rconn.cid], timestamp, data) + writer.write(connmap[rconn.id], timestamp, data) def convert_2to1(src: Path, dst: Path) -> None: diff --git a/src/rosbags/rosbag1/reader.py b/src/rosbags/rosbag1/reader.py index c7733c66..8798c529 100644 --- a/src/rosbags/rosbag1/reader.py +++ b/src/rosbags/rosbag1/reader.py @@ -53,7 +53,7 @@ class RecordType(IntEnum): class Connection(NamedTuple): """Connection information.""" - cid: int + id: int topic: str msgtype: str msgdef: str @@ -436,7 +436,7 @@ class Reader: count = reduce( lambda x, y: x + y, ( - y.connection_counts.get(x.cid, 0) + y.connection_counts.get(x.id, 0) for x in connections for y in self.chunk_infos ), @@ -607,7 +607,7 @@ class Reader: if not connections: connections = self.connections.values() - indexes = [self.indexes[x.cid] for x in connections] + indexes = [self.indexes[x.id] 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 2d5076ea..8063757f 100644 --- a/src/rosbags/rosbag1/writer.py +++ b/src/rosbags/rosbag1/writer.py @@ -261,7 +261,7 @@ class Writer: bio = self.chunks[-1].data self.write_connection(connection, bio) - self.connections[connection.cid] = connection + self.connections[connection.id] = connection return connection def write(self, connection: Connection, timestamp: int, data: bytes) -> None: @@ -283,7 +283,7 @@ class Writer: raise WriterError(f'There is no connection {connection!r}.') from None chunk = self.chunks[-1] - chunk.connections[connection.cid].append((timestamp, chunk.data.tell())) + chunk.connections[connection.id].append((timestamp, chunk.data.tell())) if timestamp < chunk.start: chunk.start = timestamp @@ -292,7 +292,7 @@ class Writer: chunk.end = timestamp header = Header() - header.set_uint32('conn', connection.cid) + header.set_uint32('conn', connection.id) header.set_time('time', timestamp) header.write(chunk.data, RecordType.MSGDATA) @@ -305,7 +305,7 @@ class Writer: def write_connection(connection: Connection, bio: BinaryIO) -> None: """Write connection record.""" header = Header() - header.set_uint32('conn', connection.cid) + header.set_uint32('conn', connection.id) header.set_string('topic', connection.topic) header.write(bio, RecordType.CONNECTION) diff --git a/tests/test_writer1.py b/tests/test_writer1.py index 28ba6cee..dd188525 100644 --- a/tests/test_writer1.py +++ b/tests/test_writer1.py @@ -49,7 +49,7 @@ def test_add_connection(tmp_path: Path) -> None: with Writer(path) as writer: res = writer.add_connection('/foo', 'test_msgs/msg/Test', 'MESSAGE_DEFINITION', 'HASH') - assert res.cid == 0 + assert res.id == 0 data = path.read_bytes() assert data.count(b'MESSAGE_DEFINITION') == 2 assert data.count(b'HASH') == 2 @@ -57,7 +57,7 @@ def test_add_connection(tmp_path: Path) -> None: with Writer(path) as writer: res = writer.add_connection('/foo', 'std_msgs/msg/Int8') - assert res.cid == 0 + assert res.id == 0 data = path.read_bytes() assert data.count(b'int8 data') == 2 assert data.count(b'27ffa0c9c4b8fb8492252bcad9e5c57b') == 2 @@ -85,7 +85,7 @@ def test_add_connection(tmp_path: Path) -> None: 'HASH', latching=1, ) - assert (res1.cid, res2.cid, res3.cid) == (0, 1, 2) + assert (res1.id, res2.id, res3.id) == (0, 1, 2) def test_write_errors(tmp_path: Path) -> None: