Skip to main content

LineBuffer

Struct LineBuffer 

Source
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

Source

pub fn new() -> Self

Creates a new, empty line buffer with the compiled header regex.

Source

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.

Source

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.

Source

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).

Source

pub fn is_empty(&self) -> bool

Returns true if no entry is currently being accumulated.

Trait Implementations§

Source§

impl Default for LineBuffer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.