ITCH 5.0 Market Data Handler 1.0.0
NASDAQ ITCH 5.0 Market Data Feed Handler
Loading...
Searching...
No Matches
b2bits::nasdaq::moldudp64::UDPPacket Class Reference

MoldUDP64 packet parser and message iterator. More...

Detailed Description

MoldUDP64 packet parser and message iterator.

Provides safe iteration over messages contained within a MoldUDP64 packet. The class validates packet boundaries and message lengths to prevent buffer overruns when parsing potentially malformed packets.

Each MoldUDP64 packet consists of:

  • PacketHeader (20 bytes): Session, sequence number, message count
  • Message blocks: Variable-length messages, each with 2-byte length prefix

Usage pattern:

  1. Construct with packet header pointer and total packet size
  2. Read header information (session, sequence, count)
  3. Call next() repeatedly to iterate through messages
  4. next() returns nullptr when all messages have been consumed
Note
Thread-safety: Not thread-safe. Each packet should be parsed by one thread.
The class does not own the packet data; caller must ensure lifetime.
Example:
// Parse a received UDP packet
auto* header = reinterpret_cast<const PacketHeader*>(udp_buffer);
UDPPacket packet(header, udp_size);
std::cout << "Session: " << packet.get_session()
<< " Seq: " << packet.get_sn()
<< " Count: " << packet.get_count() << "\n";
// Iterate through messages
while (auto* msg = packet.next()) {
// Process message (ITCH data follows MessageBlock header)
process_message(msg);
}
MoldUDP64 packet header.
Definition Messages.h:44
UDPPacket(const PacketHeader *header, std::size_t size)
Construct a packet parser.
Definition Packet.h:76

#include <nasdaq/moldudp64/Packet.h>

Public Member Functions

 UDPPacket (const PacketHeader *header, std::size_t size)
 Construct a packet parser.
const PacketHeaderget_header () const
 Get the packet header.
UInt16 get_count () const
 Get the message count in this packet.
UInt64 get_sn () const
 Get the first message sequence number.
StringRef get_session () const
 Get the session identifier.
const MessageBlocknext ()
 Get the next message in the packet.

Constructor & Destructor Documentation

◆ UDPPacket()

b2bits::nasdaq::moldudp64::UDPPacket::UDPPacket ( const PacketHeader * header,
std::size_t size )
inline

Construct a packet parser.

Initializes the packet parser with a pointer to the packet header and the total size of the received datagram. The constructor sets up internal pointers for safe message iteration.

Parameters
headerPointer to the PacketHeader at the start of the packet
sizeTotal size of the UDP datagram in bytes
Note
The header pointer must remain valid for the lifetime of this object
Size should be the actual received datagram size from recvfrom()

Member Function Documentation

◆ get_count()

UInt16 b2bits::nasdaq::moldudp64::UDPPacket::get_count ( ) const
inline

Get the message count in this packet.

Returns the number of messages contained in this packet, or EOS_COUNT (0xFFFF) if this is an end-of-session packet.

Returns
Message count, or EOS_COUNT for end-of-session

References b2bits::nasdaq::moldudp64::PacketHeader::get_count(), and get_header().

Referenced by next().

◆ get_header()

const PacketHeader * b2bits::nasdaq::moldudp64::UDPPacket::get_header ( ) const
inline

Get the packet header.

Returns
Const pointer to the PacketHeader

Referenced by get_count(), get_session(), and get_sn().

◆ get_session()

StringRef b2bits::nasdaq::moldudp64::UDPPacket::get_session ( ) const
inline

Get the session identifier.

Returns the session name for this packet, which identifies which MoldUDP64 stream this packet belongs to.

Returns
Session identifier as a StringRef (10 characters)

References get_header(), and b2bits::nasdaq::moldudp64::PacketHeader::get_session().

◆ get_sn()

UInt64 b2bits::nasdaq::moldudp64::UDPPacket::get_sn ( ) const
inline

Get the first message sequence number.

Returns the sequence number of the first message in this packet. Subsequent messages have sequential sequence numbers (sn+1, sn+2, ...).

Returns
First message sequence number in host byte order

References get_header(), and b2bits::nasdaq::moldudp64::PacketHeader::get_sequence_number().

◆ next()

const MessageBlock * b2bits::nasdaq::moldudp64::UDPPacket::next ( )
inline

Get the next message in the packet.

Advances the internal iterator to the next message and returns a pointer to its MessageBlock header. The actual message payload (e.g., ITCH data) follows the MessageBlock header.

This method performs bounds checking and will throw if a message length would exceed the packet boundary, indicating a malformed packet.

Returns
Pointer to the next MessageBlock, or nullptr if all messages consumed
Exceptions
std::runtime_errorif message length exceeds packet boundary
Note
Call this method repeatedly until it returns nullptr
The returned pointer is only valid until the next call to next()

References get_count(), and next().

Referenced by next().


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