class Fix::Protocol::Message
Represents an instance of a FIX message
Constants
- DEFAULT_VERSION
Default version for when we do not specify anything
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/fix/protocol/message.rb, line 39 def initialize super header.msg_type = MessageClassMapping.reverse_get(self.class) end
version=(v)
click to toggle source
Allows the version tag to be overridden at runtime
@param version [String] The version to output and expect in messages
# File lib/fix/protocol/message.rb, line 22 def self.version=(v) @@expected_version = v end
Public Instance Methods
dump()
click to toggle source
Dumps this message as a FIX protocol message, it will automatically calculate the body length and and checksum
@return [String] The FIX message
Calls superclass method
# File lib/fix/protocol/message.rb, line 50 def dump if valid? dumped = super header.body_length = dumped.gsub(/^8=[^\x01]+\x01/, '').gsub(/^9=[^\x01]+\x01/, '').length dumped = super "#{dumped}10=#{'%03d' % (dumped.bytes.inject(&:+) % 256)}\x01" end end
errors()
click to toggle source
Returns the errors relevant to the message header
@return [Array<String>] The errors on the message header
Calls superclass method
# File lib/fix/protocol/message.rb, line 73 def errors if (version == @@expected_version) super else [super, "Unsupported version: <#{version}>, expected <#{@@expected_version}>"].flatten end end
valid?()
click to toggle source
Whether this instance is ready to be dumped as a valid FIX message
@return [Boolean] Whether there are errors present for this instance
# File lib/fix/protocol/message.rb, line 64 def valid? (errors.nil? || errors.empty?) && parse_failure.nil? end