Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
mcap::McapWriter Class Referencefinal

Provides a write interface to an MCAP file. More...

#include <writer.hpp>

Public Member Functions

void addChannel (Channel &channel)
 Add a new channel to the MCAP file and set channel.id to a generated channel id. The channel id is used when adding messages to the file. More...
 
void addSchema (Schema &schema)
 Add a new schema to the MCAP file and set schema.id to a generated schema id. The schema id is used when adding channels to the file. More...
 
void close ()
 Write the MCAP footer, flush pending writes to the output stream, and reset internal state. More...
 
void closeLastChunk ()
 finishes the current chunk in progress and writes it to the file, if a chunk is in progress. More...
 
IWritabledataSink ()
 Returns a pointer to the IWritable data destination backing this writer. Will return nullptr if the writer is not open. More...
 
void open (IWritable &writer, const McapWriterOptions &options)
 Open a new MCAP file for writing and write the header. More...
 
void open (std::ostream &stream, const McapWriterOptions &options)
 Open a new MCAP file for writing and write the header. More...
 
Status open (std::string_view filename, const McapWriterOptions &options)
 Open a new MCAP file for writing and write the header. More...
 
const Statisticsstatistics () const
 Current MCAP file-level statistics. This is written as a Statistics record in the Summary section of the MCAP file. More...
 
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. More...
 
Status write (Attachment &attachment)
 Write an attachment to the output stream. More...
 
Status write (const Message &message)
 Write a message to the output stream. More...
 
Status write (const Metadata &metadata)
 Write a metadata record to the output stream. More...
 
 ~McapWriter ()
 

Static Public Member Functions

static uint64_t write (IWritable &output, const Attachment &attachment)
 
static uint64_t write (IWritable &output, const AttachmentIndex &index)
 
static void write (IWritable &output, const ByteArray bytes)
 
static uint64_t write (IWritable &output, const Channel &channel)
 
static uint64_t write (IWritable &output, const Chunk &chunk)
 
static uint64_t write (IWritable &output, const ChunkIndex &index)
 
static uint64_t write (IWritable &output, const DataEnd &dataEnd)
 
static uint64_t write (IWritable &output, const Footer &footer, bool crcEnabled)
 
static uint64_t write (IWritable &output, const Header &header)
 
static void write (IWritable &output, const KeyValueMap &map, uint32_t size=0)
 
static uint64_t write (IWritable &output, const Message &message)
 
static uint64_t write (IWritable &output, const MessageIndex &index)
 
static uint64_t write (IWritable &output, const Metadata &metadata)
 
static uint64_t write (IWritable &output, const MetadataIndex &index)
 
static uint64_t write (IWritable &output, const Record &record)
 
static uint64_t write (IWritable &output, const Schema &schema)
 
static uint64_t write (IWritable &output, const Statistics &stats)
 
static void write (IWritable &output, const std::byte *data, uint64_t size)
 
static void write (IWritable &output, const std::string_view str)
 
static uint64_t write (IWritable &output, const SummaryOffset &summaryOffset)
 
static void write (IWritable &output, OpCode value)
 
static void write (IWritable &output, uint16_t value)
 
static void write (IWritable &output, uint32_t value)
 
static void write (IWritable &output, uint64_t value)
 
static void writeMagic (IWritable &output)
 

Private Member Functions

IChunkWritergetChunkWriter ()
 
IWritablegetOutput ()
 
void writeChunk (IWritable &output, IChunkWriter &chunkData)
 

Private Attributes

std::vector< AttachmentIndexattachmentIndex_
 
std::vector< Channelchannels_
 
std::vector< ChunkIndexchunkIndex_
 
uint64_t chunkSize_ = DefaultChunkSize
 
Compression compression_ = Compression::None
 
Timestamp currentChunkEnd_ = 0
 
Timestamp currentChunkStart_ = MaxTime
 
std::unordered_map< ChannelId, MessageIndexcurrentMessageIndex_
 
std::unique_ptr< FileWriterfileOutput_
 
std::unique_ptr< LZ4Writerlz4Chunk_
 
std::vector< MetadataIndexmetadataIndex_
 
bool opened_ = false
 
McapWriterOptions options_ {""}
 
IWritableoutput_ = nullptr
 
std::vector< Schemaschemas_
 
Statistics statistics_ {}
 
std::unique_ptr< StreamWriterstreamOutput_
 
std::unique_ptr< BufferWriteruncompressedChunk_
 
uint64_t uncompressedSize_ = 0
 
std::unordered_set< SchemaIdwrittenSchemas_
 
std::unique_ptr< ZStdWriterzstdChunk_
 

Detailed Description

Provides a write interface to an MCAP file.

Definition at line 304 of file writer.hpp.

Constructor & Destructor Documentation

◆ ~McapWriter()

mcap::McapWriter::~McapWriter ( )

Member Function Documentation

◆ addChannel()

void mcap::McapWriter::addChannel ( Channel channel)

Add a new channel to the MCAP file and set channel.id to a generated channel id. The channel id is used when adding messages to the file.

Parameters
channelDescription of the channel to register. The id value is ignored and will be set to a generated channel id.

◆ addSchema()

void mcap::McapWriter::addSchema ( Schema schema)

Add a new schema to the MCAP file and set schema.id to a generated schema id. The schema id is used when adding channels to the file.

Parameters
schemaDescription of the schema to register. The id field is ignored and will be set to a generated schema id.

◆ close()

void mcap::McapWriter::close ( )

Write the MCAP footer, flush pending writes to the output stream, and reset internal state.

◆ closeLastChunk()

void mcap::McapWriter::closeLastChunk ( )

finishes the current chunk in progress and writes it to the file, if a chunk is in progress.

◆ dataSink()

IWritable* mcap::McapWriter::dataSink ( )

Returns a pointer to the IWritable data destination backing this writer. Will return nullptr if the writer is not open.

◆ getChunkWriter()

IChunkWriter* mcap::McapWriter::getChunkWriter ( )
private

◆ getOutput()

IWritable& mcap::McapWriter::getOutput ( )
private

◆ open() [1/3]

void mcap::McapWriter::open ( IWritable writer,
const McapWriterOptions options 
)

Open a new MCAP file for writing and write the header.

Parameters
writerAn implementation of the IWritable interface. Output bytes will be written to this object.
optionsOptions for MCAP writing. profile is required.

◆ open() [2/3]

void mcap::McapWriter::open ( std::ostream &  stream,
const McapWriterOptions options 
)

Open a new MCAP file for writing and write the header.

Parameters
streamOutput stream to write to.
optionsOptions for MCAP writing. profile is required.

◆ open() [3/3]

Status mcap::McapWriter::open ( std::string_view  filename,
const McapWriterOptions options 
)

Open a new MCAP file for writing and write the header.

Parameters
filenameFilename of the MCAP file to write.
optionsOptions for MCAP writing. profile is required.
Returns
A non-success status if the file could not be opened for writing.

◆ statistics()

const Statistics& mcap::McapWriter::statistics ( ) const

Current MCAP file-level statistics. This is written as a Statistics record in the Summary section of the MCAP file.

◆ terminate()

void mcap::McapWriter::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.

◆ write() [1/27]

Status mcap::McapWriter::write ( Attachment attachment)

Write an attachment to the output stream.

Parameters
attachmentAttachment to add. The attachment.crc will be calculated and set if configuration options allow CRC calculation.
Returns
A non-zero error code on failure.

◆ write() [2/27]

Status mcap::McapWriter::write ( const Message message)

Write a message to the output stream.

Parameters
msgMessage to add.
Returns
A non-zero error code on failure.

◆ write() [3/27]

Status mcap::McapWriter::write ( const Metadata metadata)

Write a metadata record to the output stream.

Parameters
metadataNamed group of key/value string pairs to add.
Returns
A non-zero error code on failure.

◆ write() [4/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Attachment attachment 
)
static

◆ write() [5/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const AttachmentIndex index 
)
static

◆ write() [6/27]

static void mcap::McapWriter::write ( IWritable output,
const ByteArray  bytes 
)
static

◆ write() [7/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Channel channel 
)
static

◆ write() [8/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Chunk chunk 
)
static

◆ write() [9/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const ChunkIndex index 
)
static

◆ write() [10/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const DataEnd dataEnd 
)
static

◆ write() [11/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Footer footer,
bool  crcEnabled 
)
static

◆ write() [12/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Header header 
)
static

◆ write() [13/27]

static void mcap::McapWriter::write ( IWritable output,
const KeyValueMap map,
uint32_t  size = 0 
)
static

◆ write() [14/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Message message 
)
static

◆ write() [15/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const MessageIndex index 
)
static

◆ write() [16/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Metadata metadata 
)
static

◆ write() [17/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const MetadataIndex index 
)
static

◆ write() [18/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Record record 
)
static

◆ write() [19/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Schema schema 
)
static

◆ write() [20/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const Statistics stats 
)
static

◆ write() [21/27]

static void mcap::McapWriter::write ( IWritable output,
const std::byte *  data,
uint64_t  size 
)
static

◆ write() [22/27]

static void mcap::McapWriter::write ( IWritable output,
const std::string_view  str 
)
static

◆ write() [23/27]

static uint64_t mcap::McapWriter::write ( IWritable output,
const SummaryOffset summaryOffset 
)
static

◆ write() [24/27]

static void mcap::McapWriter::write ( IWritable output,
OpCode  value 
)
static

◆ write() [25/27]

static void mcap::McapWriter::write ( IWritable output,
uint16_t  value 
)
static

◆ write() [26/27]

static void mcap::McapWriter::write ( IWritable output,
uint32_t  value 
)
static

◆ write() [27/27]

static void mcap::McapWriter::write ( IWritable output,
uint64_t  value 
)
static

◆ writeChunk()

void mcap::McapWriter::writeChunk ( IWritable output,
IChunkWriter chunkData 
)
private

◆ writeMagic()

static void mcap::McapWriter::writeMagic ( IWritable output)
static

Member Data Documentation

◆ attachmentIndex_

std::vector<AttachmentIndex> mcap::McapWriter::attachmentIndex_
private

Definition at line 452 of file writer.hpp.

◆ channels_

std::vector<Channel> mcap::McapWriter::channels_
private

Definition at line 451 of file writer.hpp.

◆ chunkIndex_

std::vector<ChunkIndex> mcap::McapWriter::chunkIndex_
private

Definition at line 454 of file writer.hpp.

◆ chunkSize_

uint64_t mcap::McapWriter::chunkSize_ = DefaultChunkSize
private

Definition at line 443 of file writer.hpp.

◆ compression_

Compression mcap::McapWriter::compression_ = Compression::None
private

Definition at line 460 of file writer.hpp.

◆ currentChunkEnd_

Timestamp mcap::McapWriter::currentChunkEnd_ = 0
private

Definition at line 459 of file writer.hpp.

◆ currentChunkStart_

Timestamp mcap::McapWriter::currentChunkStart_ = MaxTime
private

Definition at line 458 of file writer.hpp.

◆ currentMessageIndex_

std::unordered_map<ChannelId, MessageIndex> mcap::McapWriter::currentMessageIndex_
private

Definition at line 457 of file writer.hpp.

◆ fileOutput_

std::unique_ptr<FileWriter> mcap::McapWriter::fileOutput_
private

Definition at line 445 of file writer.hpp.

◆ lz4Chunk_

std::unique_ptr<LZ4Writer> mcap::McapWriter::lz4Chunk_
private

Definition at line 448 of file writer.hpp.

◆ metadataIndex_

std::vector<MetadataIndex> mcap::McapWriter::metadataIndex_
private

Definition at line 453 of file writer.hpp.

◆ opened_

bool mcap::McapWriter::opened_ = false
private

Definition at line 462 of file writer.hpp.

◆ options_

McapWriterOptions mcap::McapWriter::options_ {""}
private

Definition at line 442 of file writer.hpp.

◆ output_

IWritable* mcap::McapWriter::output_ = nullptr
private

Definition at line 444 of file writer.hpp.

◆ schemas_

std::vector<Schema> mcap::McapWriter::schemas_
private

Definition at line 450 of file writer.hpp.

◆ statistics_

Statistics mcap::McapWriter::statistics_ {}
private

Definition at line 455 of file writer.hpp.

◆ streamOutput_

std::unique_ptr<StreamWriter> mcap::McapWriter::streamOutput_
private

Definition at line 446 of file writer.hpp.

◆ uncompressedChunk_

std::unique_ptr<BufferWriter> mcap::McapWriter::uncompressedChunk_
private

Definition at line 447 of file writer.hpp.

◆ uncompressedSize_

uint64_t mcap::McapWriter::uncompressedSize_ = 0
private

Definition at line 461 of file writer.hpp.

◆ writtenSchemas_

std::unordered_set<SchemaId> mcap::McapWriter::writtenSchemas_
private

Definition at line 456 of file writer.hpp.

◆ zstdChunk_

std::unique_ptr<ZStdWriter> mcap::McapWriter::zstdChunk_
private

Definition at line 449 of file writer.hpp.


The documentation for this class was generated from the following file:


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:52