Add support for rosbag2 version 5 metadata

This commit is contained in:
Marko Durkovic 2022-04-21 15:58:09 +02:00
parent 34ffe96692
commit d196e8b74e
2 changed files with 27 additions and 2 deletions

View File

@ -44,6 +44,14 @@ if TYPE_CHECKING:
message_count: int
topic_metadata: TopicMetadata
class FileInformation(TypedDict):
"""Per file metadata."""
path: str
starting_time: StartingTime
duration: Duration
message_count: int
class Metadata(TypedDict):
"""Rosbag2 metadata file."""
@ -56,6 +64,7 @@ if TYPE_CHECKING:
compression_format: str
compression_mode: str
topics_with_message_count: list[TopicWithMessageCount]
files: list[FileInformation]
class ReaderError(Exception):
@ -99,6 +108,8 @@ class Reader:
- Version 2: Changed field sizes in C++ implementation.
- Version 3: Added compression.
- Version 4: Added QoS metadata to topics, changed relative file paths
- Version 5: Added per file metadata
"""
def __init__(self, path: Union[Path, str]):
@ -125,7 +136,7 @@ class Reader:
try:
self.metadata: Metadata = dct['rosbag2_bagfile_information']
if (ver := self.metadata['version']) > 4:
if (ver := self.metadata['version']) > 5:
raise ReaderError(f'Rosbag2 version {ver} not supported; please report issue.')
if storageid := self.metadata['storage_identifier'] != 'sqlite3':
raise ReaderError(
@ -160,6 +171,8 @@ class Reader:
if self.compression_mode and (cfmt := self.compression_format) != 'zstd':
raise ReaderError(f'Compression format {cfmt!r} is not supported.')
self.files: list[FileInformation] = self.metadata.get('files', [])[:]
except KeyError as exc:
raise ReaderError(f'A metadata key is missing {exc!r}.') from None

View File

@ -233,7 +233,7 @@ class Writer: # pylint: disable=too-many-instance-attributes
metadata: dict[str, Metadata] = {
'rosbag2_bagfile_information': {
'version': 4,
'version': 5,
'storage_identifier': 'sqlite3',
'relative_file_paths': [self.dbpath.name],
'duration': {
@ -256,6 +256,18 @@ class Writer: # pylint: disable=too-many-instance-attributes
],
'compression_format': self.compression_format,
'compression_mode': self.compression_mode,
'files': [
{
'path': self.dbpath.name,
'starting_time': {
'nanoseconds_since_epoch': start,
},
'duration': {
'nanoseconds': duration,
},
'message_count': count,
},
],
},
}
with self.metapath.open('w') as metafile: