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