OnixS C++ FIX Engine  4.12.0
API Documentation
Fix Dictionary Validator Sample

This sample demonstrates how to validate FIX messages from the summary log file by the given dictionary.

Source code:

#include "../../Common/Helpers.h"
#include "../../Common/Settings.h"
using namespace Settings;
namespace
{
int parseLogFile(const std::string & logFile, const DictionaryPtr & dialect);
};
int main(int argc, char * argv[])
{
std::clog << "FixDictionaryValidator Sample." << std::endl << std::endl;
try
{
if(argc < 2)
{
std::clog << "Usage: FixDictionaryValidator [FixLogFileToValidate.summary] (DialectFile) (DialectId)" << std::endl;
return 1;
}
EngineSettings settings;
settings.listenPort(-1)
.licenseStore(LicenseStore)
.validateRequiredFields(true)
.validateUnknownFields(true)
.validateUnknownMessages(true)
.validateRepeatingGroupEntryCount(true)
.validateRepeatingGroupLeadingTag(true)
.validateFieldValues(true);
if(argc > 2)
settings.dictionaryFile(argv[2]);
Engine::init(settings);
DictionaryPtr dictionary;
if(argc > 3)
dictionary.reset(new Dictionary(argv[3]));
std::clog << parseLogFile(argv[1], dictionary) << " messages are OK." << std::endl;
}
catch(const std::exception & ex)
{
processSampleException(ex.what());
return 1;
}
Engine::shutdown();
return 0;
}
namespace
{
int parseLogFile(const std::string & logFile, const DictionaryPtr & dictionary)
{
std::ifstream file(logFile.c_str());
if(!file)
throw std::runtime_error("Cannot open " + logFile + " log file.");
std::string line = "";
int lineCounter = 0;
while(std::getline(file, line))
{
++lineCounter;
if(line.empty())
continue;
const size_t StartOfFixMsgIndex = line.find("8=FIX");
if(std::string::npos == StartOfFixMsgIndex)
{
std::stringstream ss;
ss << lineCounter;
throw std::runtime_error("Cannot find the start of the FIX message (8=FIX) in line #" + ss.str() + " of " + logFile);
}
line = line.substr(StartOfFixMsgIndex);
try
{
Message message;
if(dictionary.get())
Message::parse(line.data(), line.size(), *dictionary, MessageParsingFlag::Strict, message);
else
Message::parse(line.data(), line.size(), MessageParsingFlag::Strict, message);
message.validate();
}
catch (...)
{
std::stringstream ss;
ss << lineCounter;
std::clog << "The validation issue is detected in the summary file at line #" + ss.str() << ":" << std::endl << std::endl << line << std::endl << std::endl;
throw;
}
}
return lineCounter;
}
};