Public Member Functions | Private Attributes
FIX::Parser Class Reference

Parses FIX messages off an input stream. More...

#include <Parser.h>

List of all members.

Public Member Functions

 Parser ()
 ~Parser ()
bool extractLength (int &length, std::string::size_type &pos, const std::string &buffer) throw ( MessageParseError )
bool readFixMessage (std::string &str) throw ( MessageParseError )
void addToStream (const char *str, size_t len)
void addToStream (const std::string &str)

Private Attributes

std::string m_buffer

Detailed Description

Parses FIX messages off an input stream.

Definition at line 36 of file Parser.h.


Constructor & Destructor Documentation

FIX::Parser::Parser ( ) [inline]

Definition at line 39 of file Parser.h.

{}
FIX::Parser::~Parser ( ) [inline]

Definition at line 40 of file Parser.h.

{}

Member Function Documentation

void FIX::Parser::addToStream ( const char *  str,
size_t  len 
) [inline]

Definition at line 48 of file Parser.h.

References m_buffer.

Referenced by FIX::ThreadedSocketConnection::read(), and FIX::SocketConnection::readFromSocket().

  { m_buffer.append( str, len ); }
void FIX::Parser::addToStream ( const std::string &  str) [inline]

Definition at line 50 of file Parser.h.

References m_buffer.

  { m_buffer.append( str ); }
bool FIX::Parser::extractLength ( int &  length,
std::string::size_type &  pos,
const std::string &  buffer 
) throw ( MessageParseError )

Definition at line 33 of file Parser.cpp.

References FIX::IntConvertor::convert().

{
  if( !buffer.size() ) return false;

  std::string::size_type startPos = buffer.find( "\0019=", 0 );
  if( startPos == std::string::npos ) return false;
  startPos += 3;
  std::string::size_type endPos = buffer.find( "\001", startPos );
  if( endPos == std::string::npos ) return false;

  std::string strLength( buffer, startPos, endPos - startPos );

  try
  {
    length = IntConvertor::convert( strLength );
    if( length < 0 ) throw MessageParseError();
  }
  catch( FieldConvertError& )
  { throw MessageParseError(); }

  pos = endPos + 1;
  return true;
}
bool FIX::Parser::readFixMessage ( std::string &  str) throw ( MessageParseError )

Definition at line 59 of file Parser.cpp.

Referenced by FIX::SocketConnection::readMessage().

{
  std::string::size_type pos = 0;

  if( m_buffer.length() < 2 ) return false;
  pos = m_buffer.find( "8=" );
  if( pos == std::string::npos ) return false;
  m_buffer.erase( 0, pos );

  int length = 0;

  try
  {
    if( extractLength(length, pos, m_buffer) )
    {
      pos += length;
      if( m_buffer.size() < pos )
        return false;

      pos = m_buffer.find( "\00110=", pos-1 );
      if( pos == std::string::npos ) return false;
      pos += 4;
      pos = m_buffer.find( "\001", pos );
      if( pos == std::string::npos ) return false;
      pos += 1;

      str.assign( m_buffer, 0, pos );
      m_buffer.erase( 0, pos );
      return true;
    }
  }
  catch( MessageParseError& e )
  {
    if( length > 0 )
      m_buffer.erase( 0, pos + length );
    else
      m_buffer.erase();

    throw e;
  }

  return false;
}

Member Data Documentation

std::string FIX::Parser::m_buffer [private]

Definition at line 54 of file Parser.h.

Referenced by addToStream().


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

Generated on Mon Jun 23 2014 23:49:39 for QuickFIX by doxygen 1.7.6.1 written by Dimitri van Heesch, © 1997-2001