00001 /* 00002 * (c) Onix Solutions. 00003 */ 00004 00005 #ifndef FAST_1_1_H 00006 #define FAST_1_1_H 00007 00008 #include "FIXEngineDefines.h" 00009 #include "EngineException.h" 00010 00011 #include <string> 00012 #include <vector> 00013 00014 namespace FIXForge{ 00015 namespace FIX{ 00016 class FF_API Message; 00017 00018 namespace FAST_1_1{ 00019 00020 /// Encodes FIX messages into FAST 1.1 representation. 00021 class FF_API Encoder{ 00022 public: 00023 /** 00024 * Constructor. Creates a FIX to FAST Encoder. 00025 * 00026 * @param xmlTemplates XML-based FAST 1.1 templates. 00027 * @param fixVersion FIX Protocol version. 00028 * @param encodeEachMessageIndependently Option to reset the previous values dictionaries before encoding a new FIX message. 00029 */ 00030 Encoder(const std::string& xmlTemplates, FIXForge::FIX::Version fixVersion, bool encodeEachMessageIndependently); 00031 00032 /// Destructor. 00033 ~Encoder(void); 00034 00035 /** 00036 * Encodes the given FIX message into a FAST 1.1 stream. 00037 * 00038 * @param fixMessage Source FIX message to be encoded. 00039 * @param templateID FAST Template Identifier which uniquely describes the encoding/decoding rules. 00040 * @param buffer Supplied buffer that will contain the FAST stream chunk. 00041 * @param bufferSize Size of the supplied buffer. 00042 * 00043 * @return the size of the encoded FAST stream chunk. 00044 */ 00045 size_t encode(const FIXForge::FIX::Message& fixMessage, int templateID, char* buffer, size_t bufferSize); 00046 00047 /** 00048 * Encodes the given FIX message into a FAST 1.1 stream using the default template ID. 00049 * 00050 * @param fixMessage Source FIX message to be encoded. 00051 * @param buffer Supplied buffer that will contain the FAST stream chunk. 00052 * @param bufferSize Size of the supplied buffer. 00053 * 00054 * @return the size of the encoded FAST stream chunk. 00055 */ 00056 size_t encode(const FIXForge::FIX::Message& fixMessage, char* buffer, size_t bufferSize); 00057 00058 /** 00059 * Resets the state of the previous values dictionaries (sets the state of the previous values to undefined). 00060 * 00061 * @see encodeEachMessageIndependently. 00062 */ 00063 void reset(); 00064 00065 private: 00066 Encoder(const Encoder&); 00067 Encoder& operator = (const Encoder&); 00068 00069 Encoder(void* native); 00070 00071 struct Impl; 00072 Impl* impl_; 00073 void* native_; 00074 }; 00075 00076 /// Performs FAST 1.1 to FIX decoding. 00077 class FF_API Decoder{ 00078 public: 00079 /** 00080 * Constructor. Creates a FAST 1.1 to FIX Decoder. 00081 * 00082 * @param xmlTemplates XML-based FAST 1.1 templates. 00083 * @param fixVersion FIX Protocol version. 00084 * @param decodeEachMessageIndependently Option to reset the previous values dictionaries before decoding a new FAST stream chunk. 00085 */ 00086 Decoder(const std::string& xmlTemplates, FIXForge::FIX::Version fixVersion, bool decodeEachMessageIndependently); 00087 00088 /// Destructor. 00089 ~Decoder(void); 00090 00091 /** 00092 * Decodes the given FAST 1.1 stream chunk into the corresponding FIX Message. 00093 * 00094 * @param buffer Buffer that contains the FAST stream chunk to be decoded. 00095 * @param bufferSize Size of the buffer. 00096 * 00097 * @throw EngineException if the message cannot be decoded. 00098 * 00099 * @return the decoded FIX message. 00100 */ 00101 const FIXForge::FIX::Message& decode(const char* buffer, size_t bufferSize); 00102 00103 /** 00104 * Decodes the given FAST 1.1 stream chunk into the corresponding FIX Message. 00105 * 00106 * @param chunk The FAST stream chunk to be decoded. 00107 * 00108 * @throw EngineException if the message cannot be decoded. 00109 * 00110 * @return the decoded FIX message. 00111 */ 00112 const FIXForge::FIX::Message& decode(const std::vector<char> & chunk); 00113 00114 00115 bool decode(const char* buffer, size_t offset, size_t count, const FIXForge::FIX::Message** message, size_t* chunkLengh); 00116 00117 /** 00118 * Decoded the FAST-encoded unsigned integer. 00119 * 00120 * @param buffer Buffer that contains the FAST stream chunk to be decoded. 00121 * @param bufferSize Size of the buffer. 00122 * @param value Decoded value. 00123 * @param fieldLength Number of bytes that contained the encoded value. 00124 * 00125 * @return 'true' if the stop bit was found and the value was decoded, otherwise - 'false'. 00126 */ 00127 static bool decodeUnsignedInteger(const char* buffer, size_t bufferSize, unsigned int* value, size_t* fieldLength); 00128 00129 /** 00130 * Resets the state of the previous values dictionaries (sets the state of the previous values to undefined). 00131 * 00132 * @see decodeEachMessageIndependently. 00133 */ 00134 void reset(); 00135 00136 private: 00137 Decoder(const Decoder&); 00138 Decoder& operator = (const Decoder&); 00139 00140 Decoder(void* native); 00141 00142 struct Impl; 00143 Impl* impl_; 00144 void* native_; 00145 }; 00146 00147 00148 00149 }}}; 00150 00151 #endif
1.5.2