High Frequency FIX Parser
C++ library for high frequency messaging with the Financial Information Exchange (FIX) protocol.
Public Types | Public Member Functions | List of all members
hffix::message_reader Class Reference

One FIX message for reading. More...

#include <hffix.hpp>

Public Types

typedef field value_type
 
typedef field const & const_reference
 
typedef message_reader_const_iterator const_iterator
 
typedef field const * const_pointer
 
typedef size_t size_type
 

Public Member Functions

 message_reader (char const *buffer, size_t size)
 Construct by buffer size.
 
 message_reader (char const *begin, char const *end)
 Construct by buffer begin and end.
 
 message_reader (message_reader const &that)
 Copy constructor. The hffix::message_reader is immutable, so copying it is fine.
 
message_readeroperator= (const message_reader &that)
 Copy assignment operator. The hffix::message_reader is immutable, so copying it is fine.
 
 message_reader (message_writer const &that)
 Construct a message_reader from a message_writer. Equivalent to.
 
template<size_t N>
 message_reader (const char(&buffer)[N])
 Construct on an array reference to a buffer.
 
 ~message_reader ()
 Owns no resources, so destruction is no-op.
 
bool is_complete () const
 True if the buffer contains a complete FIX message.
 
bool is_valid () const
 True if the message is valid.
 
message_reader next_message_reader () const
 Returns a new message_reader for the next FIX message in the buffer.
 
unsigned char calculate_check_sum ()
 Calulate the checksum for this message.
 
Field Access
const_iterator begin () const
 An iterator to the MsgType field in the FIX message. Same as hffix::message_reader::message_type().
 
const_iterator end () const
 An iterator to the CheckSum field in the FIX message. Same as hffix::message_reader::check_sum().
 
const_iterator message_type () const
 An iterator to the MsgType field in the FIX message. Same as hffix::message_reader::begin().
 
const_iterator check_sum () const
 An iterator to the CheckSum field in the FIX message. Same as hffix::message_reader::end().
 
char const * prefix_begin () const
 Returns the FIX version prefix BeginString field value begin pointer. (Example: "FIX.4.4")
 
char const * prefix_end () const
 Returns the FIX version prefix BeginString field value end pointer.
 
size_t prefix_size () const
 Returns the FIX version prefix BeginString field value size. (Example: returns 7 for "FIX.4.4")
 
bool find_with_hint (int tag, const_iterator &i) const
 Convenient synonym for hffix::find_with_hint(reader.begin(), reader.end(), hffix::tag_equal(tag), i).
 

Buffer Access

char const * buffer_begin () const
 A pointer to the begining of the buffer.
 
char const * buffer_end () const
 A pointer to past-the-end of the buffer.
 
size_t buffer_size () const
 The size of the buffer in bytes.
 
char const * message_begin () const
 A pointer to the beginning of the FIX message in the buffer.
 
char const * message_end () const
 A pointer to past-the-end of the FIX message in the buffer.
 
size_t message_size () const
 The entire size of the FIX message in bytes.
 

Detailed Description

One FIX message for reading.

An immutable Forward Container of FIX fields. Given a buffer containing a FIX message, the hffix::message_reader will provide an Iterator for iterating over the fields in the message without modifying the buffer. The buffer used to construct the hffix::message_reader must outlive the hffix::message_reader.

During construction, hffix::message_reader checks to make sure there is a complete, valid FIX message in the buffer. It looks only at the header and trailer transport fields in the message, not at the content fields, so construction is O(1).

If hffix::message_reader is complete and valid after construction, hffix::message_reader::begin() returns an iterator that points to the MsgType field in the FIX Standard Message Header, and hffix::message_reader::end() returns an iterator that points to the CheckSum field in the FIX Standard Message Trailer.

The hffix::message_reader will only iterate over content fields of the message, and will skip over all of the framing transport fields that are mixed in with the content fields in FIX. Here is the list of skipped fields which will not appear when iterating over the fields of the message:

Fields of binary data type are content fields, and will be iterated over like any other field. The special FIX binary data length framing fields will be skipped, but the length of the binary data is accessible from the hffix::message_reader::value_type::value().size() of the content field.

Definition at line 2396 of file hffix.hpp.

Member Typedef Documentation

◆ const_iterator

Definition at line 2402 of file hffix.hpp.

◆ const_pointer

typedef field const* hffix::message_reader::const_pointer

Definition at line 2403 of file hffix.hpp.

◆ const_reference

typedef field const& hffix::message_reader::const_reference

Definition at line 2401 of file hffix.hpp.

◆ size_type

typedef size_t hffix::message_reader::size_type

Definition at line 2404 of file hffix.hpp.

◆ value_type

Definition at line 2400 of file hffix.hpp.

Constructor & Destructor Documentation

◆ message_reader() [1/5]

hffix::message_reader::message_reader ( char const *  buffer,
size_t  size 
)
inline

Construct by buffer size.

Parameters
bufferPointer to the buffer to be read.
sizeNumber of bytes in the buffer to be read.

Definition at line 2411 of file hffix.hpp.

◆ message_reader() [2/5]

hffix::message_reader::message_reader ( char const *  begin,
char const *  end 
)
inline

Construct by buffer begin and end.

Parameters
beginPointer to the buffer to be read.
endPointer to past-the-end of the buffer to be read.

Definition at line 2426 of file hffix.hpp.

◆ message_reader() [3/5]

hffix::message_reader::message_reader ( message_reader const &  that)
inline

Copy constructor. The hffix::message_reader is immutable, so copying it is fine.

Definition at line 2439 of file hffix.hpp.

◆ message_reader() [4/5]

hffix::message_reader::message_reader ( message_writer const &  that)
inline

Construct a message_reader from a message_writer. Equivalent to.

One FIX message for reading.
Definition hffix.hpp:2396
One FIX message for writing.
Definition hffix.hpp:622
char * message_end() const
Pointer to past-the-end of the message.
Definition hffix.hpp:693
char * message_begin() const
Pointer to beginning of the message.
Definition hffix.hpp:685

Definition at line 2473 of file hffix.hpp.

◆ message_reader() [5/5]

template<size_t N>
hffix::message_reader::message_reader ( const char(&)  buffer[N])
inline

Construct on an array reference to a buffer.

Template Parameters
NThe size of the array.
Parameters
bufferAn array reference. The reader will read from the entire array of length N.

Definition at line 2489 of file hffix.hpp.

◆ ~message_reader()

hffix::message_reader::~message_reader ( )
inline

Owns no resources, so destruction is no-op.

Definition at line 2502 of file hffix.hpp.

Member Function Documentation

◆ begin()

const_iterator hffix::message_reader::begin ( ) const
inline

An iterator to the MsgType field in the FIX message. Same as hffix::message_reader::message_type().

Exceptions
std::logic_errorif called on an invalid message. This exception is preventable by program logic. You should always check if a message is_valid() before reading.

Definition at line 2593 of file hffix.hpp.

◆ buffer_begin()

char const * hffix::message_reader::buffer_begin ( ) const
inline

A pointer to the begining of the buffer.

buffer_begin() == message_begin()

Definition at line 2684 of file hffix.hpp.

◆ buffer_end()

char const * hffix::message_reader::buffer_end ( ) const
inline

A pointer to past-the-end of the buffer.

Definition at line 2690 of file hffix.hpp.

◆ buffer_size()

size_t hffix::message_reader::buffer_size ( ) const
inline

The size of the buffer in bytes.

Definition at line 2697 of file hffix.hpp.

◆ calculate_check_sum()

unsigned char hffix::message_reader::calculate_check_sum ( )
inline

Calulate the checksum for this message.

Note that the hffix library never does this calculation implicitly for messages read. For checksum calculation this function must be explicitly called.

The only thing to do after calculating the checksum for this message is to compare it to the CheckSum field that the message reports for itself, like so:

if (r.calculate_check_sum() == r.check_sum()->value()as_int<unsigned char>()) {}
field_value const & value() const
Weakly-typed value of the field.
Definition hffix.hpp:2159
unsigned char calculate_check_sum()
Calulate the checksum for this message.
Definition hffix.hpp:2581
const_iterator check_sum() const
An iterator to the CheckSum field in the FIX message. Same as hffix::message_reader::end().
Definition hffix.hpp:2623
Returns
The calculated checksum.
Exceptions
std::logic_errorif called on an invalid message. Check for is_valid() before calling.

Definition at line 2581 of file hffix.hpp.

◆ check_sum()

const_iterator hffix::message_reader::check_sum ( ) const
inline

An iterator to the CheckSum field in the FIX message. Same as hffix::message_reader::end().

Exceptions
std::logic_errorif called on an invalid message. This exception is preventable by program logic. You should always check if a message is_valid() before reading.

Definition at line 2623 of file hffix.hpp.

◆ end()

const_iterator hffix::message_reader::end ( ) const
inline

An iterator to the CheckSum field in the FIX message. Same as hffix::message_reader::check_sum().

Exceptions
std::logic_errorif called on an invalid message. This exception is preventable by program logic. You should always check if a message is_valid() before reading.

Definition at line 2603 of file hffix.hpp.

◆ find_with_hint()

bool hffix::message_reader::find_with_hint ( int  tag,
const_iterator i 
) const
inline

Convenient synonym for hffix::find_with_hint(reader.begin(), reader.end(), hffix::tag_equal(tag), i).

Similar to std::find_if. See hffix::find_with_hint for details.

Parameters
tagThe field tag number to find.
iIf a field is found which has the tag number tag, then i is modified to point to the found item. Else i is unmodified.
Returns
True if a field was found, and i was modified to point to the found field.

Example usage:

if (reader.find_with_hint(MsgSeqNum, i))
int seqnum = i++->as_int<int>();
if (reader.find_with_hint(TargetCompID, i))
std::string targetcompid = i++->as_string();
The iterator type for hffix::message_reader. Typedef'd as hffix::message_reader::const_iterator.
Definition hffix.hpp:2181

Definition at line 2670 of file hffix.hpp.

◆ is_complete()

bool hffix::message_reader::is_complete ( ) const
inline

True if the buffer contains a complete FIX message.

Definition at line 2508 of file hffix.hpp.

◆ is_valid()

bool hffix::message_reader::is_valid ( ) const
inline

True if the message is valid.

A valid message must meet these criteria.

  • The first field is BeginString.
  • The next field is BodyLength, and there is a CheckSum field at the end of the message at the location dictated by BodyLength.
  • After BodyLength there is a MsgType field.

If false, the message is unintelligable, and the length of the message is unknown.

fix-42_with_errata_20010501.pdf p.17: "Valid FIX Message is a message that is properly formed according to this specification and contains a valid body length and checksum field"

Definition at line 2526 of file hffix.hpp.

◆ message_begin()

char const * hffix::message_reader::message_begin ( ) const
inline

A pointer to the beginning of the FIX message in the buffer.

buffer_begin() == message_begin()

Exceptions
std::logic_errorif called on an invalid message. This exception is preventable by program logic. You should always check if a message is_valid() before reading.

Definition at line 2708 of file hffix.hpp.

◆ message_end()

char const * hffix::message_reader::message_end ( ) const
inline

A pointer to past-the-end of the FIX message in the buffer.

Exceptions
std::logic_errorif called on an invalid message. This exception is preventable by program logic. You should always check if a message is_valid() before reading.

Definition at line 2715 of file hffix.hpp.

◆ message_size()

size_t hffix::message_reader::message_size ( ) const
inline

The entire size of the FIX message in bytes.

Exceptions
std::logic_errorif called on an invalid message. This exception is preventable by program logic. You should always check if a message is_valid() before reading.

Definition at line 2724 of file hffix.hpp.

◆ message_type()

const_iterator hffix::message_reader::message_type ( ) const
inline

An iterator to the MsgType field in the FIX message. Same as hffix::message_reader::begin().

Exceptions
std::logic_errorif called on an invalid message. This exception is preventable by program logic. You should always check if a message is_valid() before reading.

Definition at line 2613 of file hffix.hpp.

◆ next_message_reader()

message_reader hffix::message_reader::next_message_reader ( ) const
inline

Returns a new message_reader for the next FIX message in the buffer.

If this message is_valid() and is_complete(), assume that the next message comes immediately after this one and return a new message_reader constructed at this->message_end().

If this message !is_valid(), will search the remainder of the buffer for the text "8=FIX", to see if there might be a complete or partial valid message anywhere else in the remainder of the buffer, will return a new message_reader constructed at that location.

Exceptions
std::logic_errorIf this message !is_complete().

Definition at line 2543 of file hffix.hpp.

◆ operator=()

message_reader & hffix::message_reader::operator= ( const message_reader that)
inline

Copy assignment operator. The hffix::message_reader is immutable, so copying it is fine.

Definition at line 2452 of file hffix.hpp.

◆ prefix_begin()

char const * hffix::message_reader::prefix_begin ( ) const
inline

Returns the FIX version prefix BeginString field value begin pointer. (Example: "FIX.4.4")

Definition at line 2632 of file hffix.hpp.

◆ prefix_end()

char const * hffix::message_reader::prefix_end ( ) const
inline

Returns the FIX version prefix BeginString field value end pointer.

Definition at line 2639 of file hffix.hpp.

◆ prefix_size()

size_t hffix::message_reader::prefix_size ( ) const
inline

Returns the FIX version prefix BeginString field value size. (Example: returns 7 for "FIX.4.4")

Definition at line 2646 of file hffix.hpp.


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