/* * Copyright Onix Solutions Limited [OnixS]. All rights reserved. * * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law * and international copyright treaties. * * Access to and use of the software is governed by the terms of the applicable ONIXS Software * Services Agreement (the Agreement) and Customer end user license agreements granting * a non-assignable, non-transferable and non-exclusive license to use the software * for it's own data processing purposes under the terms defined in the Agreement. * * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part * of this source code or associated reference material to any other location for further reproduction * or redistribution, and any amendments to this copyright notice, are expressly prohibited. * * Any reproduction or redistribution for sale or hiring of the Software not in accordance with * the terms of the Agreement is a violation of copyright law. */ #if !defined(__ONIXS_EVENTBASEDDECODER_H__) #define __ONIXS_EVENTBASEDDECODER_H__ #include #include #include #include #include #include #include #include namespace OnixS { namespace FIX { ONIXS_FIXENGINE_API_DECL(class, Message); ONIXS_FIXENGINE_API_DECL(class, Dictionary); namespace FAST { /// Performs the FAST decoding using IDecodeListener to inform a user about the decoding process. class ONIXS_FIXENGINE_API EventBasedDecoder { public: /// Creates a FAST Decoder. /// /// @param xmlTemplates XML-based FAST templates. /// @param fixVersion The FIX Protocol version. /// @param decodeEachMessageIndependently The option to reset the previous /// values dictionaries before decoding a new FAST stream chunk. /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details. EventBasedDecoder(const std::string & xmlTemplates, ProtocolVersion::Enum fixVersion, bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits); /// Creates a FAST Decoder. /// /// @param xmlTemplates XML-based FAST templates. /// @param fixDictionary The customized FIX dictionary used for decoded messages /// @param decodeEachMessageIndependently The option to reset the previous /// values dictionaries before decoding a new FAST stream chunk. /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details. EventBasedDecoder(const std::string & xmlTemplates, const OnixS::FIX::Dictionary & fixDictionary, bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits); /// Creates a FAST to FIX Decoder for the FIX dictionary-independent mode. /// The generic FIX dictionary is created by the provided FAST-template content, it uses the FIX 4.0 as a base FIX dictionary and has a generic name. /// /// @param xmlTemplates XML-based FAST templates. /// @param decodeEachMessageIndependently The option to reset the previous /// values dictionaries before decoding a new FAST stream chunk. /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details. EventBasedDecoder(const std::string & xmlTemplates, bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits); /// Creates a FAST to FIX Decoder for the FIX dictionary-independent mode. /// The generic FIX dictionary is created by the provided FAST-template content, it uses the specified FIX dictionary as a base and has a generic name. /// /// @param baseVersion This version of the FIX protocol becomes the base for the newly generated FIX dictionary. /// @param xmlTemplates XML-based FAST templates to generate the FIX dictionary. This FIX dictionary takes a generic identifier generated on a base of the XML content and @c baseVersion /// @param decodeEachMessageIndependently The option to reset the previous /// values dictionaries before decoding a new FAST stream chunk. /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details. EventBasedDecoder(ProtocolVersion::Enum baseVersion, const std::string & xmlTemplates, bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits); /// Creates a FAST to FIX Decoder for the FIX dictionary-independent mode. /// The generic FIX dictionary is created by the provided FAST-template content, it uses the specified FIX dictionary as a base and has the specified name. /// @note The new FIX dictionary instance will be generated if and only if there is no a FIX dictionary with the same name. /// /// @param baseVersion This version of the FIX protocol becomes the base for the newly generated FIX dictionary. /// @param xmlTemplates XML-based FAST templates. /// @param genericFixDictionaryId The identifier which is applied to the generic FIX dictionary. This FIX dictionary is generated using @c xmlTemplates and @c baseVersion. /// @param decodeEachMessageIndependently The option to reset the previous /// values dictionaries before decoding a new FAST stream chunk. /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details. EventBasedDecoder(ProtocolVersion::Enum baseVersion, const std::string & xmlTemplates, const std::string & genericFixDictionaryId, bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits); /// The destructor. ~EventBasedDecoder(void); /// Input data traits of the decoder. /// @return Input data traits provided during the construction of the decoder. InputDataTraits::Enum inputDataTraits() const; /// Decodes the given FAST stream chunk. /// /// @param buffer The buffer that contains the FAST stream chunk to be decoded. /// @param bufferSize The size of the buffer. /// @param listener The listener which receives decoding events. /// @param usedSize The number of sequential bytes in the chunk which were recognized as FAST-encoded messages. /// /// @throw An exception if the message cannot be decoded. /// /// @return true if at least a single message was successfully decoded. bool decode(const char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize); // Deprecated bool decode(const unsigned char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize); /// Decodes the given FAST stream chunk. /// /// @param chunk The FAST stream chunk to be decoded. /// @param listener The listener which receives decoding events. /// @param usedSize The number of sequential bytes in the chunk which were recognized as FAST-encoded messages. /// /// @throw An exception if the message cannot be decoded. /// /// @return true if at least a single message was successfully decoded. bool decode(const std::vector & chunk, IDecodeListener * listener, size_t * usedSize); // Deprecated bool decode(const OnixS::Sockets::Bytes & chunk, IDecodeListener * listener, size_t * usedSize); /// Decodes the first message from the given FAST stream chunk. /// /// @param buffer The buffer that contains the FAST stream chunk to be decoded. /// @param bufferSize The size of the buffer. /// @param listener The listener which receives decoding events. /// @param usedSize The number of sequential bytes in the chunk which were recognized as a FAST-encoded message. /// /// @throw An exception if the message cannot be decoded. /// /// @return true if the message was successfully decoded. bool decodeSingleMessage(const char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize); // Deprecated bool decodeSingleMessage(const unsigned char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize); /// Decodes the first message from the given FAST stream chunk. /// /// @param chunk The FAST stream chunk to be decoded. /// @param listener The listener which receives decoding events. /// @param usedSize The number of sequential bytes in the chunk which were recognized as a FAST-encoded message. /// /// @throw An exception if the message cannot be decoded. /// /// @return true if the message was successfully decoded. bool decodeSingleMessage(const std::vector & chunk, IDecodeListener * listener, size_t * usedSize); // Deprecated bool decodeSingleMessage(const OnixS::Sockets::Bytes & chunk, IDecodeListener * listener, size_t * usedSize); /// Decodes the FAST-encoded unsigned integer. /// /// @param buffer The buffer that contains the FAST stream chunk to be decoded. /// @param bufferSize The size of the buffer. /// @param value The decoded value. /// @param fieldLength The number of bytes that contained the encoded value. /// /// @return 'true' if the stop bit was found and the value was decoded, otherwise - 'false'. static bool tryDecodeUnsignedInteger(const char * buffer, size_t bufferSize, unsigned int * value, size_t * fieldLength); // Deprecated static bool tryDecodeUnsignedInteger(const unsigned char * buffer, size_t bufferSize, unsigned int * value, size_t * fieldLength); /// Resets the state of the previous values dictionaries (sets the state of the previous values to undefined). /// /// @see decodeEachMessageIndependently. void reset(); /// The FIX dictionary used by the decoder instance. /// /// @return The FIX dictionary currently used by the decoder instance. If the decoder was initialized with the FIX dictionary-independent mode, the method returns /// a reference to the internally generated FIX dictionary. OnixS::FIX::Dictionary fixDictionary() const; private: friend ONIXS_FIXENGINE_API_DECL(class, OnixS::FIX::Dictionary); EventBasedDecoder(const EventBasedDecoder &); EventBasedDecoder & operator = (const EventBasedDecoder &); class Impl; Impl * impl_; }; } } } #endif // __ONIXS_EVENTBASEDDECODER_H__