Skip to main content

MessageParser

Struct MessageParser 

Source
pub struct MessageParser { /* private fields */ }
Expand description

A stateful parser that reconstructs fully attributed LogsData records from a stream of FXT log packets.

§Background & Architecture

In the Fuchsia Trace Format (FXT) structured logging protocol, log attribution metadata is separated from the actual log payload to optimize transmission overhead. Instead of repeating the full moniker and component URL on every log record, the system transmits two distinct types of records:

  1. Manifest/Control Records: Sent with the LOG_CONTROL_BIT set. These records map a numeric base tag ID to component identity metadata (ExtendedMoniker and URL).
  2. Legacy Log Records: Contain the message content, severity, timestamp, and arguments, along with a tag ID indicating which component produced the log.

§Stateful Parsing

MessageParser maintains an internal tag_map to track the active association between numeric tag IDs and their component identity (ExtendedMetadata).

  • When parsing a manifest record (is_control == true), MessageParser updates its state mapping for the derived base tag. If the record also reports rolled out (dropped) logs, a LogsData payload representing those dropped logs is returned. Otherwise, it registers the attribution mapping and returns Ok((None, remaining)).
  • When parsing a legacy log record (is_control == false), MessageParser resolves the record’s tag to retrieve the component’s identity from the internal mapping, constructing a fully attributed LogsData containing the correct component moniker and URL.

Implementations§

Source§

impl MessageParser

Source

pub fn parse_next<'a, F: MessageFormatter>( &mut self, bytes: &'a [u8], formatter: F, ) -> Result<(Option<F::Result>, &'a [u8]), MessageError>

Parses the next log record from the given bytes.

This function can handle both standard log records and “Archivist” manifest records. Archivist records update an internal map used to attribute subsequent log records.

§Arguments
  • bytes: A byte slice containing one or more log records.
§Returns

A Result containing:

  • Ok((Option<LogsData>, &[u8])): A tuple where the first element is Some(LogsData) if a log message was parsed, or None if it was an Archivist manifest record. The second element is the remaining slice of bytes after parsing the record.
  • Err(MessageError): An error if parsing failed.

Trait Implementations§

Source§

impl Default for MessageParser

Source§

fn default() -> MessageParser

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
§

impl<T, D> Encode<Ambiguous1, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
§

impl<T, D> Encode<Ambiguous2, D> for T
where D: ResourceDialect,

§

unsafe fn encode( self, _encoder: &mut Encoder<'_, D>, _offset: usize, _depth: Depth, ) -> Result<(), Error>

Encodes the object into the encoder’s buffers. Any handles stored in the object are swapped for Handle::INVALID. Read more
§

impl<F, N> FidlIntoNative<Box<N>> for F
where F: FidlIntoNative<N>,

§

fn fidl_into_native(self) -> Box<N>

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
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.