forked from objectcomputing/mFAST
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Vladimir Karnushin
committed
Dec 26, 2016
1 parent
353e7c9
commit b7f19c8
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
add_subdirectory (performance_test) | ||
add_subdirectory (message_printer) | ||
add_subdirectory (hello_world) | ||
# add_subdirectory (Model) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
######################################################################### | ||
# The following lines shows how to write CMakeLists.txt for mFAST applications | ||
# when the applications are not in the mFAST source tree. | ||
########################################################################## | ||
|
||
# cmake_minimum_required(VERSION 2.8) | ||
# find_package(mFAST REQUIRED COMPONENTS coder) | ||
# | ||
# include_directories(${MFAST_INCLUDE_DIR}) | ||
# link_directories(${MFAST_LIBRARY_DIRS}) | ||
|
||
add_executable (hello_world hello_world.cpp) | ||
target_link_libraries (hello_world ${MFAST_LIBRARIES}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
#include <iostream> | ||
#include <string> | ||
|
||
#include <mfast.h> | ||
#include <mfast/coder/fast_decoder.h> | ||
#include <mfast/json/json.h> | ||
#include <mfast/xml_parser/dynamic_templates_description.h> | ||
|
||
using std::string; | ||
using std::ostringstream; | ||
using std::cout; | ||
using std::endl; | ||
|
||
using mfast::templates_description; | ||
using mfast::dynamic_templates_description; | ||
using mfast::fast_decoder; | ||
using mfast::message_cref; | ||
using mfast::ascii_string_cref; | ||
using mfast::json::encode; | ||
|
||
// example from http://jettekfix.com/node/36 | ||
static const string fast_template = | ||
"\ | ||
<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\ | ||
<templates xmlns=\"http://www.fixprotocol.org/ns/fast/td/1.1\">\ | ||
<template dictionary=\"1\" id=\"1\" name=\"HelloWorld\">\ | ||
<string id=\"58\" name=\"Text\">\ | ||
<default value=\"\"></default>\ | ||
</string>\ | ||
</template>\ | ||
</templates>\ | ||
"; | ||
|
||
// 58=HelloWorld<SOH> | ||
static const string fast_message = | ||
"\xE0\x81\x48\x65\x6C\x6C\x6F\x57\x6F\x72\x6C\xE4"; | ||
|
||
int main() { | ||
dynamic_templates_description description(fast_template); | ||
|
||
const templates_description* descriptions[] = {&description}; | ||
|
||
fast_decoder decoder; | ||
decoder.include(descriptions); | ||
|
||
const char* start = fast_message.c_str(); | ||
const char* end = start + fast_message.length(); | ||
|
||
cout << "Decoding message \"58=HelloWorld<SOH>\":" << endl; | ||
cout << endl; | ||
|
||
message_cref msg = decoder.decode(start, end); | ||
|
||
cout << "Template id: " << msg.id() << endl; | ||
cout << "Template name: " << msg.name() << endl; | ||
cout << endl; | ||
|
||
ascii_string_cref field = static_cast<ascii_string_cref>((msg)[0]); | ||
|
||
cout << "Field id: " << field.id() << endl; | ||
cout << "Field name: " << field.name() << endl; | ||
cout << "Field content: " << field.c_str() << endl; | ||
cout << endl; | ||
|
||
cout << "Encoding message to JSON:" << endl; | ||
|
||
ostringstream json_message; | ||
bool result = encode(json_message, msg, 0); | ||
if (result) cout << "Success: " << json_message.str() << endl; | ||
|
||
return 0; | ||
} |