diff --git a/in_session.go b/in_session.go index 7bcec5399..55315d41b 100644 --- a/in_session.go +++ b/in_session.go @@ -12,7 +12,7 @@ type inSession struct{ loggedOn } func (state inSession) String() string { return "In Session" } func (state inSession) FixMsgIn(session *session, msg Message) sessionState { - msgType, err := msg.Header.GetMsgType() + msgType, err := msg.MsgType() if err != nil { return handleStateError(session, err) } diff --git a/logon_state.go b/logon_state.go index 46ece35e4..04b3a6d46 100644 --- a/logon_state.go +++ b/logon_state.go @@ -10,7 +10,7 @@ type logonState struct{ connectedNotLoggedOn } func (s logonState) String() string { return "Logon State" } func (s logonState) FixMsgIn(session *session, msg Message) (nextState sessionState) { - msgType, err := msg.Header.GetMsgType() + msgType, err := msg.MsgType() if err != nil { return handleStateError(session, err) } diff --git a/message.go b/message.go index 9ad859547..7246d4588 100644 --- a/message.go +++ b/message.go @@ -43,23 +43,6 @@ func (h *Header) Init() { }) } -// GetMsgType returns MsgType (tag 35) field's value -func (h *Header) GetMsgType() (msgType enum.MsgType, err MessageRejectError) { - var s string - if s, err = h.GetString(tagMsgType); err == nil { - msgType = enum.MsgType(s) - } - return -} - -// HasMsgTypeOf returns true if the Header contains MsgType (tag 35) field and its value is the specified one. -func (h *Header) HasMsgTypeOf(msgType enum.MsgType) bool { - if v, err := h.GetMsgType(); err == nil { - return v == msgType - } - return false -} - //Body is the primary application section of a FIX message type Body struct{ FieldMap } @@ -220,6 +203,23 @@ func ParseMessage(rawMessage []byte) (Message, error) { return msg, nil } +// MsgType returns MsgType (tag 35) field's value +func (m Message) MsgType() (enum.MsgType, MessageRejectError) { + s, err := m.Header.GetString(tagMsgType) + if err != nil { + return enum.MsgType(""), err + } + return enum.MsgType(s), nil +} + +// IsMsgTypeOf returns true if the Header contains MsgType (tag 35) field and its value is the specified one. +func (m Message) IsMsgTypeOf(msgType enum.MsgType) bool { + if v, err := m.MsgType(); err == nil { + return v == msgType + } + return false +} + //reverseRoute returns a message builder with routing header fields initialized as the reverse of this message. func (m Message) reverseRoute() Message { reverseMsg := NewMessage() diff --git a/message_router.go b/message_router.go index 223796e7a..586b40573 100644 --- a/message_router.go +++ b/message_router.go @@ -34,7 +34,7 @@ func (c MessageRouter) Route(msg Message, sessionID SessionID) MessageRejectErro return nil } - msgType, err := msg.Header.GetMsgType() + msgType, err := msg.MsgType() if err != nil { return err } diff --git a/message_test.go b/message_test.go index 9f6b818b4..cb5eab44f 100644 --- a/message_test.go +++ b/message_test.go @@ -43,7 +43,7 @@ func TestMessage_ParseMessage(t *testing.T) { t.Errorf("Expected %v fields, got %v", expectedLenFields, len(msg.fields)) } - msgType, err := msg.Header.GetMsgType() + msgType, err := msg.MsgType() if err != nil { t.Error("Unexpected error, ", err) } @@ -52,11 +52,11 @@ func TestMessage_ParseMessage(t *testing.T) { t.Errorf("Expected msgType MsgType_ORDER_SINGLE, got %#v", msgType) } - if !msg.Header.HasMsgTypeOf(enum.MsgType_ORDER_SINGLE) { + if !msg.IsMsgTypeOf(enum.MsgType_ORDER_SINGLE) { t.Errorf("Expected Header.HasMsgTypeOf(MsgType_ORDER_SINGLE) is true") } - if msg.Header.HasMsgTypeOf(enum.MsgType_LOGON) { + if msg.IsMsgTypeOf(enum.MsgType_LOGON) { t.Errorf("Expected Header.HasMsgTypeOf(MsgType_LOGON) is false") } } diff --git a/session.go b/session.go index 0feae628c..ce8e826b8 100644 --- a/session.go +++ b/session.go @@ -234,7 +234,7 @@ func (s *session) prepMessageForSend(msg *Message) error { seqNum := s.store.NextSenderMsgSeqNum() msg.Header.SetField(tagMsgSeqNum, FIXInt(seqNum)) - msgType, err := msg.Header.GetMsgType() + msgType, err := msg.MsgType() if err != nil { return err } @@ -465,7 +465,7 @@ func (s *session) verifySelect(msg Message, checkTooHigh bool, checkTooLow bool) } func (s *session) fromCallback(msg Message) MessageRejectError { - msgType, err := msg.Header.GetMsgType() + msgType, err := msg.MsgType() if err != nil { return err }