Skip to content

Commit

Permalink
Apply Header.GetMsgType()
Browse files Browse the repository at this point in the history
  • Loading branch information
reedom committed Sep 18, 2016
1 parent 50a627f commit 1b493c8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 18 deletions.
6 changes: 3 additions & 3 deletions in_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions logon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down
4 changes: 2 additions & 2 deletions message_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
19 changes: 9 additions & 10 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down

0 comments on commit 1b493c8

Please sign in to comment.