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>> { ... }
}parse only.Expand description
A format parser.
The contract every implementation keeps, and the driver relies on:
NoMatchmeans nothing was written to the sink.- A span the parser accepts is never one its signature rules out.
- A
Bodyspan lies within the input. ADecodedbody 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§
Sourcefn name(&self) -> &str
fn name(&self) -> &str
Registry name: a format (syslog), or a format and an instance
(grok:firewall). See valid_parser_name.
Sourcefn tier(&self) -> MatcherTier
fn tier(&self) -> MatcherTier
The slowest tier anything in this parser runs on.
Sourcefn parse<'a>(
&self,
input: &'a [u8],
out: &mut dyn FieldSink<'a>,
) -> Result<Parsed, ParseError>
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§
Sourcefn cost(&self) -> Option<Cost>
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.
Sourcefn parse_counted<'a>(
&self,
input: &'a [u8],
out: &mut dyn FieldSink<'a>,
counts: &mut ParserCounts,
) -> Result<Parsed, ParseError>
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.
Sourcefn decodes(&self) -> bool
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.
Sourcefn detectable(&self) -> bool
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.
Sourcefn hands_on_body(&self) -> bool
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.
Sourcefn escape_value(
&self,
input: &[u8],
field: usize,
at: Range<usize>,
value: &[u8],
out: &mut Vec<u8>,
) -> Option<Range<usize>>
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§
impl Parser for Cef
parse-cef only.impl Parser for CloudLog
parse-cloud only.impl Parser for Compiled
parse-grok only.impl Parser for Cri
parse-cri only.impl Parser for Csv
parse-csv only.impl Parser for Decoder
decode-base64 or decode-gzip or decode-hex or decode-rsyslog or decode-snappy or decode-text or decode-zlib or decode-zstd only.impl Parser for Dissect
parse-dissect only.impl Parser for Gelf
parse-gelf only.impl Parser for Grok
parse-grok only.impl Parser for Http
parse-http only.impl Parser for Ini
parse-ini only.impl Parser for Kv
parse-kv only.impl Parser for Leef
parse-leef only.impl Parser for Msgpack
parse-msgpack only.impl Parser for Ndjson
parse-ndjson only.impl Parser for Prometheus
parse-prometheus only.impl Parser for Protobuf
parse-protobuf only.impl Parser for Query
parse-query only.impl Parser for Syslog
parse-syslog only.impl Parser for Toml
parse-toml only.impl Parser for Uri
parse-uri only.impl Parser for Xml
parse-xml only.impl Parser for Yaml
parse-yaml only.