OnixS C++ FIX Engine  4.2.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>
29 #include <OnixS/FIXEngine/FIX/InputDataTraits.h>
30 #include <OnixS/FIXEngine/Sockets/Definitions.h>
31 #include <OnixS/FIXEngine/FIX/ValuesEnums.h>
33 
34 namespace OnixS {
35 namespace FIX {
36 ONIXS_FIXENGINE_API_DECL(class, Message);
37 ONIXS_FIXENGINE_API_DECL(class, Dictionary);
38 
39 namespace FAST {
40 /// Performs FAST decoding using IDecodeListener to inform user about the decoding process.
42 {
43 public:
44  /// Creates FAST Decoder.
45  ///
46  /// @param xmlTemplates XML-based FAST templates.
47  /// @param fixVersion FIX Protocol version.
48  /// @param decodeEachMessageIndependently Option to reset the previous
49  /// values dictionaries before decoding a new FAST stream chunk.
50  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
51  EventBasedDecoder(const std::string & xmlTemplates, ProtocolVersion::Enum fixVersion,
52  bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits);
53 
54  /// Creates a FAST Decoder.
55  ///
56  /// @param xmlTemplates XML-based FAST templates.
57  /// @param fixDictionary Customized FIX dictionary used for decoded messages
58  /// @param decodeEachMessageIndependently Option to reset the previous
59  /// values dictionaries before decoding a new FAST stream chunk.
60  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
61  EventBasedDecoder(const std::string & xmlTemplates,
62  const OnixS::FIX::Dictionary & fixDictionary, bool decodeEachMessageIndependently,
63  InputDataTraits::Enum inputDataTraits);
64 
65  /// Creates a FAST to FIX Decoder for FIX dictionary-independent mode.
66  /// The generic FIX dictionary is created by the provided FAST-template content, uses FIX 4.0 as base FIX dictionary and has generic name.
67  ///
68  /// @param xmlTemplates XML-based FAST templates.
69  /// @param decodeEachMessageIndependently Option to reset the previous
70  /// values dictionaries before decoding a new FAST stream chunk.
71  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
72  EventBasedDecoder(const std::string & xmlTemplates, bool decodeEachMessageIndependently,
73  InputDataTraits::Enum inputDataTraits);
74 
75  /// Creates a FAST to FIX Decoder for FIX dictionary-independent mode.
76  /// The generic FIX dictionary is created by the provided FAST-template content, uses specified FIX dictionary as base and has generic name.
77  ///
78  /// @param baseVersion Version of FIX protocol which dictionary becomes base for the newly generated FIX dictionary.
79  /// @param xmlTemplates XML-based FAST templates used to generate FIX dictionary. This FIX dictionary takes generic identifier generated on base of the XML contanet and @c baseVersion
80  /// @param decodeEachMessageIndependently Option to reset the previous
81  /// values dictionaries before decoding a new FAST stream chunk.
82  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
83  EventBasedDecoder(ProtocolVersion::Enum baseVersion, const std::string & xmlTemplates,
84  bool decodeEachMessageIndependently, InputDataTraits::Enum inputDataTraits);
85 
86  /// Creates a FAST to FIX Decoder for FIX dictionary-independent mode.
87  /// The generic FIX dictionary is created by the provided FAST-template content, uses specified FIX dictionary as base and has the specified name.
88  /// @note New FIX dictionary instance will be generated if and only if there is no FIX dictionary with the same name.
89  ///
90  /// @param baseVersion Version of FIX protocol which dictionary becomes base for the newly generated FIX dictionary.
91  /// @param xmlTemplates XML-based FAST templates.
92  /// @param genericFixDictionaryId Identifier which is applied to generic FIX dictionary. This FIX dictionary is generated using @c xmlTemplates and @c baseVersion.
93  /// @param decodeEachMessageIndependently Option to reset the previous
94  /// values dictionaries before decoding a new FAST stream chunk.
95  /// @param inputDataTraits Traits of input data, has effect only when @c decodeEachMessageIndependently is @c false. See InputDataTraits::Enum for details.
96  EventBasedDecoder(ProtocolVersion::Enum baseVersion, const std::string & xmlTemplates,
97  const std::string & genericFixDictionaryId, bool decodeEachMessageIndependently,
98  InputDataTraits::Enum inputDataTraits);
99 
100  /// Destructor.
101  ~EventBasedDecoder(void);
102 
103  /// Input data traits of the decoder.
104  /// @return Input data traits provided during construction of the decoder.
105  InputDataTraits::Enum inputDataTraits() const;
106 
107  /// Decodes the given FAST stream chunk.
108  ///
109  /// @param buffer Buffer that contains the FAST stream chunk to be decoded.
110  /// @param bufferSize Size of the buffer.
111  /// @param listener Listener which receives decoding events.
112  /// @param usedSize Number of sequential bytes in the chunk which were recognized as FAST-encoded messages.
113  ///
114  /// @throw Exception if the message cannot be decoded.
115  ///
116  /// @return true if at least a single message was successfully decoded.
117  bool decode(const char * buffer, size_t bufferSize, IDecodeListener * listener,
118  size_t * usedSize); // Deprecated
119  bool decode(const unsigned char * buffer, size_t bufferSize, IDecodeListener * listener,
120  size_t * usedSize);
121 
122  /// Decodes the given FAST stream chunk.
123  ///
124  /// @param chunk The FAST stream chunk to be decoded.
125  /// @param listener Listener which receives decoding events.
126  /// @param usedSize Number of sequential bytes in the chunk which were recognized as FAST-encoded messages.
127  ///
128  /// @throw Exception if the message cannot be decoded.
129  ///
130  /// @return true if at least a single message was successfully decoded.
131  bool decode(const std::vector<char> & chunk, IDecodeListener * listener,
132  size_t * usedSize); // Deprecated
133  bool decode(const OnixS::Sockets::Bytes & chunk, IDecodeListener * listener, size_t * usedSize);
134 
135  /// Decodes the just a first message from given FAST stream chunk.
136  ///
137  /// @param buffer Buffer that contains the FAST stream chunk to be decoded.
138  /// @param bufferSize Size of the buffer.
139  /// @param listener Listener which receives decoding events.
140  /// @param usedSize Number of sequential bytes in the chunk which were recognized as FAST-encoded message.
141  ///
142  /// @throw Exception if the message cannot be decoded.
143  ///
144  /// @return true if the message was successfully decoded.
145  bool decodeSingleMessage(const char * buffer, size_t bufferSize, IDecodeListener * listener,
146  size_t * usedSize); // Deprecated
147  bool decodeSingleMessage(const unsigned char * buffer, size_t bufferSize,
148  IDecodeListener * listener, size_t * usedSize);
149 
150  /// Decodes the just a first message from given FAST stream chunk.
151  ///
152  /// @param chunk The FAST stream chunk to be decoded.
153  /// @param listener Listener which receives decoding events.
154  /// @param usedSize Number of sequential bytes in the chunk which were recognized as FAST-encoded message.
155  ///
156  /// @throw Exception if the message cannot be decoded.
157  ///
158  /// @return true if the message was successfully decoded.
159  bool decodeSingleMessage(const std::vector<char> & chunk, IDecodeListener * listener,
160  size_t * usedSize); // Deprecated
161  bool decodeSingleMessage(const OnixS::Sockets::Bytes & chunk, IDecodeListener * listener,
162  size_t * usedSize);
163 
164  /// Decodes the FAST-encoded unsigned integer.
165  ///
166  /// @param buffer Buffer that contains the FAST stream chunk to be decoded.
167  /// @param bufferSize Size of the buffer.
168  /// @param value Decoded value.
169  /// @param fieldLength Number of bytes that contained the encoded value.
170  ///
171  /// @return 'true' if the stop bit was found and the value was decoded, otherwise - 'false'.
172  static bool tryDecodeUnsignedInteger(const char * buffer, size_t bufferSize,
173  unsigned int * value, size_t * fieldLength); // Deprecated
174  static bool tryDecodeUnsignedInteger(const unsigned char * buffer, size_t bufferSize,
175  unsigned int * value, size_t * fieldLength);
176 
177  /// Resets the state of the previous values dictionaries (sets the state of the previous values to undefined).
178  ///
179  /// @see decodeEachMessageIndependently.
180  void reset();
181 
182  /// FIX dictionary used by the decoder instance.
183  ///
184  /// @return FIX dictionary currently used by the decoder instance. If the decoder was initialized with FIX dictionary-independent mode, the method returns
185  /// reference to internally generated FIX dictionary.
186  OnixS::FIX::Dictionary fixDictionary() const;
187 private:
189 
191  EventBasedDecoder & operator = (const EventBasedDecoder &);
192 
193  struct Impl;
194  Impl * impl_;
195 };
196 }
197 }
198 }
199 
200 #endif // __ONIXS_EVENTBASEDDECODER_H__
Identifies FIX messages dictionary.
Definition: Dictionary.h:79
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
Decode session&#39;s listener.
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
Performs FAST decoding using IDecodeListener to inform user about the decoding process.