Class: Qrack::Transport::Frame

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



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

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

Instance Attribute Details

#channelObject

Returns the value of attribute channel.



28
29
30
# File 'lib/qrack/transport/frame08.rb', line 28

def channel
  @channel
end

#payloadObject

Returns the value of attribute payload.



28
29
30
# File 'lib/qrack/transport/frame08.rb', line 28

def payload
  @payload
end

Class Method Details

.parse(buf) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/qrack/transport/frame08.rb', line 58

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



52
53
54
55
56
# File 'lib/qrack/transport/frame08.rb', line 52

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

#idObject



34
35
36
# File 'lib/qrack/transport/frame08.rb', line 34

def id
  self.class::ID
end

#to_binaryObject



38
39
40
41
42
43
44
45
46
# File 'lib/qrack/transport/frame08.rb', line 38

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



48
49
50
# File 'lib/qrack/transport/frame08.rb', line 48

def to_s
  to_binary.to_s
end