OnixS C++ FIX Engine  4.12.0
API Documentation
EventBasedDecoder.h
Go to the documentation of this file.
1 /*
2 * Copyright Onix Solutions Limited [OnixS]. All rights reserved.
3 *
4 * This software owned by Onix Solutions Limited [OnixS] and is protected by copyright law
5 * and international copyright treaties.
6 *
7 * Access to and use of the software is governed by the terms of the applicable ONIXS Software
8 * Services Agreement (the Agreement) and Customer end user license agreements granting
9 * a non-assignable, non-transferable and non-exclusive license to use the software
10 * for it's own data processing purposes under the terms defined in the Agreement.
11 *
12 * Except as otherwise granted within the terms of the Agreement, copying or reproduction of any part
13 * of this source code or associated reference material to any other location for further reproduction
14 * or redistribution, and any amendments to this copyright notice, are expressly prohibited.
15 *
16 * Any reproduction or redistribution for sale or hiring of the Software not in accordance with
17 * the terms of the Agreement is a violation of copyright law.
18 */
19 
20 #if !defined(__ONIXS_EVENTBASEDDECODER_H__)
21 #define __ONIXS_EVENTBASEDDECODER_H__
22 
23 #include <string>
24 #include <vector>
25 
26 #include <OnixS/FIXEngine/ABI.h>
32 
33 namespace OnixS {
34 namespace FIX {
35 ONIXS_FIXENGINE_API_DECL(class, Message);
36 ONIXS_FIXENGINE_API_DECL(class, Dictionary);
37 
38 namespace FAST {
39 /// Performs the FAST decoding using IDecodeListener to inform a user about the decoding process.
41 {
42 public:
43  /// Creates a FAST Decoder.
44  ///
45  /// @param xmlTemplates XML-based FAST templates.
46  /// @param fixVersion The FIX Protocol version.
47  /// @param decodeEachMessageIndependently The option to reset the previous
48  /// values dictionaries before decoding a new FAST stream chunk.
49  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
50  EventBasedDecoder(const std::string & xmlTemplates, ProtocolVersion::Enum fixVersion,
51  bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits);
52 
53  /// Creates a FAST Decoder.
54  ///
55  /// @param xmlTemplates XML-based FAST templates.
56  /// @param fixDictionary The customized FIX dictionary used for decoded messages
57  /// @param decodeEachMessageIndependently The option to reset the previous
58  /// values dictionaries before decoding a new FAST stream chunk.
59  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
60  EventBasedDecoder(const std::string & xmlTemplates,
61  const OnixS::FIX::Dictionary & fixDictionary, bool decodeEachMessageIndependently,
62  InputDataTraits::Enum inputDataTraits);
63 
64  /// Creates a FAST to FIX Decoder for the FIX dictionary-independent mode.
65  /// 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.
66  ///
67  /// @param xmlTemplates XML-based FAST templates.
68  /// @param decodeEachMessageIndependently The option to reset the previous
69  /// values dictionaries before decoding a new FAST stream chunk.
70  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
71  EventBasedDecoder(const std::string & xmlTemplates, bool decodeEachMessageIndependently,
72  InputDataTraits::Enum inputDataTraits);
73 
74  /// Creates a FAST to FIX Decoder for the FIX dictionary-independent mode.
75  /// 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.
76  ///
77  /// @param baseVersion This version of the FIX protocol becomes the base for the newly generated FIX dictionary.
78  /// @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
79  /// @param decodeEachMessageIndependently The option to reset the previous
80  /// values dictionaries before decoding a new FAST stream chunk.
81  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
82  EventBasedDecoder(ProtocolVersion::Enum baseVersion, const std::string & xmlTemplates,
83  bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits);
84 
85  /// Creates a FAST to FIX Decoder for the FIX dictionary-independent mode.
86  /// 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.
87  /// @note The new FIX dictionary instance will be generated if and only if there is no a FIX dictionary with the same name.
88  ///
89  /// @param baseVersion This version of the FIX protocol becomes the base for the newly generated FIX dictionary.
90  /// @param xmlTemplates XML-based FAST templates.
91  /// @param genericFixDictionaryId The identifier which is applied to the generic FIX dictionary. This FIX dictionary is generated using @c xmlTemplates and @c baseVersion.
92  /// @param decodeEachMessageIndependently The option to reset the previous
93  /// values dictionaries before decoding a new FAST stream chunk.
94  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
95  EventBasedDecoder(ProtocolVersion::Enum baseVersion, const std::string & xmlTemplates,
96  const std::string & genericFixDictionaryId, bool decodeEachMessageIndependently,
97  InputDataTraits::Enum inputDataTraits);
98 
99  /// The destructor.
100  ~EventBasedDecoder(void);
101 
102  /// Input data traits of the decoder.
103  /// @return Input data traits provided during the construction of the decoder.
104  InputDataTraits::Enum inputDataTraits() const;
105 
106  /// Decodes the given FAST stream chunk.
107  ///
108  /// @param buffer The buffer that contains the FAST stream chunk to be decoded.
109  /// @param bufferSize The size of the buffer.
110  /// @param listener The listener which receives decoding events.
111  /// @param usedSize The number of sequential bytes in the chunk which were recognized as FAST-encoded messages.
112  ///
113  /// @throw An exception if the message cannot be decoded.
114  ///
115  /// @return true if at least a single message was successfully decoded.
116  bool decode(const char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize); // Deprecated
117  bool decode(const unsigned char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize);
118 
119  /// Decodes the given FAST stream chunk.
120  ///
121  /// @param chunk The FAST stream chunk to be decoded.
122  /// @param listener The listener which receives decoding events.
123  /// @param usedSize The number of sequential bytes in the chunk which were recognized as FAST-encoded messages.
124  ///
125  /// @throw An exception if the message cannot be decoded.
126  ///
127  /// @return true if at least a single message was successfully decoded.
128  bool decode(const std::vector<char> & chunk, IDecodeListener * listener, size_t * usedSize); // Deprecated
129  bool decode(const OnixS::Sockets::Bytes & chunk, IDecodeListener * listener, size_t * usedSize);
130 
131  /// Decodes the first message from the given FAST stream chunk.
132  ///
133  /// @param buffer The buffer that contains the FAST stream chunk to be decoded.
134  /// @param bufferSize The size of the buffer.
135  /// @param listener The listener which receives decoding events.
136  /// @param usedSize The number of sequential bytes in the chunk which were recognized as a FAST-encoded message.
137  ///
138  /// @throw An exception if the message cannot be decoded.
139  ///
140  /// @return true if the message was successfully decoded.
141  bool decodeSingleMessage(const char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize); // Deprecated
142  bool decodeSingleMessage(const unsigned char * buffer, size_t bufferSize, IDecodeListener * listener, size_t * usedSize);
143 
144  /// Decodes the first message from the given FAST stream chunk.
145  ///
146  /// @param chunk The FAST stream chunk to be decoded.
147  /// @param listener The listener which receives decoding events.
148  /// @param usedSize The number of sequential bytes in the chunk which were recognized as a FAST-encoded message.
149  ///
150  /// @throw An exception if the message cannot be decoded.
151  ///
152  /// @return true if the message was successfully decoded.
153  bool decodeSingleMessage(const std::vector<char> & chunk, IDecodeListener * listener, size_t * usedSize); // Deprecated
154  bool decodeSingleMessage(const OnixS::Sockets::Bytes & chunk, IDecodeListener * listener, size_t * usedSize);
155 
156  /// Decodes the FAST-encoded unsigned integer.
157  ///
158  /// @param buffer The buffer that contains the FAST stream chunk to be decoded.
159  /// @param bufferSize The size of the buffer.
160  /// @param value The decoded value.
161  /// @param fieldLength The number of bytes that contained the encoded value.
162  ///
163  /// @return 'true' if the stop bit was found and the value was decoded, otherwise - 'false'.
164  static bool tryDecodeUnsignedInteger(const char * buffer, size_t bufferSize, unsigned int * value, size_t * fieldLength); // Deprecated
165  static bool tryDecodeUnsignedInteger(const unsigned char * buffer, size_t bufferSize, unsigned int * value, size_t * fieldLength);
166 
167  /// Resets the state of the previous values dictionaries (sets the state of the previous values to undefined).
168  ///
169  /// @see decodeEachMessageIndependently.
170  void reset();
171 
172  /// The FIX dictionary used by the decoder instance.
173  ///
174  /// @return The FIX dictionary currently used by the decoder instance. If the decoder was initialized with the FIX dictionary-independent mode, the method returns
175  /// a reference to the internally generated FIX dictionary.
176  OnixS::FIX::Dictionary fixDictionary() const;
177 private:
179 
181  EventBasedDecoder & operator = (const EventBasedDecoder &);
182 
183  class Impl;
184  Impl * impl_;
185 };
186 }
187 }
188 }
189 
190 #endif // __ONIXS_EVENTBASEDDECODER_H__
std::vector< Byte > Bytes
Sequence of bytes.
Definition: Definitions.h:43
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
Identifies the FIX messages dictionary.
Definition: Dictionary.h:73
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
The decode session&#39;s listener.
Performs the FAST decoding using IDecodeListener to inform a user about the decoding process...