Class: Krakow::FrameType Abstract
- Inherits:
-
Object
- Object
- Krakow::FrameType
- Extended by:
- Utils::Lazy::ClassMethods
- Includes:
- Utils::Lazy, Utils::Lazy::InstanceMethods
- Defined in:
- lib/krakow/frame_type.rb,
lib/krakow/frame_type/error.rb,
lib/krakow/frame_type/message.rb,
lib/krakow/frame_type/response.rb
Overview
This class is abstract.
Received message
Defined Under Namespace
Classes: Error, Message, Response
Constant Summary collapse
- FRAME_TYPE_MAP =
Registered frame types
[ FrameType::Response, FrameType::Error, FrameType::Message ]
- SIZE_BYTES =
Size bytes
4
Instance Attribute Summary
Attributes included from Utils::Lazy::InstanceMethods
Class Method Summary collapse
-
.build(args = {}) ⇒ FrameType
Build proper FrameType instance based on args.
-
.decode(bytes) ⇒ Hash
Information about incoming frame.
Instance Method Summary collapse
-
#content ⇒ String
Content of message.
Methods included from Utils::Lazy::ClassMethods
attribute, attributes, set_attributes
Methods included from Utils::Lazy::InstanceMethods
Methods included from Utils::Lazy
Methods included from Utils::Logging
Class Method Details
.build(args = {}) ⇒ FrameType
Build proper FrameType instance based on args
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/krakow/frame_type.rb', line 41 def build(args={}) klass = FRAME_TYPE_MAP[args[:type].to_i] if(klass == FrameType::Response) klass.new(:response => args[:data]) elsif(klass == FrameType::Error) klass.new(:error => args[:data]) elsif(klass == FrameType::Message) unpacked = args[:data].unpack("Q>s>a16a#{args[:size]}") klass.new( Hash[*([:timestamp, :attempts, :message_id, :message].zip(unpacked).flatten)] ) else raise TypeError.new "Unknown frame type received: #{args[:type].inspect} - #{klass.inspect}" end end |
.decode(bytes) ⇒ Hash
Information about incoming frame
30 31 32 33 |
# File 'lib/krakow/frame_type.rb', line 30 def decode(bytes) size, type = bytes.unpack('l>l>') {:size => size - SIZE_BYTES, :type => type} end |
Instance Method Details
#content ⇒ String
Content of message
61 62 63 |
# File 'lib/krakow/frame_type.rb', line 61 def content raise NotImplementedError.new 'Content method not properly defined!' end |