TraceFileWriter¶
-
class TraceFileWriter¶
Abstract base class for writing trace files in various formats.
This class provides an interface for writing protobuf messages to trace files. Different implementations can support various file formats like .osi, .mcap or .txth.
The WriteMessage() method accepts any protobuf message via the type-erased google::protobuf::Message base class. For MCAP format, the topic parameter selects the channel; for single-channel formats (.osi, .txth) it is ignored.
Concrete implementations also provide template<typename T> WriteMessage() overloads for compile-time type safety when the message type is known.
Note
Thread Safety: Instances are not thread-safe. Concurrent calls on the same writer must be externally synchronized.
Note
Error Strategy:
Openreturnsfalseand logs tostd::cerron failure.WriteMessagereturnsfalseon write errors.Subclassed by osi3::MCAPTraceFileWriter, osi3::SingleChannelBinaryTraceFileWriter, osi3::TXTHTraceFileWriter
Public Functions
-
virtual ~TraceFileWriter() = default¶
Virtual destructor.
-
TraceFileWriter() = default¶
Default constructor.
-
TraceFileWriter(const TraceFileWriter&) = delete¶
Deleted copy constructor.
-
TraceFileWriter &operator=(const TraceFileWriter&) = delete¶
Deleted copy assignment operator.
-
TraceFileWriter(TraceFileWriter&&) = delete¶
Deleted move constructor.
-
TraceFileWriter &operator=(TraceFileWriter&&) = delete¶
Deleted move assignment operator.
-
virtual bool Open(const std::filesystem::path &file_path) = 0¶
Opens a file for writing.
- Parameters:
file_path – Path to the file to be created/opened
- Returns:
true if successful, false otherwise
-
virtual bool WriteMessage(const google::protobuf::Message &message, const std::string &topic = "") = 0¶
Writes a protobuf message to the trace file.
Type-erased write method that accepts any protobuf message. The behavior of the topic parameter depends on the writer implementation:
MCAP: topic selects the channel. If the topic has not been registered via AddChannel(), it is auto-registered using the message’s descriptor. Required file metadata is also auto-added on first write if not set.
Binary (.osi) and Text (.txth): topic is ignored (single-channel formats).
- Parameters:
message – The protobuf message to write
topic – Channel/topic name (required for MCAP, ignored for .osi/.txth)
- Returns:
true if successful, false otherwise
-
virtual void Close() = 0¶
Closes the trace file.
-
virtual ~TraceFileWriter() = default¶