@@ -181,10 +181,17 @@ func ParseMessageWithDataDictionary(
181181
182182// doParsing executes the message parsing process.
183183func doParsing (mp * msgParser ) (err error ) {
184+ mp .msg .Header .rwLock .Lock ()
185+ defer mp .msg .Header .rwLock .Unlock ()
186+ mp .msg .Body .rwLock .Lock ()
187+ defer mp .msg .Body .rwLock .Unlock ()
188+ mp .msg .Trailer .rwLock .Lock ()
189+ defer mp .msg .Trailer .rwLock .Unlock ()
190+
184191 // Initialize for parsing.
185- mp .msg .Header .Clear ()
186- mp .msg .Body .Clear ()
187- mp .msg .Trailer .Clear ()
192+ mp .msg .Header .clearNoLock ()
193+ mp .msg .Body .clearNoLock ()
194+ mp .msg .Trailer .clearNoLock ()
188195
189196 // Allocate expected message fields in one chunk.
190197 fieldCount := bytes .Count (mp .rawBytes , []byte {'\001' })
@@ -262,7 +269,7 @@ func doParsing(mp *msgParser) (err error) {
262269 }
263270
264271 if mp .parsedFieldBytes .tag == tagXMLDataLen {
265- xmlDataLen , _ = mp .msg .Header .GetInt (tagXMLDataLen )
272+ xmlDataLen , _ = mp .msg .Header .getIntNoLock (tagXMLDataLen )
266273 }
267274 mp .fieldIndex ++
268275 }
@@ -287,7 +294,7 @@ func doParsing(mp *msgParser) (err error) {
287294 }
288295 }
289296
290- bodyLength , err := mp .msg .Header .GetInt (tagBodyLength )
297+ bodyLength , err := mp .msg .Header .getIntNoLock (tagBodyLength )
291298 if err != nil {
292299 err = parseError {OrigError : err .Error ()}
293300 } else if length != bodyLength && ! xmlDataMsg {
@@ -368,7 +375,7 @@ func parseGroup(mp *msgParser, tags []Tag) {
368375// tags slice will contain multiple tags if the tag in question is found while processing a group already.
369376func isNumInGroupField (msg * Message , tags []Tag , appDataDictionary * datadictionary.DataDictionary ) bool {
370377 if appDataDictionary != nil {
371- msgt , err := msg .MsgType ()
378+ msgt , err := msg .msgTypeNoLock ()
372379 if err != nil {
373380 return false
374381 }
@@ -401,7 +408,7 @@ func isNumInGroupField(msg *Message, tags []Tag, appDataDictionary *datadictiona
401408// tags slice will contain multiple tags if the tag in question is found while processing a group already.
402409func getGroupFields (msg * Message , tags []Tag , appDataDictionary * datadictionary.DataDictionary ) (fields []* datadictionary.FieldDef ) {
403410 if appDataDictionary != nil {
404- msgt , err := msg .MsgType ()
411+ msgt , err := msg .msgTypeNoLock ()
405412 if err != nil {
406413 return
407414 }
@@ -471,6 +478,10 @@ func (m *Message) MsgType() (string, MessageRejectError) {
471478 return m .Header .GetString (tagMsgType )
472479}
473480
481+ func (m * Message ) msgTypeNoLock () (string , MessageRejectError ) {
482+ return m .Header .getStringNoLock (tagMsgType )
483+ }
484+
474485// IsMsgTypeOf returns true if the Header contains MsgType (tag 35) field and its value is the specified one.
475486func (m * Message ) IsMsgTypeOf (msgType string ) bool {
476487 if v , err := m .MsgType (); err == nil {
0 commit comments