pjmsg_mcap_wrapper
|
Provides a read interface to an MCAP file.
Definition at line 275 of file reader.hpp.
#include <reader.hpp>
Public Member Functions | |
~McapReader () | |
Status | open (IReadable &reader) |
Opens an MCAP file for reading from an already constructed IReadable implementation. | |
Status | open (std::string_view filename) |
Opens an MCAP file for reading from a given filename. | |
Status | open (std::ifstream &stream) |
Opens an MCAP file for reading from a std::ifstream input file stream. | |
void | close () |
Closes the MCAP file, clearing any internal data structures and state and dropping the data source reference. | |
Status | readSummary (ReadSummaryMethod method, const ProblemCallback &onProblem=[](const Status &) {}) |
Read and parse the Summary section at the end of the MCAP file, if available. This will populate internal indexes to allow for efficient summarization and random access. This method will automatically be called upon requesting summary data or first seek if Summary section parsing is allowed by the configuration options. | |
LinearMessageView | readMessages (Timestamp startTime=0, Timestamp endTime=MaxTime) |
Returns an iterable view with begin() and end() methods for iterating Messages in the MCAP file. If a non-zero startTime is provided, this will first parse the Summary section (by calling readSummary() ) if allowed by the configuration options and it has not been parsed yet. | |
LinearMessageView | readMessages (const ProblemCallback &onProblem, Timestamp startTime=0, Timestamp endTime=MaxTime) |
Returns an iterable view with begin() and end() methods for iterating Messages in the MCAP file. If a non-zero startTime is provided, this will first parse the Summary section (by calling readSummary() ) if allowed by the configuration options and it has not been parsed yet. | |
LinearMessageView | readMessages (const ProblemCallback &onProblem, const ReadMessageOptions &options) |
Returns an iterable view with begin() and end() methods for iterating Messages in the MCAP file. Uses the options from options to select the messages that are yielded. | |
std::pair< ByteOffset, ByteOffset > | byteRange (Timestamp startTime, Timestamp endTime=MaxTime) const |
Returns starting and ending byte offsets that must be read to iterate all messages in the given time range. If readSummary() has been successfully called and the recording contains Chunk records, this range will be narrowed to Chunk records that contain messages in the given time range. Otherwise, this range will be the entire Data section if the Data End record has been found or the entire file otherwise. | |
IReadable * | dataSource () |
Returns a pointer to the IReadable data source backing this reader. Will return nullptr if the reader is not open. | |
const std::optional< Header > & | header () const |
Returns the parsed Header record, if it has been encountered. | |
const std::optional< Footer > & | footer () const |
Returns the parsed Footer record, if it has been encountered. | |
const std::optional< Statistics > & | statistics () const |
Returns the parsed Statistics record, if it has been encountered. | |
const std::unordered_map< ChannelId, ChannelPtr > | channels () const |
Returns all of the parsed Channel records. Call readSummary() first to fully populate this data structure. | |
const std::unordered_map< SchemaId, SchemaPtr > | schemas () const |
Returns all of the parsed Schema records. Call readSummary() first to fully populate this data structure. | |
ChannelPtr | channel (ChannelId channelId) const |
Look up a Channel record by channel ID. If the Channel has not been encountered yet or does not exist in the file, this will return nullptr. | |
SchemaPtr | schema (SchemaId schemaId) const |
Look up a Schema record by schema ID. If the Schema has not been encountered yet or does not exist in the file, this will return nullptr. | |
const std::vector< ChunkIndex > & | chunkIndexes () const |
Returns all of the parsed ChunkIndex records. Call readSummary() first to fully populate this data structure. | |
const std::multimap< std::string, MetadataIndex > & | metadataIndexes () const |
Returns all of the parsed MetadataIndex records. Call readSummary() first to fully populate this data structure. The multimap's keys are the name field from each indexed Metadata. | |
const std::multimap< std::string, AttachmentIndex > & | attachmentIndexes () const |
Returns all of the parsed AttachmentIndex records. Call readSummary() first to fully populate this data structure. The multimap's keys are the name field from each indexed Attachment. | |
Static Public Member Functions | |
static Status | ReadRecord (IReadable &reader, uint64_t offset, Record *record) |
static Status | ReadFooter (IReadable &reader, uint64_t offset, Footer *footer) |
static Status | ParseHeader (const Record &record, Header *header) |
static Status | ParseFooter (const Record &record, Footer *footer) |
static Status | ParseSchema (const Record &record, Schema *schema) |
static Status | ParseChannel (const Record &record, Channel *channel) |
static Status | ParseMessage (const Record &record, Message *message) |
static Status | ParseChunk (const Record &record, Chunk *chunk) |
static Status | ParseMessageIndex (const Record &record, MessageIndex *messageIndex) |
static Status | ParseChunkIndex (const Record &record, ChunkIndex *chunkIndex) |
static Status | ParseAttachment (const Record &record, Attachment *attachment) |
static Status | ParseAttachmentIndex (const Record &record, AttachmentIndex *attachmentIndex) |
static Status | ParseStatistics (const Record &record, Statistics *statistics) |
static Status | ParseMetadata (const Record &record, Metadata *metadata) |
static Status | ParseMetadataIndex (const Record &record, MetadataIndex *metadataIndex) |
static Status | ParseSummaryOffset (const Record &record, SummaryOffset *summaryOffset) |
static Status | ParseDataEnd (const Record &record, DataEnd *dataEnd) |
static std::optional< Compression > | ParseCompression (const std::string_view compression) |
Converts a compression string ("", "zstd", "lz4") to the Compression enum. | |
Private Types | |
using | ChunkInterval = internal::Interval< ByteOffset, ChunkIndex > |
Private Member Functions | |
void | reset_ () |
Status | readSummarySection_ (IReadable &reader) |
Status | readSummaryFromScan_ (IReadable &reader) |
Private Attributes | |
friend | LinearMessageView |
IReadable * | input_ = nullptr |
std::FILE * | file_ = nullptr |
std::unique_ptr< FileReader > | fileInput_ |
std::unique_ptr< FileStreamReader > | fileStreamInput_ |
std::optional< Header > | header_ |
std::optional< Footer > | footer_ |
std::optional< Statistics > | statistics_ |
std::vector< ChunkIndex > | chunkIndexes_ |
internal::IntervalTree< ByteOffset, ChunkIndex > | chunkRanges_ |
std::multimap< std::string, AttachmentIndex > | attachmentIndexes_ |
std::multimap< std::string, MetadataIndex > | metadataIndexes_ |
std::unordered_map< SchemaId, SchemaPtr > | schemas_ |
std::unordered_map< ChannelId, ChannelPtr > | channels_ |
ByteOffset | dataStart_ = 0 |
ByteOffset | dataEnd_ = EndOffset |
bool | parsedSummary_ = false |
|
private |
Definition at line 478 of file reader.hpp.
mcap::McapReader::~McapReader | ( | ) |
Definition at line 269 of file reader.inl.
const std::multimap< std::string, AttachmentIndex > & mcap::McapReader::attachmentIndexes | ( | ) | const |
Returns all of the parsed AttachmentIndex records. Call readSummary()
first to fully populate this data structure. The multimap's keys are the name
field from each indexed Attachment.
Definition at line 650 of file reader.inl.
std::pair< ByteOffset, ByteOffset > mcap::McapReader::byteRange | ( | Timestamp | startTime, |
Timestamp | endTime = MaxTime |
||
) | const |
Returns starting and ending byte offsets that must be read to iterate all messages in the given time range. If readSummary()
has been successfully called and the recording contains Chunk records, this range will be narrowed to Chunk records that contain messages in the given time range. Otherwise, this range will be the entire Data section if the Data End record has been found or the entire file otherwise.
This method is automatically used by readMessages()
, and only needs to be called directly if the caller is manually constructing an iterator.
startTime | Start time in nanoseconds. |
endTime | Optional end time in nanoseconds. |
Definition at line 587 of file reader.inl.
ChannelPtr mcap::McapReader::channel | ( | ChannelId | channelId | ) | const |
const std::unordered_map< ChannelId, ChannelPtr > mcap::McapReader::channels | ( | ) | const |
Returns all of the parsed Channel records. Call readSummary()
first to fully populate this data structure.
Definition at line 624 of file reader.inl.
const std::vector< ChunkIndex > & mcap::McapReader::chunkIndexes | ( | ) | const |
Returns all of the parsed ChunkIndex records. Call readSummary()
first to fully populate this data structure.
Definition at line 642 of file reader.inl.
void mcap::McapReader::close | ( | ) |
Closes the MCAP file, clearing any internal data structures and state and dropping the data source reference.
Definition at line 345 of file reader.inl.
IReadable * mcap::McapReader::dataSource | ( | ) |
Returns a pointer to the IReadable data source backing this reader. Will return nullptr if the reader is not open.
Definition at line 608 of file reader.inl.
const std::optional< Footer > & mcap::McapReader::footer | ( | ) | const |
Returns the parsed Footer record, if it has been encountered.
Definition at line 616 of file reader.inl.
const std::optional< Header > & mcap::McapReader::header | ( | ) | const |
Returns the parsed Header record, if it has been encountered.
Definition at line 612 of file reader.inl.
const std::multimap< std::string, MetadataIndex > & mcap::McapReader::metadataIndexes | ( | ) | const |
Returns all of the parsed MetadataIndex records. Call readSummary()
first to fully populate this data structure. The multimap's keys are the name
field from each indexed Metadata.
Definition at line 646 of file reader.inl.
Opens an MCAP file for reading from an already constructed IReadable implementation.
reader | An implementation of the IReader interface that provides raw MCAP data. |
open()
is called and a success response is returned. Definition at line 273 of file reader.inl.
Status mcap::McapReader::open | ( | std::ifstream & | stream | ) |
Opens an MCAP file for reading from a std::ifstream input file stream.
stream | Input file stream to read MCAP data from. |
open()
is called and a success response is returned. Definition at line 340 of file reader.inl.
Status mcap::McapReader::open | ( | std::string_view | filename | ) |
Opens an MCAP file for reading from a given filename.
filename | Filename to open. |
open()
is called and a success response is returned. Definition at line 325 of file reader.inl.
|
static |
Definition at line 993 of file reader.inl.
|
static |
Definition at line 1060 of file reader.inl.
Definition at line 806 of file reader.inl.
Definition at line 864 of file reader.inl.
|
static |
Definition at line 931 of file reader.inl.
|
static |
Converts a compression string ("", "zstd", "lz4") to the Compression enum.
Definition at line 1207 of file reader.inl.
Definition at line 1194 of file reader.inl.
Definition at line 752 of file reader.inl.
Definition at line 729 of file reader.inl.
Definition at line 846 of file reader.inl.
|
static |
Definition at line 904 of file reader.inl.
Definition at line 1132 of file reader.inl.
|
static |
Definition at line 1157 of file reader.inl.
Definition at line 768 of file reader.inl.
|
static |
Definition at line 1094 of file reader.inl.
|
static |
Definition at line 1178 of file reader.inl.
Definition at line 694 of file reader.inl.
LinearMessageView mcap::McapReader::readMessages | ( | const ProblemCallback & | onProblem, |
const ReadMessageOptions & | options | ||
) |
Returns an iterable view with begin()
and end()
methods for iterating Messages in the MCAP file. Uses the options from options
to select the messages that are yielded.
Definition at line 575 of file reader.inl.
LinearMessageView mcap::McapReader::readMessages | ( | const ProblemCallback & | onProblem, |
Timestamp | startTime = 0 , |
||
Timestamp | endTime = MaxTime |
||
) |
Returns an iterable view with begin()
and end()
methods for iterating Messages in the MCAP file. If a non-zero startTime
is provided, this will first parse the Summary section (by calling readSummary()
) if allowed by the configuration options and it has not been parsed yet.
onProblem | A callback that will be called when a parsing error occurs. Problems can either be recoverable, indicating some data could not be read, or non-recoverable, stopping the iteration. |
startTime | Optional start time in nanoseconds. Messages before this time will not be returned. |
endTime | Optional end time in nanoseconds. Messages equal to or after this time will not be returned. |
Definition at line 567 of file reader.inl.
LinearMessageView mcap::McapReader::readMessages | ( | Timestamp | startTime = 0 , |
Timestamp | endTime = MaxTime |
||
) |
Returns an iterable view with begin()
and end()
methods for iterating Messages in the MCAP file. If a non-zero startTime
is provided, this will first parse the Summary section (by calling readSummary()
) if allowed by the configuration options and it has not been parsed yet.
startTime | Optional start time in nanoseconds. Messages before this time will not be returned. |
endTime | Optional end time in nanoseconds. Messages equal to or after this time will not be returned. |
Definition at line 562 of file reader.inl.
Definition at line 654 of file reader.inl.
Status mcap::McapReader::readSummary | ( | ReadSummaryMethod | method, |
const ProblemCallback & | onProblem = [](const Status&) {} |
||
) |
Read and parse the Summary section at the end of the MCAP file, if available. This will populate internal indexes to allow for efficient summarization and random access. This method will automatically be called upon requesting summary data or first seek if Summary section parsing is allowed by the configuration options.
Definition at line 369 of file reader.inl.
Definition at line 487 of file reader.inl.
Definition at line 413 of file reader.inl.
|
private |
Definition at line 356 of file reader.inl.
const std::unordered_map< SchemaId, SchemaPtr > mcap::McapReader::schemas | ( | ) | const |
Returns all of the parsed Schema records. Call readSummary()
first to fully populate this data structure.
Definition at line 628 of file reader.inl.
const std::optional< Statistics > & mcap::McapReader::statistics | ( | ) | const |
Returns the parsed Statistics record, if it has been encountered.
Definition at line 620 of file reader.inl.
|
private |
Definition at line 490 of file reader.hpp.
|
private |
Definition at line 493 of file reader.hpp.
|
private |
Definition at line 488 of file reader.hpp.
|
private |
Definition at line 489 of file reader.hpp.
|
private |
Definition at line 495 of file reader.hpp.
|
private |
Definition at line 494 of file reader.hpp.
|
private |
Definition at line 482 of file reader.hpp.
|
private |
Definition at line 483 of file reader.hpp.
|
private |
Definition at line 484 of file reader.hpp.
|
private |
Definition at line 486 of file reader.hpp.
|
private |
Definition at line 485 of file reader.hpp.
|
private |
Definition at line 481 of file reader.hpp.
|
private |
Definition at line 479 of file reader.hpp.
|
private |
Definition at line 491 of file reader.hpp.
|
private |
Definition at line 496 of file reader.hpp.
|
private |
Definition at line 492 of file reader.hpp.
|
private |
Definition at line 487 of file reader.hpp.