Class: AMQP::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/amqp/frame.rb,
lib/amqp/spec.rb

Overview

:nodoc: all

Defined Under Namespace

Classes: Body, Header, Heartbeat, Invalid, Method, OobBody, OobHeader, OobMethod, Trace

Constant Summary collapse

206

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(payload = nil, channel = 0) ⇒ Frame

Returns a new instance of Frame.



7
8
9
# File 'lib/amqp/frame.rb', line 7

def initialize payload = nil, channel = 0
  @channel, @payload = channel, payload
end

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



10
11
12
# File 'lib/amqp/frame.rb', line 10

def channel
  @channel
end

#payloadObject

Returns the value of attribute payload.



10
11
12
# File 'lib/amqp/frame.rb', line 10

def payload
  @payload
end

Class Method Details

.Frame(id) ⇒ Object



19
20
21
22
23
24
25
26
27
28
# File 'lib/amqp/spec.rb', line 19

def self.Frame id
  (@_base_frames ||= {})[id] ||= Class.new(Frame) do
    class_eval %[
      def self.inherited klass
        klass.const_set(:ID, #{id})
        Frame.types[#{id}] = klass
      end
    ]
  end
end

.parse(buf) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/amqp/frame.rb', line 58

def self.parse buf
  buf = Buffer.new(buf) unless buf.is_a? Buffer
  buf.extract do
    id, channel, payload, footer = buf.read(:octet, :short, :longstr, :octet)
    Frame.types[id].new(payload, channel) if footer == FOOTER
  end
end

.typesObject



15
16
17
# File 'lib/amqp/spec.rb', line 15

def self.types
  @types ||= {}
end

Instance Method Details

#==(frame) ⇒ Object



30
31
32
33
34
# File 'lib/amqp/frame.rb', line 30

def == frame
  [ :id, :channel, :payload ].inject(true) do |eql, field|
    eql and __send__(field) == frame.__send__(field)
  end
end

#idObject



12
13
14
# File 'lib/amqp/frame.rb', line 12

def id
  self.class::ID
end

#to_binaryObject



16
17
18
19
20
21
22
23
24
# File 'lib/amqp/frame.rb', line 16

def to_binary
  buf = Buffer.new
  buf.write :octet, id
  buf.write :short, channel
  buf.write :longstr, payload
  buf.write :octet, FOOTER
  buf.rewind
  buf
end

#to_sObject



26
27
28
# File 'lib/amqp/frame.rb', line 26

def to_s
  to_binary.to_s
end