pub struct MoqTraceWriter<W: Write> {
inner: BufWriter<W>,
}Expand description
Streaming writer for .moqtrace files.
Writes a preamble (magic, version, header) on construction, then accepts
events one at a time via write_event.
For a segmented trace — on-disk capture rotation, or a live stream carried
over MoQT — call start_segment to begin a new
segment with a fresh preamble of its own. A plain file is one segment.
The inner writer is wrapped in a BufWriter so events can be appended
at line rate without incurring one syscall per event. Call
flush or into_inner to drain the
buffer.
Fields§
§inner: BufWriter<W>Implementations§
Source§impl<W: Write> MoqTraceWriter<W>
impl<W: Write> MoqTraceWriter<W>
Sourcepub fn new(writer: W, header: &TraceHeader) -> Result<Self, MoqTraceError>
pub fn new(writer: W, header: &TraceHeader) -> Result<Self, MoqTraceError>
Create a new writer, writing the preamble and header of the file (or of its first segment).
Sourcepub fn write_event(&mut self, event: &TraceEvent) -> Result<(), MoqTraceError>
pub fn write_event(&mut self, event: &TraceEvent) -> Result<(), MoqTraceError>
Append a single event to the current segment.
Sourcepub fn start_segment(
&mut self,
header: &TraceHeader,
) -> Result<(), MoqTraceError>
pub fn start_segment( &mut self, header: &TraceHeader, ) -> Result<(), MoqTraceError>
Begin a new segment, writing a fresh preamble immediately after the previous segment’s last event.
The header must carry segment metadata, and
this returns an error if it does not. That field is what tells a
reader the sequence numbers and timestamps it is about to see restart
at zero; without it a reader takes each segment for a complete file
and reconstructs a timeline that repeatedly jumps backwards.
The new header should keep the same protocol, perspective,
detail and session_id as the segments before it, and increment
segment.sequence.
Sourcepub fn flush(&mut self) -> Result<(), MoqTraceError>
pub fn flush(&mut self) -> Result<(), MoqTraceError>
Flush the underlying writer.
Sourcepub fn into_inner(self) -> Result<W, MoqTraceError>
pub fn into_inner(self) -> Result<W, MoqTraceError>
Consume the writer and return the inner writer.
Flushes any buffered bytes. Returns an error if the flush fails.