Class: Fix::Protocol::Message

Inherits:
MessagePart show all
Defined in:
lib/fix/protocol/message.rb

Overview

Represents an instance of a FIX message

Instance Attribute Summary

Attributes inherited from MessagePart

#name, #parse_failure

Instance Method Summary collapse

Methods inherited from MessagePart

collection, #errors, field, inherited, #initialize_node, #node_for_name, #nodes, parse, #parse, part, structure

Constructor Details

#initializeMessage

Returns a new instance of Message.



18
19
20
21
# File 'lib/fix/protocol/message.rb', line 18

def initialize
  super
  header.msg_type = MessageClassMapping.reverse_get(self.class)
end

Instance Method Details

#dumpString

Dumps this message as a FIX protocol message, it will automatically calculate the body length and and checksum

Returns:

  • (String)

    The FIX message



29
30
31
32
33
34
35
36
# File 'lib/fix/protocol/message.rb', line 29

def dump
  if valid?
    dumped = super
    header.body_length = dumped.gsub(/^8=[^\x01]+\x019=[^\x01]+\x01/, '').length
    dumped = super
    "#{dumped}10=#{'%03d' % (dumped.bytes.inject(&:+) % 256)}\x01"
  end
end

#valid?Boolean

Whether this instance is ready to be dumped as a valid FIX message

Returns:

  • (Boolean)

    Whether there are errors present for this instance



43
44
45
# File 'lib/fix/protocol/message.rb', line 43

def valid?
  (errors.nil? || errors.empty?) && parse_failure.nil?
end