OnixS C++ FIX Engine  4.2.0
API Documentation
SerializedMessage.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 #pragma once
21 
26 
27 #include <OnixS/FIXEngine/FIX/SerializedFieldRefAndKey.h>
28 
30 
31 namespace OnixS {
32 namespace FIX {
33 ONIXS_FIXENGINE_API_DECL(class, Message);
34 
35 /// Provides access to FIX fields from a serialized (tag=value) message.
36 ///
37 /// Fields can be accessed using temporary field references and using
38 /// special keys which remain constant during lifetime of the single instance.
39 ///
40 /// To access a field, a reference must be obtained using the 'find' member.
41 /// 'find' member search for a field using a regular Tag identifier.
42 /// If 'find' succeeds, a temporary reference is returned. That reference can
43 /// be either used to modify the field or to allocate a key for that field using
44 /// 'allocateKey' member. Once the key is allocated it can be used like a tag
45 /// to quick access the field.
46 ///
47 /// There are pre-allocated keys to access service fields like MsgType, MsgSeqNum, SendingTime, etc.
48 ///
49 /// @note BodyLength and CheckSum fields are not synchronized each time other fields are updated.
50 /// Therefore, to bring the serialized message (tag=value) into the valid state, it's necessary to invoke the 'adjust' member.
52 {
53 public:
54  /// Constructs an instance from the tag=value form.
55  SerializedMessage(const char * rawMessage, size_t rawMessageSize, bool useZeroCopyBuffer = true);
56 
57  /// Constructs an instance from the tag=value form without session-level fields.
58  /// Required fields will be added during the construction.
60  OnixS::FIX::ProtocolVersion::Enum protocolVersion,
61  const char * msgType,
62  const char * senderCompId,
63  const char * targetCompId,
64  const char * rawMessageWithoutHeaderTrailer,
65  size_t rawMessageWithoutHeaderTrailerSize,
66  bool useZeroCopyBuffer = true);
67 
68  /// Constructs an instance from the given Message object.
69  SerializedMessage(const OnixS::FIX::Message & message, bool useZeroCopyBuffer = true);
70 
71  /// Initializes as a copy of the given instance.
72  SerializedMessage(const SerializedMessage & other);
73 
74  /// Utilizes internal resources.
76 
77  /// Returns the content of the serialized message.
78  const char * chars() const;
79 
80  /// Size of the serialized content.
81  size_t size() const;
82 
83  /// Returns a string that represents the serialized message.
84  std::string toString() const;
85 
86  /// Looks for a field using the given tag number.
87  /// @return A valid reference in case of success, otherwise - an invalid one.
88  SerializedFieldRef find(Tag) const;
89 
90  /// Looks for a field with assumption field is located
91  /// after given another field using its tag number.
92  ///
93  /// Member is suitable to access same fields but from
94  /// different repeating group instances.
95  ///
96  /// @return A valid reference in case of success, otherwise - an invalid one.
97  SerializedFieldRef find(Tag, const SerializedFieldRef &) const;
98 
99  /// Allocates a key to the requested field for further access.
100  SerializedFieldKey allocateKey(const SerializedFieldRef &);
101 
102  /// Finds and allocates a key to the requested field for further access.
103  SerializedFieldKey allocateKey(Tag);
104 
105  /// Provides access to a field value by the given temporary reference.
106  StringRef operator[](const SerializedFieldRef &) const;
107 
108  /// Provides access to a field value by the given field key.
109  StringRef operator[](SerializedFieldKey) const;
110 
111  /// Updates the field value.
112  ///
113  /// @note Once the value is updated, only the reference used to
114  /// access the field remains valid, other references become invalid.
115  void set(SerializedFieldRef &, const StringRef &);
116 
117  /// Updates the field value.
118  ///
119  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
120  void set(SerializedFieldKey, const StringRef &);
121 
122  /// Updates the field value.
123  ///
124  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
125  void set(SerializedFieldRef &, Char);
126 
127  /// Updates the field value.
128  ///
129  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
130  void set(SerializedFieldKey, Char);
131 
132  /// Updates the field value.
133  ///
134  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
135  void set(SerializedFieldRef &, Int32);
136 
137  /// Updates the field value.
138  ///
139  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
140  void set(SerializedFieldKey, Int32);
141 
142  /// Updates the field value.
143  ///
144  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
145  void set(SerializedFieldRef &, UInt32);
146 
147  /// Updates the field value.
148  ///
149  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
150  void set(SerializedFieldKey, UInt32);
151 
152  /// Updates the field value.
153  ///
154  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
155  void set(SerializedFieldRef &, Int64);
156 
157  /// Updates the field value.
158  ///
159  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
160  void set(SerializedFieldKey, Int64);
161 
162  /// Updates the field value.
163  ///
164  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
165  void set(SerializedFieldRef &, UInt64);
166 
167  /// Updates the field value.
168  ///
169  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
170  void set(SerializedFieldKey, UInt64);
171 
172  /// Updates the field value.
173  ///
174  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
175  void set(SerializedFieldRef &, const Decimal &);
176 
177  /// Updates the field value.
178  ///
179  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
180  void set(SerializedFieldKey, const Decimal &);
181 
182  /// Updates the field value.
183  ///
184  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid..
185  void set(SerializedFieldRef &, const Timestamp &, TimestampFormat::Enum);
186 
187  /// Updates the field value.
188  ///
189  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
190  void set(SerializedFieldKey, const Timestamp &, TimestampFormat::Enum);
191 
192  /// Updates the field value.
193  ///
194  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid..
195  void set(SerializedFieldRef &, const TimeSpan &, TimeSpanFormat::Enum);
196 
197  /// Updates the field value.
198  ///
199  /// @note Once the value is updated, only the reference used to access the field remains valid, other references become invalid.
200  void set(SerializedFieldKey, const TimeSpan &, TimeSpanFormat::Enum);
201 
202  /// Updates BodyLength and CheckSum fields.
203  void adjust();
204 
205  /// Re-initializes as a copy of the given instance.
206  SerializedMessage & operator = (const SerializedMessage &);
207 
208 private:
209  friend class MessageOperator;
210  friend class SerializedMessageWrapper;
211 
212  SerializedMessage(const OnixS::FIX::Core::Messaging::Extras::SerializedMessage & other);
213 
214  OnixS::FIX::Core::Messaging::Extras::SerializedMessage * impl_;
215 };
216 
217 inline
218 SerializedFieldRef
220 {
221  return find(tag, SerializedFieldRef());
222 }
223 
224 /// Stream output.
226 std::ostream & operator << (std::ostream & os, const SerializedMessage & message);
227 }
228 }
int Int32
Definition: Numeric.h:32
Provides access to FIX fields from a serialized (tag=value) message.
ONIXS_FIXENGINE_API_DECL(class, IEngineListener)
ONIXS_FIXENGINE_API std::ostream & operator<<(std::ostream &os, const Group &group)
Stream output.
Timestamps related functionality.
Definition: Timestamp.h:91
Provides efficient way of accessing text-based FIX field values.
Definition: StringRef.h:44
unsigned Tag
Alias for tag numbers.
Definition: Tag.h:27
#define ONIXS_FIXENGINE_API
Definition: ABI.h:45
Decimal type for better precision.
Definition: Numeric.h:44
char Char
Definition: Numeric.h:30
Encapsulates operations over a FIX Message.
Definition: Message.h:49
unsigned long long UInt64
Definition: Numeric.h:36
Time span related functionality.
Definition: TimeSpan.h:93
long long Int64
Definition: Numeric.h:35
unsigned int UInt32
Definition: Numeric.h:33
SerializedFieldRef find(Tag) const
Looks for a field using the given tag number.