Trait packet::records::RecordsImpl
source · pub trait RecordsImpl: RecordsImplLayout {
type Record<'a>;
// Required method
fn parse_with_context<'a, BV: BufferView<&'a [u8]>>(
data: &mut BV,
context: &mut Self::Context,
) -> RecordParseResult<Self::Record<'a>, Self::Error>;
}
Expand description
An implementation of a records parser.
RecordsImpl
provides functions to parse sequential records. It is required
in order to construct a Records
or RecordsIter
.
Required Associated Types§
sourcetype Record<'a>
type Record<'a>
The type of a single record; the output from the parse_with_context
function.
For long or variable-length data, implementers are advised to make
Record
a reference into the bytes passed to parse_with_context
. Such
a reference will need to carry the lifetime 'a
, which is the same
lifetime that is passed to parse_with_context
, and is also the
lifetime parameter to this trait.
Required Methods§
sourcefn parse_with_context<'a, BV: BufferView<&'a [u8]>>(
data: &mut BV,
context: &mut Self::Context,
) -> RecordParseResult<Self::Record<'a>, Self::Error>
fn parse_with_context<'a, BV: BufferView<&'a [u8]>>( data: &mut BV, context: &mut Self::Context, ) -> RecordParseResult<Self::Record<'a>, Self::Error>
Parses a record with some context.
parse_with_context
takes a variable-length data
and a context
to
maintain state.
data
may be empty. It is up to the implementer to handle an exhausted
data
.
When returning Ok(ParsedRecord::Skipped)
, it’s the implementer’s
responsibility to consume the bytes of the record from data
. If this
doesn’t happen, then parse_with_context
will be called repeatedly on
the same data
, and the program will be stuck in an infinite loop. If
the implementation is unable to determine how many bytes to consume from
data
in order to skip the record, parse_with_context
must return
Err
.
parse_with_context
must be deterministic, or else
Records::parse_with_context
cannot guarantee that future iterations
will not produce errors (and thus panic).