From 1b493c82fd1921a6687e18fa495ebacf263c53d4 Mon Sep 17 00:00:00 2001 From: HANAI tohru Date: Sun, 18 Sep 2016 15:17:19 +0900 Subject: [PATCH] Apply Header.GetMsgType() --- in_session.go | 6 +++--- logon_state.go | 6 +++--- message_router.go | 4 ++-- session.go | 19 +++++++++---------- 4 files changed, 17 insertions(+), 18 deletions(-) diff --git a/in_session.go b/in_session.go index 1a2fe9a4f..7bcec5399 100644 --- a/in_session.go +++ b/in_session.go @@ -12,12 +12,12 @@ type inSession struct{ loggedOn } func (state inSession) String() string { return "In Session" } func (state inSession) FixMsgIn(session *session, msg Message) sessionState { - var msgType FIXString - if err := msg.Header.GetField(tagMsgType, &msgType); err != nil { + msgType, err := msg.Header.GetMsgType() + if err != nil { return handleStateError(session, err) } - switch enum.MsgType(msgType) { + switch msgType { case enum.MsgType_LOGON: if err := session.handleLogon(msg); err != nil { if err := session.initiateLogout(""); err != nil { diff --git a/logon_state.go b/logon_state.go index 554bb78c9..46ece35e4 100644 --- a/logon_state.go +++ b/logon_state.go @@ -10,12 +10,12 @@ type logonState struct{ connectedNotLoggedOn } func (s logonState) String() string { return "Logon State" } func (s logonState) FixMsgIn(session *session, msg Message) (nextState sessionState) { - var msgType FIXString - if err := msg.Header.GetField(tagMsgType, &msgType); err != nil { + msgType, err := msg.Header.GetMsgType() + if err != nil { return handleStateError(session, err) } - if enum.MsgType(msgType) != enum.MsgType_LOGON { + if msgType != enum.MsgType_LOGON { session.log.OnEventf("Invalid Session State: Received Msg %s while waiting for Logon", msg) return latentState{} } diff --git a/message_router.go b/message_router.go index 25c499463..223796e7a 100644 --- a/message_router.go +++ b/message_router.go @@ -34,8 +34,8 @@ func (c MessageRouter) Route(msg Message, sessionID SessionID) MessageRejectErro return nil } - var msgType FIXString - if err := msg.Header.GetField(tagMsgType, &msgType); err != nil { + msgType, err := msg.Header.GetMsgType() + if err != nil { return err } diff --git a/session.go b/session.go index 1018f89bf..0feae628c 100644 --- a/session.go +++ b/session.go @@ -234,15 +234,15 @@ func (s *session) prepMessageForSend(msg *Message) error { seqNum := s.store.NextSenderMsgSeqNum() msg.Header.SetField(tagMsgSeqNum, FIXInt(seqNum)) - var msgType FIXString - if err := msg.Header.GetField(tagMsgType, &msgType); err != nil { + msgType, err := msg.Header.GetMsgType() + if err != nil { return err } if isAdminMessageType(string(msgType)) { s.application.ToAdmin(*msg, s.sessionID) - if enum.MsgType(msgType) == enum.MsgType_LOGON { + if msgType == enum.MsgType_LOGON { var resetSeqNumFlag FIXBoolean if msg.Body.Has(tagResetSeqNumFlag) { if err := msg.Body.GetField(tagResetSeqNumFlag, &resetSeqNumFlag); err != nil { @@ -267,12 +267,11 @@ func (s *session) prepMessageForSend(msg *Message) error { } } - msgBytes, err := msg.Build() - if err == nil { - err = s.persist(seqNum, msgBytes) + if msgBytes, err := msg.Build(); err != nil { + return err + } else { + return s.persist(seqNum, msgBytes) } - - return err } func (s *session) persist(seqNum int, msgBytes []byte) error { @@ -466,8 +465,8 @@ func (s *session) verifySelect(msg Message, checkTooHigh bool, checkTooLow bool) } func (s *session) fromCallback(msg Message) MessageRejectError { - var msgType FIXString - if err := msg.Header.GetField(tagMsgType, &msgType); err != nil { + msgType, err := msg.Header.GetMsgType() + if err != nil { return err }