Class McapWriter
Defined in File writer.hpp
Class Documentation
-
class McapWriter
Provides a write interface to an MCAP file.
Public Functions
-
~McapWriter()
-
Status open(std::string_view filename, const McapWriterOptions &options)
Open a new MCAP file for writing and write the header.
- Parameters:
filename – Filename of the MCAP file to write.
options – Options for MCAP writing.
profileis required.
- Returns:
A non-success status if the file could not be opened for writing.
-
void open(IWritable &writer, const McapWriterOptions &options)
Open a new MCAP file for writing and write the header.
- Parameters:
writer – An implementation of the IWritable interface. Output bytes will be written to this object.
options – Options for MCAP writing.
profileis required.
-
void open(std::ostream &stream, const McapWriterOptions &options)
Open a new MCAP file for writing and write the header.
- Parameters:
stream – Output stream to write to.
options – Options for MCAP writing.
profileis required.
-
void close()
Write the MCAP footer, flush pending writes to the output stream, and reset internal state.
-
void terminate()
Reset internal state without writing the MCAP footer or flushing pending writes. This should only be used in error cases as the output MCAP file will be truncated.
-
void addSchema(Schema &schema)
Add a new schema to the MCAP file and set
schema.idto a generated schema id. The schema id is used when adding channels to the file.- Parameters:
schema – Description of the schema to register. The
idfield is ignored and will be set to a generated schema id.
-
void addChannel(Channel &channel)
Add a new channel to the MCAP file and set
channel.idto a generated channel id. The channel id is used when adding messages to the file.- Parameters:
channel – Description of the channel to register. The
idvalue is ignored and will be set to a generated channel id.
-
Status write(const Message &message)
Write a message to the output stream.
- Parameters:
msg – Message to add.
- Returns:
A non-zero error code on failure.
-
Status write(Attachment &attachment)
Write an attachment to the output stream.
- Parameters:
attachment – Attachment to add. The
attachment.crcwill be calculated and set if configuration options allow CRC calculation.- Returns:
A non-zero error code on failure.
-
Status write(const Metadata &metadata)
Write a metadata record to the output stream.
- Parameters:
metadata – Named group of key/value string pairs to add.
- Returns:
A non-zero error code on failure.
-
const Statistics &statistics() const
Current MCAP file-level statistics. This is written as a Statistics record in the Summary section of the MCAP file.
-
IWritable *dataSink()
Returns a pointer to the IWritable data destination backing this writer. Will return nullptr if the writer is not open.
-
void closeLastChunk()
finishes the current chunk in progress and writes it to the file, if a chunk is in progress.
Public Static Functions
-
static uint64_t write(IWritable &output, const Attachment &attachment)
-
static uint64_t write(IWritable &output, const MessageIndex &index)
-
static uint64_t write(IWritable &output, const ChunkIndex &index)
-
static uint64_t write(IWritable &output, const AttachmentIndex &index)
-
static uint64_t write(IWritable &output, const MetadataIndex &index)
-
static uint64_t write(IWritable &output, const Statistics &stats)
-
static uint64_t write(IWritable &output, const SummaryOffset &summaryOffset)
-
static void write(IWritable &output, const KeyValueMap &map, uint32_t size = 0)
-
~McapWriter()