Class: Carrot::AMQP::Frame
- Inherits:
-
Object
- Object
- Carrot::AMQP::Frame
show all
- Defined in:
- lib/amqp/frame.rb,
lib/amqp/spec.rb
Overview
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.
3
4
5
|
# File 'lib/amqp/frame.rb', line 3
def initialize payload = nil, channel = 0
@channel, @payload = channel, payload
end
|
Instance Attribute Details
#channel ⇒ Object
Returns the value of attribute channel.
6
7
8
|
# File 'lib/amqp/frame.rb', line 6
def channel
@channel
end
|
#payload ⇒ Object
Returns the value of attribute payload.
6
7
8
|
# File 'lib/amqp/frame.rb', line 6
def payload
@payload
end
|
Class Method Details
.Frame(id) ⇒ Object
7
8
9
10
11
12
13
14
15
16
|
# File 'lib/amqp/spec.rb', line 7
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
54
55
56
57
58
59
60
|
# File 'lib/amqp/frame.rb', line 54
def self.parse(buf)
buf = Buffer.new(buf) unless buf.is_a? Buffer
buf. do
id, channel, payload, = buf.read(:octet, :short, :longstr, :octet)
Frame.types[id].new(payload, channel) if == FOOTER
end
end
|
.types ⇒ Object
3
4
5
|
# File 'lib/amqp/spec.rb', line 3
def self.types
@types ||= {}
end
|
Instance Method Details
#==(frame) ⇒ Object
26
27
28
29
30
|
# File 'lib/amqp/frame.rb', line 26
def == frame
[ :id, :channel, :payload ].inject(true) do |eql, field|
eql and __send__(field) == frame.__send__(field)
end
end
|
#id ⇒ Object
8
9
10
|
# File 'lib/amqp/frame.rb', line 8
def id
self.class::ID
end
|
#to_binary ⇒ Object
12
13
14
15
16
17
18
19
20
|
# File 'lib/amqp/frame.rb', line 12
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_s ⇒ Object
22
23
24
|
# File 'lib/amqp/frame.rb', line 22
def to_s
to_binary.to_s
end
|