Skip to content

Commit

Permalink
Add Message.{MsgType, IsMsgTypeOf} methods
Browse files Browse the repository at this point in the history
  • Loading branch information
reedom committed Sep 19, 2016
1 parent 1b493c8 commit a27a6e2
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
2 changes: 1 addition & 1 deletion in_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
2 changes: 1 addition & 1 deletion logon_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
34 changes: 17 additions & 17 deletions message.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 }

Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion message_router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions message_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -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")
}
}
Expand Down
4 changes: 2 additions & 2 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit a27a6e2

Please sign in to comment.