pub struct PcapReader { /* private fields */ }Expand description
PCAP数据集读取器
提供对PCAP数据集的高性能读取功能,支持:
- 自动索引管理和验证
- 顺序读取和文件切换
- 智能缓存和性能优化
- 多文件数据集统一访问
Implementations§
Source§impl PcapReader
impl PcapReader
Sourcepub fn new_with_config<P: AsRef<Path>>(
base_path: P,
dataset_name: &str,
configuration: ReaderConfig,
) -> PcapResult<Self>
pub fn new_with_config<P: AsRef<Path>>( base_path: P, dataset_name: &str, configuration: ReaderConfig, ) -> PcapResult<Self>
Sourcepub fn initialize(&mut self) -> PcapResult<()>
pub fn initialize(&mut self) -> PcapResult<()>
初始化读取器
确保索引可用并准备好读取操作
Sourcepub fn get_dataset_info(&mut self) -> PcapResult<DatasetInfo>
pub fn get_dataset_info(&mut self) -> PcapResult<DatasetInfo>
获取数据集信息
Sourcepub fn get_file_info_list(&mut self) -> PcapResult<Vec<FileInfo>>
pub fn get_file_info_list(&mut self) -> PcapResult<Vec<FileInfo>>
获取文件信息列表
Sourcepub fn dataset_path(&self) -> &Path
pub fn dataset_path(&self) -> &Path
获取数据集路径
Sourcepub fn dataset_name(&self) -> &str
pub fn dataset_name(&self) -> &str
获取数据集名称
Sourcepub fn read_packet(&mut self) -> PcapResult<Option<ValidatedPacket>>
pub fn read_packet(&mut self) -> PcapResult<Option<ValidatedPacket>>
读取下一个数据包(默认方法,带校验结果)
从当前位置读取下一个数据包,包含校验状态信息。如果当前文件读取完毕, 会自动切换到下一个文件。
§返回
Ok(Some(result))- 成功读取到数据包和校验结果Ok(None)- 到达文件末尾,无更多数据包Err(error)- 读取过程中发生错误
Sourcepub fn read_packet_data_only(&mut self) -> PcapResult<Option<DataPacket>>
pub fn read_packet_data_only(&mut self) -> PcapResult<Option<DataPacket>>
读取下一个数据包(仅返回数据,不返回校验信息)
从当前位置读取下一个数据包,仅返回数据包本身。如果当前文件读取完毕, 会自动切换到下一个文件。
§返回
Ok(Some(packet))- 成功读取到数据包Ok(None)- 到达文件末尾,无更多数据包Err(error)- 读取过程中发生错误
Sourcepub fn read_packets(&mut self, count: usize) -> PcapResult<Vec<ValidatedPacket>>
pub fn read_packets(&mut self, count: usize) -> PcapResult<Vec<ValidatedPacket>>
Sourcepub fn read_packets_data_only(
&mut self,
count: usize,
) -> PcapResult<Vec<DataPacket>>
pub fn read_packets_data_only( &mut self, count: usize, ) -> PcapResult<Vec<DataPacket>>
Sourcepub fn reset(&mut self) -> PcapResult<()>
pub fn reset(&mut self) -> PcapResult<()>
重置读取器到数据集开始位置
将读取器重置到数据集的开始位置,后续读取将从第一个数据包开始。
Sourcepub fn index(&self) -> &IndexManager
pub fn index(&self) -> &IndexManager
获取索引管理器的引用 允许外部通过 reader.index().method() 的方式访问索引功能
Sourcepub fn index_mut(&mut self) -> &mut IndexManager
pub fn index_mut(&mut self) -> &mut IndexManager
获取索引管理器的可变引用 允许外部通过 reader.index_mut().method() 的方式访问索引功能
Sourcepub fn seek_by_timestamp(
&mut self,
timestamp_ns: u64,
) -> PcapResult<Option<TimestampPointer>>
pub fn seek_by_timestamp( &mut self, timestamp_ns: u64, ) -> PcapResult<Option<TimestampPointer>>
Sourcepub fn read_packets_by_time_range(
&mut self,
start_timestamp_ns: u64,
end_timestamp_ns: u64,
) -> PcapResult<Vec<ValidatedPacket>>
pub fn read_packets_by_time_range( &mut self, start_timestamp_ns: u64, end_timestamp_ns: u64, ) -> PcapResult<Vec<ValidatedPacket>>
Sourcepub fn get_cache_stats(&self) -> CacheStats
pub fn get_cache_stats(&self) -> CacheStats
获取缓存统计信息
Sourcepub fn clear_cache(&mut self) -> PcapResult<()>
pub fn clear_cache(&mut self) -> PcapResult<()>
清理缓存
Sourcepub fn seek_to_timestamp(&mut self, timestamp_ns: u64) -> PcapResult<u64>
pub fn seek_to_timestamp(&mut self, timestamp_ns: u64) -> PcapResult<u64>
Sourcepub fn seek_to_packet(&mut self, packet_index: usize) -> PcapResult<()>
pub fn seek_to_packet(&mut self, packet_index: usize) -> PcapResult<()>
Sourcepub fn total_packets(&self) -> Option<usize>
pub fn total_packets(&self) -> Option<usize>
获取总数据包数量(如果索引可用)
Sourcepub fn current_packet_index(&self) -> u64
pub fn current_packet_index(&self) -> u64
获取当前数据包索引位置(全局序号,从0开始)
Sourcepub fn skip_packets(&mut self, count: usize) -> PcapResult<usize>
pub fn skip_packets(&mut self, count: usize) -> PcapResult<usize>
Sourcepub fn read_packet_by_timestamp(
&mut self,
timestamp_ns: u64,
) -> PcapResult<Option<ValidatedPacket>>
pub fn read_packet_by_timestamp( &mut self, timestamp_ns: u64, ) -> PcapResult<Option<ValidatedPacket>>
根据时间戳读取数据包
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for PcapReader
impl !RefUnwindSafe for PcapReader
impl Send for PcapReader
impl !Sync for PcapReader
impl Unpin for PcapReader
impl UnwindSafe for PcapReader
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more