Esempio n. 1
0
void Message::validate( const ValidationRules* vrptr )
{
  /*
  try
  {
    */
    if ( !ValidationRules::shouldValidate( vrptr ) ) return;
    if ( ValidationRules::shouldValidateLength( vrptr ) )
    {
      const BodyLength& aBodyLength = FIELD_GET_REF( m_header, BodyLength );

      const int expectedLength = (int)aBodyLength;
      const int actualLength = bodyLength();

      if ( expectedLength != actualLength )
      {
        std::stringstream text;
        text << "Expected BodyLength=" << expectedLength
             << ", Received BodyLength=" << actualLength;
        throw InvalidMessage(text.str());
      }
    }

    if ( ValidationRules::shouldValidateChecksum( vrptr ) ) 
    {
      const CheckSum& aCheckSum = FIELD_GET_REF( m_trailer, CheckSum );

      const int expectedChecksum = (int)aCheckSum;
      const int actualChecksum = checkSum();

      if ( expectedChecksum != actualChecksum )
      {
        std::stringstream text;
        text << "Expected CheckSum=" << expectedChecksum
             << ", Received CheckSum=" << actualChecksum;
        throw InvalidMessage(text.str());
      }
    }
  /*
  }
  catch ( FieldNotFound& e )
  {
    const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
    throw InvalidMessage( fieldName + std::string(" is missing") );
  }
  catch ( IncorrectDataFormat& e )
  {
    const std::string fieldName = ( e.field == FIX::FIELD::BodyLength ) ? "BodyLength" : "CheckSum";
    throw InvalidMessage( fieldName + std::string(" has wrong format: ") + e.detail );
  }
  */
}
Esempio n. 2
0
std::string& Message::toString( std::string& str, 
                                int beginStringField,
                                int bodyLengthField, 
                                int checkSumField ) const
{
  int length = bodyLength( beginStringField, bodyLengthField, checkSumField );
  m_header.setField( IntField(bodyLengthField, length) );
  m_trailer.setField( CheckSumField(checkSumField, checkSum(checkSumField)) );

#if defined(_MSC_VER) && _MSC_VER < 1300
  str = "";
#else
  str.clear();
#endif

  /*small speculation about the space needed for FIX string*/
  str.reserve( length + 64 );

  m_header.calculateString( str );
  FieldMap::calculateString( str );
  m_trailer.calculateString( str );

  return str;
}
Esempio n. 3
0
                               int checkSumField ) const
{ QF_STACK_PUSH(Message::toString)

  std::string str;
  return toString( str, beginStringField, bodyLengthField, checkSumField );

  QF_STACK_POP
}

std::string& Message::toString( std::string& str, 
                                int beginStringField,
                                int bodyLengthField, 
                                int checkSumField ) const
{ QF_STACK_PUSH(Message::toString)

  int length = bodyLength( beginStringField, bodyLengthField, checkSumField );
  m_header.setField( IntField(bodyLengthField, length) );
  m_trailer.setField( CheckSumField(checkSumField, checkSum(checkSumField)) );

  m_header.calculateString( str, true );
  FieldMap::calculateString( str, false );
  m_trailer.calculateString( str, false );

  return str;

  QF_STACK_POP
}

std::string Message::toXML() const
{ QF_STACK_PUSH(Message::toXML)