itch-mold-replay 1.0
Time-accurate NASDAQ TotalView-ITCH 5.0 replay over MoldUDP64
Loading...
Searching...
No Matches
imr::mold::PacketBuilder Class Reference

Builds MoldUDP64 packets. More...

#include <packet_builder.h>

Classes

struct  Config
 

Public Member Functions

 PacketBuilder (const Config &cfg)
 
bool try_add (std::span< const char > message) noexcept
 Adds a message to the messge block.
 
std::span< iovec > finalize () noexcept
 Writes the message count to the header and returns header + message block as iovecs.
 
void reset (types::header::SequenceNumber seq=1) noexcept
 Writes sequence number for new packet to header and clears the message block.
 
types::header::MessageCount message_count () const noexcept
 Number of messages added since last reset().
 
std::string_view session () const noexcept
 Returns the configured MoldUDP64 session from header.
 

Static Public Attributes

static constexpr auto min_message_size {14}
 

Detailed Description

Builds MoldUDP64 packets.

Usage:

  1. Call reset() to write the sequence number to the header.
  2. Add messages with try_add() until all are added, or it returns false (packet full per the configured MTU).
  3. Call finalize() to write the message count to the header and get the completed packet as a span of iovecs

Constructor & Destructor Documentation

◆ PacketBuilder()

imr::mold::PacketBuilder::PacketBuilder ( const Config cfg)
explicit
Exceptions
std::invalid_argumentif cfg.session is not 10 characters
std::invalid_argumentif cfg.MTU less than the size of a MoldUDP64 header (20 bytes)

Member Function Documentation

◆ try_add()

bool imr::mold::PacketBuilder::try_add ( std::span< const char >  message)
noexcept

Adds a message to the messge block.

Returns
false without adding message if wouldn't fit under configured MTU.

◆ finalize()

std::span< iovec > imr::mold::PacketBuilder::finalize ( )
noexcept

Writes the message count to the header and returns header + message block as iovecs.

◆ reset()

void imr::mold::PacketBuilder::reset ( types::header::SequenceNumber  seq = 1)
noexcept

Writes sequence number for new packet to header and clears the message block.

◆ message_count()

types::header::MessageCount imr::mold::PacketBuilder::message_count ( ) const
noexcept

Number of messages added since last reset().

◆ session()

std::string_view imr::mold::PacketBuilder::session ( ) const
noexcept

Returns the configured MoldUDP64 session from header.

Member Data Documentation

◆ min_message_size

constexpr auto imr::mold::PacketBuilder::min_message_size {14}
staticconstexpr

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