pub struct LineBuffer { /* private fields */ }Expand description
Accumulates raw lines and produces complete LogEntry values when an
entry is structurally complete.
§Usage
Feed lines one at a time via push_line. Each call
returns a Vec<LogEntry> containing zero, one, or two complete entries:
- Zero entries: continuation line for an in-progress multi-line entry, or a headerless line discarded with a warning.
- One entry: a single-line entry emitted on arrival, a multi-line entry being brace-balance-flushed (default feature behavior), or a multi-line entry being flushed by the arrival of the next header.
- Two entries: a multi-line entry being flushed by a new header plus the new single-line entry that triggered the flush, both emitted from one call.
After the input stream ends (EOF or file rotation), call
flush to retrieve any remaining buffered entry.
§Flush triggers
With the default brace_depth_flush feature enabled, a multi-line
entry flushes the moment its body’s JSON depth returns to 0 — no need
to wait for the next header. Bodies that never contain a { (rare
non-JSON GRE markers and true-bodied REST responses) still fall back
to the original “flush on next header” path. See the module-level docs
for the corpus analysis backing this design.
§Example
use manasight_parser::log::entry::LineBuffer;
let mut buf = LineBuffer::new();
// First header (multi-line, date-prefixed) — nothing to flush yet.
assert!(buf.push_line("[UnityCrossThreadLogger]1/1/2025 12:00:00 PM").is_empty());
// Continuation line opens a `{` — still accumulating until the body
// brace-balances (or, with the feature disabled, until the next header).
assert!(buf.push_line(r#"{"key": "ba"#).is_empty());
// The body's brace depth returns to 0 — entry flushes immediately
// (default feature on); the next header is not required.
let entries = buf.push_line(r#" r"}"#);
assert_eq!(entries.len(), 1);Implementations§
Source§impl LineBuffer
impl LineBuffer
Sourcepub fn push_line(&mut self, line: &str) -> Vec<LogEntry>
pub fn push_line(&mut self, line: &str) -> Vec<LogEntry>
Feeds a single line into the buffer.
Returns a Vec<LogEntry> containing 0, 1, or 2 complete entries
— see the type-level documentation for the full semantics.
§Header classification
When line matches a known header pattern, it is classified as either
single-line or multi-line (see module-level docs). Single-line
headers ([UnityCrossThreadLogger]<non-digit>, [ConnectionManager]…,
Matchmaking:…) flush any prior multi-line entry and emit the new
entry in the same call. Multi-line headers
([UnityCrossThreadLogger]<digit>) flush any prior
entry and begin a fresh accumulation.
Metadata lines (DETAILED LOGS: ENABLED / DISABLED) are
self-contained — treated as single-line entries that flush any prior
in-progress entry alongside themselves.
Lines that arrive before any header has been seen are discarded with a warning log — this handles partial entries at the start of a file or after rotation.
§Input contract
Callers must strip any trailing \r (Windows CRLF) before invoking
this method. crate::log::tailer::FileTailer::poll already does
this; direct callers in tests must do the same to keep classification
well-defined. push_line itself strips a leading [<digits>] Unity
frame-counter prefix before classification, so callers and tests need
not pre-strip it.
Sourcepub fn flush(&mut self) -> Option<LogEntry>
pub fn flush(&mut self) -> Option<LogEntry>
Flushes any remaining buffered entry.
Call this when the input stream ends (EOF or file rotation) to
retrieve the last accumulated multi-line entry, if any. Single-line
entries are never buffered — they are emitted by [push_line] in the
same call that received them — so this method only ever returns at
most one entry.
Sourcepub fn reset(&mut self)
pub fn reset(&mut self)
Resets the buffer, discarding any in-progress entry.
Useful on file rotation when the previous partial entry should be abandoned. Also re-arms the orphan-warning flag so the first post-rotation orphan still surfaces a warning (the rotation case the warning was originally meant to detect).