Skip to main content

Parser

Trait Parser 

Source
pub trait Parser: Send + Sync {
    // Required methods
    fn name(&self) -> &str;
    fn tier(&self) -> MatcherTier;
    fn signature(&self) -> &Signature;
    fn parse<'a>(
        &self,
        input: &'a [u8],
        out: &mut dyn FieldSink<'a>,
    ) -> Result<Parsed, ParseError>;

    // Provided methods
    fn cost(&self) -> Option<Cost> { ... }
    fn parse_counted<'a>(
        &self,
        input: &'a [u8],
        out: &mut dyn FieldSink<'a>,
        counts: &mut ParserCounts,
    ) -> Result<Parsed, ParseError> { ... }
    fn decodes(&self) -> bool { ... }
    fn detectable(&self) -> bool { ... }
    fn hands_on_body(&self) -> bool { ... }
    fn escape_value(
        &self,
        input: &[u8],
        field: usize,
        at: Range<usize>,
        value: &[u8],
        out: &mut Vec<u8>,
    ) -> Option<Range<usize>> { ... }
}
Available on crate feature parse only.
Expand description

A format parser.

The contract every implementation keeps, and the driver relies on:

  • NoMatch means nothing was written to the sink.
  • A span the parser accepts is never one its signature rules out.
  • A Body span lies within the input. A Decoded body is bytes it owns.
  • Every prefix it pushes is popped before it returns, on an error too.
  • Its work is at most proportional to its input, or for a decoder to its output, which its cap bounds.

Required Methods§

Source

fn name(&self) -> &str

Registry name: a format (syslog), or a format and an instance (grok:firewall). See valid_parser_name.

Source

fn tier(&self) -> MatcherTier

The slowest tier anything in this parser runs on.

Source

fn signature(&self) -> &Signature

The cheapest test that rules a span out.

Source

fn parse<'a>( &self, input: &'a [u8], out: &mut dyn FieldSink<'a>, ) -> Result<Parsed, ParseError>

Parse input, writing fields into out.

§Errors

ParseError when the input is this parser’s but is broken. Fields written before the error are rolled back by the driver.

Provided Methods§

Source

fn cost(&self) -> Option<Cost>

What a line costs, measured on the reference host, or None where nothing was. A stock parser has its own row in the table.

Source

fn parse_counted<'a>( &self, input: &'a [u8], out: &mut dyn FieldSink<'a>, counts: &mut ParserCounts, ) -> Result<Parsed, ParseError>

Parser::parse for a Batch: the parser’s own counts go to counts, and the batch adds them when it publishes. The default counts at once, as parse does.

§Errors

As Parser::parse.

Source

fn decodes(&self) -> bool

Whether this parser decodes its input and hands on bytes it owns, as Parsed::Decoded, in place of writing fields. A layered record puts what such a layer hands on at its own place, with no key of its own.

Source

fn detectable(&self) -> bool

Whether auto may pick this parser by its signature. A parser whose signature has no literal is never detected, whatever this returns.

Source

fn hands_on_body(&self) -> bool

Whether Parser::parse can return Parsed::Body. A parser that says false never hands on a body, so a layer plan rejects a body hop after it. The default is true, which rejects nothing.

Source

fn escape_value( &self, input: &[u8], field: usize, at: Range<usize>, value: &[u8], out: &mut Vec<u8>, ) -> Option<Range<usize>>

Appends value to out as this format writes field field of input, a record it read, in place of at: the bytes it lent for that field’s value, or ones this method wrote for its old value. Returns the range of input the appended bytes replace, at or a range around it such as at with its quotes. An empty input asks for the value as written with no record around it.

None, with out as it was, when the format can’t hold value there. The default writes value as it is over at, for a format with no escape, and leaves the write-back’s re-parse to refuse a value that doesn’t read back.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl Parser for Cef

Available on crate feature parse-cef only.
Source§

impl Parser for CloudLog

Available on crate feature parse-cloud only.
Source§

impl Parser for Compiled

Available on crate feature parse-grok only.
Source§

impl Parser for Cri

Available on crate feature parse-cri only.
Source§

impl Parser for Csv

Available on crate feature parse-csv only.
Source§

impl Parser for Decoder

Available on crate features decode-base64 or decode-gzip or decode-hex or decode-rsyslog or decode-snappy or decode-text or decode-zlib or decode-zstd only.
Source§

impl Parser for Dissect

Available on crate feature parse-dissect only.
Source§

impl Parser for Gelf

Available on crate feature parse-gelf only.
Source§

impl Parser for Grok

Available on crate feature parse-grok only.
Source§

impl Parser for Http

Available on crate feature parse-http only.
Source§

impl Parser for Ini

Available on crate feature parse-ini only.
Source§

impl Parser for Kv

Available on crate feature parse-kv only.
Source§

impl Parser for Leef

Available on crate feature parse-leef only.
Source§

impl Parser for Msgpack

Available on crate feature parse-msgpack only.
Source§

impl Parser for Ndjson

Available on crate feature parse-ndjson only.
Source§

impl Parser for Prometheus

Available on crate feature parse-prometheus only.
Source§

impl Parser for Protobuf

Available on crate feature parse-protobuf only.
Source§

impl Parser for Query

Available on crate feature parse-query only.
Source§

impl Parser for Syslog

Available on crate feature parse-syslog only.
Source§

impl Parser for Toml

Available on crate feature parse-toml only.
Source§

impl Parser for Uri

Available on crate feature parse-uri only.
Source§

impl Parser for Xml

Available on crate feature parse-xml only.
Source§

impl Parser for Yaml

Available on crate feature parse-yaml only.