Class: Qrack::Transport09::Frame

Inherits:
Object
  • Object
show all
Defined in:
lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb

Direct Known Subclasses

Body, Header, Heartbeat, Method

Constant Summary collapse

206
ID =
0

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.



23
24
25
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 23

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

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



21
22
23
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 21

def channel
  @channel
end

#payloadObject

Returns the value of attribute payload.



21
22
23
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 21

def payload
  @payload
end

Class Method Details

.parse(buf) ⇒ Object



51
52
53
54
55
56
57
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 51

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

Instance Method Details

#==(frame) ⇒ Object



45
46
47
48
49
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 45

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

#idObject



27
28
29
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 27

def id
  self.class::ID
end

#to_binaryObject



31
32
33
34
35
36
37
38
39
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 31

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

#to_sObject



41
42
43
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame09.rb', line 41

def to_s
  to_binary.to_s
end