Rename rosbag1 connection cid to id
This commit is contained in:
parent
42243eac2d
commit
dee7e9c2fc
@ -106,13 +106,13 @@ def convert_1to2(src: Path, dst: Path) -> None:
|
|||||||
candidate = upgrade_connection(rconn)
|
candidate = upgrade_connection(rconn)
|
||||||
existing = next((x for x in writer.connections.values() if x == candidate), None)
|
existing = next((x for x in writer.connections.values() if x == candidate), None)
|
||||||
wconn = existing if existing else writer.add_connection(**asdict(candidate))
|
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))
|
typs.update(get_types_from_msg(rconn.msgdef, rconn.msgtype))
|
||||||
register_types(typs)
|
register_types(typs)
|
||||||
|
|
||||||
for rconn, timestamp, data in reader.messages():
|
for rconn, timestamp, data in reader.messages():
|
||||||
data = ros1_to_cdr(data, rconn.msgtype)
|
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:
|
def convert_2to1(src: Path, dst: Path) -> None:
|
||||||
|
|||||||
@ -53,7 +53,7 @@ class RecordType(IntEnum):
|
|||||||
class Connection(NamedTuple):
|
class Connection(NamedTuple):
|
||||||
"""Connection information."""
|
"""Connection information."""
|
||||||
|
|
||||||
cid: int
|
id: int
|
||||||
topic: str
|
topic: str
|
||||||
msgtype: str
|
msgtype: str
|
||||||
msgdef: str
|
msgdef: str
|
||||||
@ -436,7 +436,7 @@ class Reader:
|
|||||||
count = reduce(
|
count = reduce(
|
||||||
lambda x, y: x + y,
|
lambda x, y: x + y,
|
||||||
(
|
(
|
||||||
y.connection_counts.get(x.cid, 0)
|
y.connection_counts.get(x.id, 0)
|
||||||
for x in connections
|
for x in connections
|
||||||
for y in self.chunk_infos
|
for y in self.chunk_infos
|
||||||
),
|
),
|
||||||
@ -607,7 +607,7 @@ class Reader:
|
|||||||
if not connections:
|
if not connections:
|
||||||
connections = self.connections.values()
|
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):
|
for entry in heapq.merge(*indexes):
|
||||||
if start and entry.time < start:
|
if start and entry.time < start:
|
||||||
continue
|
continue
|
||||||
|
|||||||
@ -261,7 +261,7 @@ class Writer:
|
|||||||
bio = self.chunks[-1].data
|
bio = self.chunks[-1].data
|
||||||
self.write_connection(connection, bio)
|
self.write_connection(connection, bio)
|
||||||
|
|
||||||
self.connections[connection.cid] = connection
|
self.connections[connection.id] = connection
|
||||||
return connection
|
return connection
|
||||||
|
|
||||||
def write(self, connection: Connection, timestamp: int, data: bytes) -> None:
|
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
|
raise WriterError(f'There is no connection {connection!r}.') from None
|
||||||
|
|
||||||
chunk = self.chunks[-1]
|
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:
|
if timestamp < chunk.start:
|
||||||
chunk.start = timestamp
|
chunk.start = timestamp
|
||||||
@ -292,7 +292,7 @@ class Writer:
|
|||||||
chunk.end = timestamp
|
chunk.end = timestamp
|
||||||
|
|
||||||
header = Header()
|
header = Header()
|
||||||
header.set_uint32('conn', connection.cid)
|
header.set_uint32('conn', connection.id)
|
||||||
header.set_time('time', timestamp)
|
header.set_time('time', timestamp)
|
||||||
|
|
||||||
header.write(chunk.data, RecordType.MSGDATA)
|
header.write(chunk.data, RecordType.MSGDATA)
|
||||||
@ -305,7 +305,7 @@ class Writer:
|
|||||||
def write_connection(connection: Connection, bio: BinaryIO) -> None:
|
def write_connection(connection: Connection, bio: BinaryIO) -> None:
|
||||||
"""Write connection record."""
|
"""Write connection record."""
|
||||||
header = Header()
|
header = Header()
|
||||||
header.set_uint32('conn', connection.cid)
|
header.set_uint32('conn', connection.id)
|
||||||
header.set_string('topic', connection.topic)
|
header.set_string('topic', connection.topic)
|
||||||
header.write(bio, RecordType.CONNECTION)
|
header.write(bio, RecordType.CONNECTION)
|
||||||
|
|
||||||
|
|||||||
@ -49,7 +49,7 @@ def test_add_connection(tmp_path: Path) -> None:
|
|||||||
|
|
||||||
with Writer(path) as writer:
|
with Writer(path) as writer:
|
||||||
res = writer.add_connection('/foo', 'test_msgs/msg/Test', 'MESSAGE_DEFINITION', 'HASH')
|
res = writer.add_connection('/foo', 'test_msgs/msg/Test', 'MESSAGE_DEFINITION', 'HASH')
|
||||||
assert res.cid == 0
|
assert res.id == 0
|
||||||
data = path.read_bytes()
|
data = path.read_bytes()
|
||||||
assert data.count(b'MESSAGE_DEFINITION') == 2
|
assert data.count(b'MESSAGE_DEFINITION') == 2
|
||||||
assert data.count(b'HASH') == 2
|
assert data.count(b'HASH') == 2
|
||||||
@ -57,7 +57,7 @@ def test_add_connection(tmp_path: Path) -> None:
|
|||||||
|
|
||||||
with Writer(path) as writer:
|
with Writer(path) as writer:
|
||||||
res = writer.add_connection('/foo', 'std_msgs/msg/Int8')
|
res = writer.add_connection('/foo', 'std_msgs/msg/Int8')
|
||||||
assert res.cid == 0
|
assert res.id == 0
|
||||||
data = path.read_bytes()
|
data = path.read_bytes()
|
||||||
assert data.count(b'int8 data') == 2
|
assert data.count(b'int8 data') == 2
|
||||||
assert data.count(b'27ffa0c9c4b8fb8492252bcad9e5c57b') == 2
|
assert data.count(b'27ffa0c9c4b8fb8492252bcad9e5c57b') == 2
|
||||||
@ -85,7 +85,7 @@ def test_add_connection(tmp_path: Path) -> None:
|
|||||||
'HASH',
|
'HASH',
|
||||||
latching=1,
|
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:
|
def test_write_errors(tmp_path: Path) -> None:
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user