Class: Fix::Protocol::Message
- Inherits:
-
MessagePart
- Object
- MessagePart
- Fix::Protocol::Message
- Defined in:
- lib/fix/protocol/message.rb
Overview
Represents an instance of a FIX message
Direct Known Subclasses
Fix::Protocol::Messages::Heartbeat, Fix::Protocol::Messages::Logon, Fix::Protocol::Messages::Logout, Fix::Protocol::Messages::MarketDataIncrementalRefresh, Fix::Protocol::Messages::MarketDataRequest, Fix::Protocol::Messages::MarketDataSnapshot, Fix::Protocol::Messages::Reject, Fix::Protocol::Messages::ResendRequest, Fix::Protocol::Messages::TestRequest
Instance Attribute Summary
Attributes inherited from MessagePart
#delegations, #name, #parse_failure
Instance Method Summary collapse
-
#dump ⇒ String
Dumps this message as a FIX protocol message, it will automatically calculate the body length and and checksum.
-
#errors ⇒ Array<String>
Returns the errors relevant to the message header.
-
#initialize ⇒ Message
constructor
A new instance of Message.
-
#valid? ⇒ Boolean
Whether this instance is ready to be dumped as a valid FIX message.
Methods inherited from MessagePart
collection, field, inherited, #initialize_node, #node_for_name, #nodes, parent_delegate, parse, #parse, part, structure, unordered
Constructor Details
#initialize ⇒ Message
Returns a new instance of Message.
26 27 28 29 |
# File 'lib/fix/protocol/message.rb', line 26 def initialize super header.msg_type = MessageClassMapping.reverse_get(self.class) end |
Instance Method Details
#dump ⇒ String
Dumps this message as a FIX protocol message, it will automatically calculate the body length and and checksum
37 38 39 40 41 42 43 44 |
# File 'lib/fix/protocol/message.rb', line 37 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 ⇒ Array<String>
Returns the errors relevant to the message header
60 61 62 63 64 65 66 |
# File 'lib/fix/protocol/message.rb', line 60 def errors if (version == 'FIX.4.4') super else [super, "Unsupported version: <#{version}>"].flatten end end |
#valid? ⇒ Boolean
Whether this instance is ready to be dumped as a valid FIX message
51 52 53 |
# File 'lib/fix/protocol/message.rb', line 51 def valid? (errors.nil? || errors.empty?) && parse_failure.nil? end |