rusticata / pcap-parser

PCAP/PCAPNG file format parser written in pure Rust. Fast, zero-copy, safe.
Other
103 stars 24 forks source link

PcapReaderIterator::consume documentation vs PcapNGReader implementation #9

Closed kbleeke closed 3 years ago

kbleeke commented 3 years ago

The documentation here says that calls to consume also refill the buffer, if necessary. However, the implementation in PcapNGReader does not do so and only refill on explicit calls to refill. Neither does the legacy implementation.

I assume this is a docs issue because refilling is fallible but consume does not return a Result?

chifflier commented 3 years ago

Hm, I had to look twice to make sure I understand this part of the code.

I think the documentation is wrong here: consume does not refill the buffer, but will shift it if necessary (done by the inner circular buffer: https://docs.rs/circular/0.3.0/circular/struct.Buffer.html#method.consume). I don't think a refill would be wise, because it would cause multiple partial reads (and would prevent the crate user to control when reads are done).

I'll update the documentation.

edit: typos