Class: Qrack::Transport::Frame

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

Direct Known Subclasses

Body, Header, Heartbeat, Method, OobBody, OobHeader, OobMethod, Trace

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.



25
26
27
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb', line 25

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

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



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

def channel
  @channel
end

#payloadObject

Returns the value of attribute payload.



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

def payload
  @payload
end

Class Method Details

.parse(buf) ⇒ Object



53
54
55
56
57
58
59
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb', line 53

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

Instance Method Details

#==(frame) ⇒ Object



47
48
49
50
51
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb', line 47

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

#idObject



29
30
31
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb', line 29

def id
	self.class::ID
end

#to_binaryObject



33
34
35
36
37
38
39
40
41
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb', line 33

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

#to_sObject



43
44
45
# File 'lib/ext/bunny-0.6.0/lib/qrack/transport/frame08.rb', line 43

def to_s
  to_binary.to_s
end