|
6 | 6 | "math" |
7 | 7 | "time" |
8 | 8 |
|
| 9 | + "github.com/quickfixgo/quickfix/datadictionary" |
9 | 10 | "github.com/quickfixgo/quickfix/enum" |
10 | 11 | ) |
11 | 12 |
|
@@ -116,6 +117,16 @@ func NewMessage() *Message { |
116 | 117 |
|
117 | 118 | //ParseMessage constructs a Message from a byte slice wrapping a FIX message. |
118 | 119 | func ParseMessage(msg *Message, rawMessage *bytes.Buffer) (err error) { |
| 120 | + return ParseMessageWithDataDictionary(msg, rawMessage, nil, nil) |
| 121 | +} |
| 122 | + |
| 123 | +//ParseMessageWithDataDictionary constructs a Message from a byte slice wrapping a FIX message using an optional session and application DataDictionary for reference. |
| 124 | +func ParseMessageWithDataDictionary( |
| 125 | + msg *Message, |
| 126 | + rawMessage *bytes.Buffer, |
| 127 | + transportDataDictionary *datadictionary.DataDictionary, |
| 128 | + applicationDataDictionary *datadictionary.DataDictionary, |
| 129 | +) (err error) { |
119 | 130 | msg.Header.Clear() |
120 | 131 | msg.Body.Clear() |
121 | 132 | msg.Trailer.Clear() |
@@ -173,9 +184,9 @@ func ParseMessage(msg *Message, rawMessage *bytes.Buffer) (err error) { |
173 | 184 | } |
174 | 185 |
|
175 | 186 | switch { |
176 | | - case parsedFieldBytes.tag.IsHeader(): |
| 187 | + case isHeaderField(parsedFieldBytes.tag, transportDataDictionary): |
177 | 188 | msg.Header.add(msg.fields[fieldIndex : fieldIndex+1]) |
178 | | - case parsedFieldBytes.tag.IsTrailer(): |
| 189 | + case isTrailerField(parsedFieldBytes.tag, transportDataDictionary): |
179 | 190 | msg.Trailer.add(msg.fields[fieldIndex : fieldIndex+1]) |
180 | 191 | default: |
181 | 192 | foundBody = true |
@@ -215,6 +226,33 @@ func ParseMessage(msg *Message, rawMessage *bytes.Buffer) (err error) { |
215 | 226 | } |
216 | 227 |
|
217 | 228 | return |
| 229 | + |
| 230 | +} |
| 231 | + |
| 232 | +func isHeaderField(tag Tag, dataDict *datadictionary.DataDictionary) bool { |
| 233 | + if tag.IsHeader() { |
| 234 | + return true |
| 235 | + } |
| 236 | + |
| 237 | + if dataDict == nil { |
| 238 | + return false |
| 239 | + } |
| 240 | + |
| 241 | + _, ok := dataDict.Header.Fields[int(tag)] |
| 242 | + return ok |
| 243 | +} |
| 244 | + |
| 245 | +func isTrailerField(tag Tag, dataDict *datadictionary.DataDictionary) bool { |
| 246 | + if tag.IsTrailer() { |
| 247 | + return true |
| 248 | + } |
| 249 | + |
| 250 | + if dataDict == nil { |
| 251 | + return false |
| 252 | + } |
| 253 | + |
| 254 | + _, ok := dataDict.Trailer.Fields[int(tag)] |
| 255 | + return ok |
218 | 256 | } |
219 | 257 |
|
220 | 258 | // MsgType returns MsgType (tag 35) field's value |
|
0 commit comments