From ff24d7e424c6324e5406160e6d2ded690de424b5 Mon Sep 17 00:00:00 2001 From: Marko Durkovic Date: Wed, 27 Jul 2022 16:03:22 +0200 Subject: [PATCH] Move metadata to dedicated module --- src/rosbags/rosbag2/metadata.py | 59 +++++++++++++++++++++++++++++++++ src/rosbags/rosbag2/reader.py | 48 ++------------------------- src/rosbags/rosbag2/writer.py | 2 +- 3 files changed, 62 insertions(+), 47 deletions(-) create mode 100644 src/rosbags/rosbag2/metadata.py diff --git a/src/rosbags/rosbag2/metadata.py b/src/rosbags/rosbag2/metadata.py new file mode 100644 index 00000000..004bb436 --- /dev/null +++ b/src/rosbags/rosbag2/metadata.py @@ -0,0 +1,59 @@ +# Copyright 2020-2022 Ternaris. +# SPDX-License-Identifier: Apache-2.0 +"""Rosbag2 metadata.""" + +from __future__ import annotations + +from typing import TypedDict + + +class StartingTime(TypedDict): + """Bag starting time.""" + + nanoseconds_since_epoch: int + + +class Duration(TypedDict): + """Bag starting time.""" + + nanoseconds: int + + +class TopicMetadata(TypedDict): + """Topic metadata.""" + + name: str + type: str + serialization_format: str + offered_qos_profiles: str + + +class TopicWithMessageCount(TypedDict): + """Topic with message count.""" + + 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.""" + + version: int + storage_identifier: str + relative_file_paths: list[str] + starting_time: StartingTime + duration: Duration + message_count: int + compression_format: str + compression_mode: str + topics_with_message_count: list[TopicWithMessageCount] + files: list[FileInformation] diff --git a/src/rosbags/rosbag2/reader.py b/src/rosbags/rosbag2/reader.py index a830724a..e69360c1 100644 --- a/src/rosbags/rosbag2/reader.py +++ b/src/rosbags/rosbag2/reader.py @@ -18,53 +18,9 @@ from rosbags.interfaces import Connection, ConnectionExtRosbag2, TopicInfo if TYPE_CHECKING: from types import TracebackType - from typing import Any, Generator, Iterable, Literal, Optional, Type, TypedDict, Union + from typing import Any, Generator, Iterable, Literal, Optional, Type, Union - class StartingTime(TypedDict): - """Bag starting time.""" - - nanoseconds_since_epoch: int - - class Duration(TypedDict): - """Bag starting time.""" - - nanoseconds: int - - class TopicMetadata(TypedDict): - """Topic metadata.""" - - name: str - type: str - serialization_format: str - offered_qos_profiles: str - - class TopicWithMessageCount(TypedDict): - """Topic with message count.""" - - 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.""" - - version: int - storage_identifier: str - relative_file_paths: list[str] - starting_time: StartingTime - duration: Duration - message_count: int - compression_format: str - compression_mode: str - topics_with_message_count: list[TopicWithMessageCount] - files: list[FileInformation] + from .metadata import FileInformation, Metadata class ReaderError(Exception): diff --git a/src/rosbags/rosbag2/writer.py b/src/rosbags/rosbag2/writer.py index 6454562b..79b6286e 100644 --- a/src/rosbags/rosbag2/writer.py +++ b/src/rosbags/rosbag2/writer.py @@ -18,7 +18,7 @@ if TYPE_CHECKING: from types import TracebackType from typing import Any, Literal, Optional, Type, Union - from .reader import Metadata + from .metadata import Metadata class WriterError(Exception):