Public Member Functions | Private Attributes | List of all members
FIX::Parser Class Reference

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

#include <Parser.h>

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

◆ Parser()

FIX::Parser::Parser ( )
inline

Definition at line 39 of file Parser.h.

39 {}

◆ ~Parser()

FIX::Parser::~Parser ( )
inline

Definition at line 40 of file Parser.h.

40 {}

Member Function Documentation

◆ addToStream() [1/2]

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

Definition at line 48 of file Parser.h.

49  { m_buffer.append( str, len ); }
std::string m_buffer
Definition: Parser.h:54

References m_buffer.

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

◆ addToStream() [2/2]

void FIX::Parser::addToStream ( const std::string &  str)
inline

Definition at line 50 of file Parser.h.

51  { m_buffer.append( str ); }

References m_buffer.

◆ extractLength()

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.

36 {
37  if( !buffer.size() ) return false;
38 
39  std::string::size_type startPos = buffer.find( "\0019=", 0 );
40  if( startPos == std::string::npos ) return false;
41  startPos += 3;
42  std::string::size_type endPos = buffer.find( "\001", startPos );
43  if( endPos == std::string::npos ) return false;
44 
45  std::string strLength( buffer, startPos, endPos - startPos );
46 
47  try
48  {
49  length = IntConvertor::convert( strLength );
50  if( length < 0 ) throw MessageParseError();
51  }
52  catch( FieldConvertError& )
53  { throw MessageParseError(); }
54 
55  pos = endPos + 1;
56  return true;
57 }
static std::string convert(signed_int value)

References FIX::IntConvertor::convert().

◆ readFixMessage()

bool FIX::Parser::readFixMessage ( std::string &  str)
throw (MessageParseError
)

Definition at line 59 of file Parser.cpp.

61 {
62  std::string::size_type pos = 0;
63 
64  if( m_buffer.length() < 2 ) return false;
65  pos = m_buffer.find( "8=" );
66  if( pos == std::string::npos ) return false;
67  m_buffer.erase( 0, pos );
68 
69  int length = 0;
70 
71  try
72  {
73  if( extractLength(length, pos, m_buffer) )
74  {
75  pos += length;
76  if( m_buffer.size() < pos )
77  return false;
78 
79  pos = m_buffer.find( "\00110=", pos-1 );
80  if( pos == std::string::npos ) return false;
81  pos += 4;
82  pos = m_buffer.find( "\001", pos );
83  if( pos == std::string::npos ) return false;
84  pos += 1;
85 
86  str.assign( m_buffer, 0, pos );
87  m_buffer.erase( 0, pos );
88  return true;
89  }
90  }
91  catch( MessageParseError& e )
92  {
93  if( length > 0 )
94  m_buffer.erase( 0, pos + length );
95  else
96  m_buffer.erase();
97 
98  throw e;
99  }
100 
101  return false;
102 }
bool extractLength(int &length, std::string::size_type &pos, const std::string &buffer)
Definition: Parser.cpp:33

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

Member Data Documentation

◆ m_buffer

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 Wed Nov 24 2021 09:55:53 for QuickFIX by doxygen 1.9.1 written by Dimitri van Heesch, © 1997-2001