class Krakow::FrameType

Received message @abstract

Constants

FRAME_TYPE_MAP

Registered frame types

SIZE_BYTES

Size bytes

Public Class Methods

build(args={}) click to toggle source

Build proper FrameType instance based on args @param args [Hash] @option args [FrameType] :type class of frame @option args [String] :data @option args [Integer] :size @return [FrameType]

# 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) click to toggle source

Information about incoming frame @param bytes [String] @return [Hash]

# File lib/krakow/frame_type.rb, line 30
def decode(bytes)
  size, type = bytes.unpack('l>l>')
  {:size => size - SIZE_BYTES, :type => type}
end

Public Instance Methods

content() click to toggle source

Content of message

@return [String]

# File lib/krakow/frame_type.rb, line 61
def content
  raise NotImplementedError.new 'Content method not properly defined!'
end