Move metadata to dedicated module

This commit is contained in:
Marko Durkovic 2022-07-27 16:03:22 +02:00
parent b9fd0b014b
commit ff24d7e424
3 changed files with 62 additions and 47 deletions

View File

@ -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]

View File

@ -18,53 +18,9 @@ from rosbags.interfaces import Connection, ConnectionExtRosbag2, TopicInfo
if TYPE_CHECKING: if TYPE_CHECKING:
from types import TracebackType 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): from .metadata import FileInformation, Metadata
"""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]
class ReaderError(Exception): class ReaderError(Exception):

View File

@ -18,7 +18,7 @@ if TYPE_CHECKING:
from types import TracebackType from types import TracebackType
from typing import Any, Literal, Optional, Type, Union from typing import Any, Literal, Optional, Type, Union
from .reader import Metadata from .metadata import Metadata
class WriterError(Exception): class WriterError(Exception):