Parser.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 ** Copyright (c) 2001-2014
3 **
4 ** This file is part of the QuickFIX FIX Engine
5 **
6 ** This file may be distributed under the terms of the quickfixengine.org
7 ** license as defined by quickfixengine.org and appearing in the file
8 ** LICENSE included in the packaging of this file.
9 **
10 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
11 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
12 **
13 ** See http://www.quickfixengine.org/LICENSE for licensing information.
14 **
15 ** Contact ask@quickfixengine.org if any conditions of this licensing are
16 ** not clear to you.
17 **
18 ****************************************************************************/
19 
20 #ifdef _MSC_VER
21 #include "stdafx.h"
22 #else
23 #include "config.h"
24 #endif
25 
26 #include "Parser.h"
27 #include "Utility.h"
28 #include "FieldConvertors.h"
29 #include <algorithm>
30 
31 namespace FIX
32 {
33 bool Parser::extractLength( int& length, std::string::size_type& pos,
34  const std::string& buffer )
35 throw( MessageParseError )
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 }
58 
59 bool Parser::readFixMessage( std::string& str )
60 throw( MessageParseError )
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 }
103 }
FIX::Parser::extractLength
bool extractLength(int &length, std::string::size_type &pos, const std::string &buffer)
Definition: Parser.cpp:50
FIX::FieldConvertError
Unable to convert field into its native format.
Definition: Exceptions.h:83
FIX::IntConvertor::convert
static std::string convert(signed_int value)
Definition: FieldConvertors.h:170
FieldConvertors.h
Parser.h
FIX
Definition: Acceptor.cpp:34
FIX::MessageParseError
Unable to parse message.
Definition: Exceptions.h:90
FIX::Parser::readFixMessage
bool readFixMessage(std::string &str)
Definition: Parser.cpp:76
Utility.h

Generated on Wed Apr 29 2020 19:41:30 for QuickFIX by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2001