pub struct V3Writer { /* private fields */ }Expand description
V3 columnar metrics writer.
Accumulates metrics in columnar format with dictionary deduplication.
Call V3Writer::write for each metric, then V3Writer::finalize to finalize
and get the encoded data.
Implementations§
Source§impl V3Writer
impl V3Writer
Sourcepub fn metric_count(&self) -> usize
pub fn metric_count(&self) -> usize
Returns the number of metrics written so far.
Sourcepub fn estimated_uncompressed_len(&self) -> usize
pub fn estimated_uncompressed_len(&self) -> usize
Returns an estimate, in bytes, of the uncompressed size of the payload this writer would currently finalize to.
This exists so callers can decide when to stop adding metrics to a batch, rather than encoding an oversized batch and discovering afterwards that it has to be split and re-encoded. It is deliberately cheap: it inspects only the lengths of the accumulated columns, so it is O(1) and safe to call after every metric.
The figure is an estimate, not the exact finalized size. Dictionary string buffers are counted exactly, since
they dominate for the high-cardinality workloads this guards against, while packed integer columns are counted
at a fixed per-entry allowance because their true varint widths are only known once delta encoding runs during
V3Writer::finalize. The allowance errs on the high side, so batches are cut slightly early rather than
slightly late; callers MUST still check the finalized payload against their real size limits.
Sourcepub fn write(
&mut self,
metric_type: V3MetricType,
name: &str,
) -> V3MetricBuilder<'_>
pub fn write( &mut self, metric_type: V3MetricType, name: &str, ) -> V3MetricBuilder<'_>
Begins writing a new metric.
Returns a V3MetricBuilder that must be used to set the metric’s
properties and add points, then closed with V3MetricBuilder::close.
Sourcepub fn finalize(self) -> Result<V3EncodedMetrics, V3EncodeError>
pub fn finalize(self) -> Result<V3EncodedMetrics, V3EncodeError>
Finalizes the writer and serializes the data to the given output buffer.
This performs delta encoding on all index arrays.