00001 // $Id: decode_8c-example.html,v 1.2 2006/02/09 19:12:40 Daniel.May Exp $ 00002 // 00003 // FIX Adapted for STreaming (sm) (FAST Protocol (sm)) 00004 // 00005 // Copyright (c) 2005-2006, Pantor Engineering AB (http://www.pantor.com) 00006 // Copyright (c) 2005-2006, SpryWare LLC (http://www.spryware.com) 00007 // Copyright (c) 2005-2006, FIX Protocol Ltd (http://www.fixprotocol.org) 00008 // All Rights Reserved. 00009 // 00010 // This work is distributed under the W3CŪ Software License [1] in the 00011 // hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 00012 // implied warranty of MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS 00013 // FOR A PARTICULAR PURPOSE. 00014 // 00015 // [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231 00016 // [FPL's Intellectual Property details] http://www.fixprotocol.org/ip 00017 // [FAST Protocol details] http://www.fixprotocol.org/fast 00018 // [FAST Protocol credits] http://fixprotocol.org/fastcredits 00019 // 00020 // The example application 'decode' will decode a sample data feed from the FAST format back to it's original 00021 // format. The FAST data is read from stdin and decoded into original messages. Ouptut is written to stdout. 00022 // See the sample test scripts example.sh (Linux) or example.bat (Windows) for example usage. 00023 // 00024 00030 #include "fastapi.h" 00031 #include "common.h" 00032 00033 // define the template ID 00034 enum test_tids 00035 { 00036 TEST_BASE_TID = 0, 00037 }; 00038 00039 // define the fields 00040 enum test_fields 00041 { 00042 TID = MAKE_TAG (FAST_TYPE_U32, FAST_OP_COPY, TEST_BASE_TID, 0), 00043 SEQ_NUM = MAKE_TAG (FAST_TYPE_U32, FAST_OP_INCR, TEST_BASE_TID, 1), 00044 TIME = MAKE_TAG (FAST_TYPE_U32, FAST_OP_COPY, TEST_BASE_TID, 2), 00045 SYMBOL = MAKE_TAG (FAST_TYPE_STR, FAST_OP_COPY, TEST_BASE_TID, 3), 00046 PRICE = MAKE_TAG (FAST_TYPE_U32, FAST_OP_COPY, TEST_BASE_TID, 4), 00047 SHARES = MAKE_TAG (FAST_TYPE_U32, FAST_OP_COPY, TEST_BASE_TID, 5), 00048 EXCH = MAKE_TAG (FAST_TYPE_STR, FAST_OP_COPY, TEST_BASE_TID, 6), 00049 }; 00050 00051 00052 00053 int main(int argc, char* argv[]) 00054 { 00055 fast_codec_t *codec; 00056 u32 tid,seq_num,price,time,shares; 00057 char symbol[16],exch[2]; 00058 00059 // We want binary input from stdio and stdout 00060 init_platform_io(); 00061 00062 // Create the Codec 00063 codec = fast_create_codec (); 00064 assert(NULL!=codec); 00065 00066 // Decode the data 00067 fprintf(stdout,"; SeqNum, Time, Symbol,Price, Shares, Exch\r\n"); 00068 00069 // keep decoding while data is present 00070 while(fast_decode_new_msg (codec, TID) > 0) 00071 { 00072 fast_decode_u32 (codec, TID, &tid); 00073 assert(tid==1); 00074 // SeqNum is first 6 chars in input file, starting at pos 0 00075 fast_decode_u32 (codec, SEQ_NUM, &seq_num); 00076 // Time is next 6 chars in input file, starting at pos 7 00077 fast_decode_u32 (codec, TIME, &time); 00078 // Symbol is next 3 chars in input file, starting at pos 14 00079 fast_decode_str (codec, SYMBOL, symbol, 3); 00080 // Price is next 5 chars in input file, starting at pos 18 00081 fast_decode_u32 (codec, PRICE, &price); 00082 // Shares are next 3 chars in input file, starting at pos 24 00083 fast_decode_u32 (codec, SHARES, &shares); 00084 // Exchange is next char in input file, starting at pos 28 00085 fast_decode_str (codec, EXCH, exch,1); 00086 // we are done with this message 00087 if(fast_decode_end_msg (codec,0) != FAST_ERR_NONE) 00088 fast_print_error (codec, stderr); 00089 else 00090 fprintf(stdout,"%06d %06d %-3.3s %05d %03d %c\r\n",seq_num,time,symbol,price,shares,exch[0]); 00091 } 00092 00093 // clean up 00094 fast_destroy_codec (codec); 00095 return 0; 00096 }