Compile the quickfast resolution Library (Shenzhen and Shenzhen level2 quote transcoding Library)

Source: Internet
Author: User
Compile the link to the level2 quote Transcoder.

Download the quickfast Project (Windows ):

Http://quickfast.googlecode.com/files/quickfast_win_src_1_4.zip

Download third-party libraries:

1. Download ActivePerl

(Google it)

2. Download the MPC

Http://www.ociweb.com/products/mpc

3. Download boost

(Google it)

4. Download xerces

Http://xerces.apache.org/xerces-c/

Download the configuration script setup. bat for the quote transcoding Library (Save the GIF file as zip and decompress it to get the bat file)

Http://hi.csdn.net/attachment/201112/13/0_1323743665laAL.gif

Setup. Bat configure scripts to set third-party library paths and compiler options

@REM 1) Customize this file by setting variables to suit your environment@REM 2) Also you should customize QuickFAST.features to enable particular features on your system.@REM 3) Delete the following line when you finishing customizing this file.@REM           [==DELETED==]echo See remarks in %0 for information about setting your build environment@REM 4) And, then run the `m.cmd' to generate *.sln & *.vcproj files@echo offREM =====================================================================================REM EDIT THE FOLLOWING LINES OR SET THESE VALUES IN YOUR ENVIRONMENT BEFORE RUNNING SETUPif "a" == "a%MPC_ROOT%" set MPC_ROOT=H:\workspace\qf\MPCif "a" == "a%XERCES_ROOT%" set XERCES_ROOT=H:\workspace\qf\xerces-c-3.1.1-x86-windows-vc-8.0if "a" == "a%XERCES_LIBNAME%" set XERCES_LIBNAME=xerces-c_3if "a" == "a%BOOST_VERSION%" set BOOST_VERSION=boost_1_47_0if "a" == "a%BOOST_ROOT%" set BOOST_ROOT=H:\workspace\qf\%BOOST_VERSION%REM END OF VALUES TO BE SETREM =====================================================================================

Note: by default, the include and Lib compiled by boost are not in the same directory. You need to move them.

RunSetup. BAT & M. batYou can generate quickfast. sln.

UseVs2008OpenQuickfast. slnCompile the connection. The generated file is in the corresponding configuration folder of the output directory.

After obtaining the database, how can I use it?

This solution provides many examples. The simplest examples are tutorialapplication and interpretapplication.

You can also use doxygen to generate documents.

Http://hi.csdn.net/attachment/201112/26/0_1324861393eteG.gif

A simple example

The author uses codecs: synchronousdecoder (synchronous decoding, the official example uses asynchronous decoder) to implement a simple decoding encapsulation,

Use TCP socket to obtain and decode the fast code stream from the upstream data source,

The fast code stream is the content encoded with fast after the step protocol header is removed.

Fast_steam=Fast(Step_packet-step_head) =Fast(Step_body)

Fastdecoder. H is the header file for export

#ifdef __cplusplusextern "C"{#endifenum MarketTag{    ShenzhenMarket = 0,    ShanghaiMarket = 1,};FASTDECODER_API int RunDecoderLoop(const char * pIp               , unsigned short nPort               , MarketTag nMarketTag               , const char * templateFileName               , const struct IDataExInterface * pNotify               );#ifdef __cplusplus};#endif

The decoded data is notified to the client to update the data through the pnotify interface in the interface.

Testfastdecoder. cpp File

Struct idataexinterface {void (_ stdcall * pfnfeedstatus) (connectionstatus connstatus); // Shanghai updated interface void (_ stdcall * handle) (const shfast30_ua3202_t *); void (_ stdcall * handle) (const shfast30_ua3201_t *); void (_ stdcall * pfnfeed_shfast30_ua3113) (const shfast30_ua3113_t *); // Shenzhen update interface void (_ stdcall * pfnfeed_szfast_103) (const szfast_103_t *); void (_ stdcall * pfnfeed_szfast_202) (const szfast_202_t *); void (_ stdcall * pfnfeed_szfast_201) (const szfast_201_t *); void (_ stdcall * pfnfeed_szfast_104) (const szfast_104_t *);};

The client can call

Void level2thread (void * Arg) {markettag nmarkettag = static_cast <markettag> (INT) Arg); idataexinterface * pnotify = new idataexinterface; memset (pnotify, 0, sizeof (idataexinterface); pnotify-> pfnfeedstatus = feedstatus; Switch (nmarkettag) {Case shenzhenmarket: {setthreadaffinitymask (getcurrentthread (), 1); pnotify-> response = response; PY y-> token = token; pnotify-> token = feed_szfast_201; pnotify-> token = feed_szfast_202; rundecoderloop ("127.0.0.1", 1111, markettag (shenzhenmarket ),". \ fasttemplates_2.00.xml ", pnotify);} break; Case shanghaimarket: {setthreadaffinitymask (getcurrentthread (), 2); pnotify-> Signature = signature; pnotify-> pfnfeed_shfast30_ua3202 = feed_shfast30_ua3202; rundecoderloop ("127.0.0.1", 2222, markettag (shanghaimarket ),". \ template.2.03.xml ", pnotify);} break;} return ;} /***** simply enable two decoding threads in the market to start decoding * The export function rundecoderloop is a loop process * so it is placed in two independent threads ***/INT main (int argc, char * argv []) {_ beginthread (level2thread, 0, (void *) shanghaimarket); _ beginthread (level2thread, 0, (void *) shenzhenmarket ); // level2thread (void *) shenzhenmarket); // level2thread (void *) shanghaimarket); printf ("press any key to quit decoder. \ n "); getchar (); Return 0 ;}

Update the client to read the configuration information from the configuration file testfastdecoder. ini.

[Shanghai]IpAddr=127.0.0.1Port=8888Template=template.2.03.xml[Shenzhen]IpAddr=127.0.0.1Port=5555Template=fasttemplates_2.00.xml

New level2thread

void Level2Thread(void * arg){    char szProfile  [MAX_PATH]  = "";    char szAppName  [MAX_PATH]  = "";    char szIpAddr   [MAX_PATH]  = "";    char szTemplate [MAX_PATH]  = "";    unsigned short wPort = 0;    MarketTag nMarketTag = static_cast<MarketTag>((int)arg);    IDataExInterface * pNotify = new IDataExInterface;    memset(pNotify, 0, sizeof(IDataExInterface));    pNotify->pfnFeedStatus              = FeedStatus;    pNotify->pfnFeed_SZFAST_103         = Feed_SZFAST_103;    pNotify->pfnFeed_SZFAST_104         = Feed_SZFAST_104;    pNotify->pfnFeed_SZFAST_201         = Feed_SZFAST_201;    pNotify->pfnFeed_SZFAST_202         = Feed_SZFAST_202;    pNotify->pfnFeed_SHFAST30_UA3113    = Feed_SHFAST30_UA3113;    pNotify->pfnFeed_SHFAST30_UA3201    = Feed_SHFAST30_UA3201;    pNotify->pfnFeed_SHFAST30_UA3202    = Feed_SHFAST30_UA3202;    SetThreadAffinityMask(GetCurrentThread()                         , (nMarketTag == ShenzhenMarket) ? 0 : 1);    GetModuleFileNameA(GetModuleHandleA(NULL), szProfile, _countof(szProfile)-sizeof(szProfile[0]));    strrchr(szProfile, '\\')[1] = 0;    strcat_s(szProfile, _countof(szProfile), "TestFastDecoder.ini");    strcpy_s(szAppName        , _countof(szAppName) - sizeof(szAppName[0])        , (nMarketTag == ShenzhenMarket) ? "Shenzhen" : "Shanghai");    GetPrivateProfileStringA(szAppName        , "IpAddr"        , NULL        , szIpAddr        , _countof(szIpAddr)-sizeof(szIpAddr[0])        , szProfile);    wPort = GetPrivateProfileIntA(szAppName        , "Port"        , 0        , szProfile);    GetPrivateProfileStringA(szAppName        , "Template"        , NULL        , szTemplate        , _countof(szTemplate)-sizeof(szTemplate[0])        , szProfile);    RunDecoderLoop(            szIpAddr            , wPort            , nMarketTag            , szTemplate            // , nMarketTag == ShenzhenMarket             // ? ".\\fasttemplates_2.00.xml"            // : ".\\template.2.03.xml"            , pNotify);    //std::cout<<szIpAddr<<wPort<<szTemplate<<nMarketTag<<std::endl;    return ;}

Several important steps for decoding fast with codecs: synchronousdecoder

1. Construct an XML parsing object

/*************************************** * *********************************** Global XML parsing class ** note: multiple Threads simultaneously construct parser, causing resource conflicts ********************************* **************************************** */static codecs:: xmltemplateparser parser;

2. parse the XML template to generate the fast template.
 

/////////////////////////////////////////////// Parse the templates from the template file// errors are reported by throwing exceptions// which are caught below.std::ifstream tmplFile(templateFileName, openMode);Codecs::TemplateRegistryPtr registry;try {   registry = parser.parse(tmplFile);}catch (std::exception & e){   std::cerr << e.what() << std::endl;   return -1;}

3. Create a decoder object
 

//////////////////////////////////////// Create a sync decoder and// setup attributes.Codecs::SynchronousDecoder * pDecoder     = new Codecs::SynchronousDecoder(registry);pDecoder->setHeaderBytes(0);pDecoder->setResetOnMessage(false);pDecoder->setLimit(0);

4. Implement a message consumer and register it with the decoder.

//////////////////////////////////////// Create an application object to use// the incoming data.  In this case to// accept complete messages and interpret// them to standard out.CMessageConsumerImpl * pHandler     = new CMessageConsumerImpl(nMarketTag                               , pNotify                               , pDecoder);//////////////////////////////////////// and use the interpreter as the consumer// of generic messages.Codecs::GenericMessageBuilder builder(*pHandler);

5. Receive network data packets (placed in pfastbody, length bit nbodylength) and start decoding.

pDataSource = new Codecs::DataSourceBuffer(pFastBody , pFastHeader->nBodyLength);

try{  pDecoder->reset();  pDecoder->decode(*pDataSource, builder);} catch (std::exception & e){  std::cout<<e.what()<<std::endl;}delete pDataSource;pDataSource = NULL;

6. Implement the message consumer Interface

/// @brief A message consumer that attempts to produce a human readable version/// of a message that has been decoded by QuickFAST.class CMessageConsumerImpl : public Codecs::MessageConsumer

Rewrite the message Consumption Function

virtual bool consumeMessage(Messages::Message & message);

7. The message consumption process is the message formatting process.

In the message formatting process, it mainly involves traversing each filed of the message. If the field is

General type, directly converted to the corresponding value; if it is sequence and group, you need

Field is converted to sequence and group and traversed. In addition

Item is also a message structure, so every member of the structure needs to be traversed in message mode;

foreach(item in seq)      foreach(member in item)

======================================

8. To be continued

Fast manual decoding, refer to spec

======================================

Output:

========================================================== ======================================

Download the project source file (Save the following GIF link as ZIP, decompress it-> rename-> decompress it, and encrypt it. If you need it, please leave a message for it)

Latest Version

Version 2.0 modified the Japanese style and configuration file quickfast-v2-1098n0).zip.png

Http://hi.csdn.net/attachment/201112/27/0_132498087296Py.gif

Previous versions

Version 1.0, project source file examples-8n0.zip

Http://hi.csdn.net/attachment/201112/26/0_132486187064m4.gif

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.