PacketReader

Trait PacketReader 

Source
pub trait PacketReader: Send + Unpin {
    // Required methods
    fn process_packets<F>(&mut self, max: usize, f: F) -> Result<usize, Error>
       where F: FnMut(PacketRef<'_>) -> Result<(), Error>;
    fn position(&self) -> PacketPosition;
    fn link_type(&self) -> u32;
}
Expand description

Sequential reader of packets from a source.

This is the hot path - implementations should be optimized for sequential reading with minimal overhead per packet.

§Zero-Copy API

Uses process_packets() with a callback pattern to avoid copying packet data. The callback receives borrowed packet data that is only valid during the callback invocation.

Required Methods§

Source

fn process_packets<F>(&mut self, max: usize, f: F) -> Result<usize, Error>
where F: FnMut(PacketRef<'_>) -> Result<(), Error>,

Process up to max packets with borrowed data via callback.

The callback receives borrowed packet data and must process it (parse, add to Arrow builders, etc.) before returning. The borrow is only valid during the callback.

Returns the number of packets processed (may be less than max at EOF).

§Example
reader.process_packets(1024, |packet| {
    // packet.data is borrowed - must be processed here
    let parsed = parse_packet(packet.link_type, packet.data);
    builder.add_row(packet.frame_number, &parsed);
    Ok(())
})?;
Source

fn position(&self) -> PacketPosition

Current position in the source.

Get the link type for packets from this reader.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§