Slick Sim 0.10.1
Exchange simulator that shadows real venues for risk-free strategy testing
Loading...
Searching...
No Matches
slick::sim::md_feed::PcapReader Class Reference

Reads UDP payloads, in capture order, out of one pcap or pcapng file. More...

#include <md_feed/pcap_reader.hpp>

Collaboration diagram for slick::sim::md_feed::PcapReader:

Public Member Functions

 PcapReader (const std::string &path)
 Opens path. Throws std::runtime_error when it cannot be opened or read as a capture.
 PcapReader (const PcapReader &)=delete
PcapReader & operator= (const PcapReader &)=delete
bool next (PcapPacket &out)
 Reads the next UDP datagram.
const std::string & error () const
 Empty after a clean end of file; otherwise what stopped the read, for example a capture truncated mid-packet.
const std::string & path () const
uint64_t truncated () const noexcept
 Frames skipped so far for being cut short or malformed - not those that are simply not UDP (IGMP, ARP, fragments of other protocols).

Detailed Description

Reads UDP payloads, in capture order, out of one pcap or pcapng file.

.zst and .gz files are decompressed as they are read, so a multi-gigabyte day file is never held in memory or on disk. That stream cannot be seeked: reaching a timestamp means reading up to it.

Classic pcap (micro or nanosecond, either byte order) and pcapng (any byte order and timestamp resolution, several interfaces) are read here, without libpcap, and reported in nanoseconds. Ethernet (with 802.1Q tags) and raw IP link types are understood. Frames that are not whole IPv4 UDP datagrams (IGMP, fragments, other protocols) are skipped.

Not thread-safe; one thread owns a reader.

Definition at line 258 of file pcap_reader.hpp.

Constructor & Destructor Documentation

◆ PcapReader() [1/2]

slick::sim::md_feed::PcapReader::PcapReader ( const std::string & path)
inlineexplicit

Opens path. Throws std::runtime_error when it cannot be opened or read as a capture.

Definition at line 261 of file pcap_reader.hpp.

References path().

Referenced by PcapReader(), and operator=().

◆ PcapReader() [2/2]

slick::sim::md_feed::PcapReader::PcapReader ( const PcapReader & )
delete

References PcapReader().

Member Function Documentation

◆ error()

const std::string & slick::sim::md_feed::PcapReader::error ( ) const
inlinenodiscard

Empty after a clean end of file; otherwise what stopped the read, for example a capture truncated mid-packet.

Definition at line 299 of file pcap_reader.hpp.

◆ next()

bool slick::sim::md_feed::PcapReader::next ( PcapPacket & out)
inline

Reads the next UDP datagram.

False at the end of the file; error() says whether that was a clean end.

Definition at line 290 of file pcap_reader.hpp.

◆ operator=()

PcapReader & slick::sim::md_feed::PcapReader::operator= ( const PcapReader & )
delete

References PcapReader().

◆ path()

const std::string & slick::sim::md_feed::PcapReader::path ( ) const
inlinenodiscard

Definition at line 300 of file pcap_reader.hpp.

Referenced by PcapReader().

◆ truncated()

uint64_t slick::sim::md_feed::PcapReader::truncated ( ) const
inlinenodiscardnoexcept

Frames skipped so far for being cut short or malformed - not those that are simply not UDP (IGMP, ARP, fragments of other protocols).

Definition at line 303 of file pcap_reader.hpp.


The documentation for this class was generated from the following file: