Class: Qrack::Transport09::Frame

Inherits:
Object
  • Object
show all
Defined in:
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.



26
27
28
# File 'lib/qrack/transport/frame09.rb', line 26

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

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



24
25
26
# File 'lib/qrack/transport/frame09.rb', line 24

def channel
  @channel
end

#payloadObject

Returns the value of attribute payload.



24
25
26
# File 'lib/qrack/transport/frame09.rb', line 24

def payload
  @payload
end

Class Method Details

.parse(buf) ⇒ Object



54
55
56
57
58
59
60
# File 'lib/qrack/transport/frame09.rb', line 54

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



48
49
50
51
52
# File 'lib/qrack/transport/frame09.rb', line 48

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

#idObject



30
31
32
# File 'lib/qrack/transport/frame09.rb', line 30

def id
  self.class::ID
end

#to_binaryObject



34
35
36
37
38
39
40
41
42
# File 'lib/qrack/transport/frame09.rb', line 34

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



44
45
46
# File 'lib/qrack/transport/frame09.rb', line 44

def to_s
  to_binary.to_s
end