Class: OpenFlow::Protocol::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/openflow-protocol/messages/parser.rb

Class Method Summary collapse

Class Method Details

.read(io) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/openflow-protocol/messages/parser.rb', line 10

def self.read(io)
  io = StringIO.new(io) if io.is_a?(String)

  header = io.readpartial(Message::HEADER_LENGTH)

  type       = Message::TYPES[header[1].unpack('C')[0].to_i]
  klass_name = type.to_s.split('_').map(&:capitalize).join
  klass      = OpenFlow::Protocol.const_get(klass_name)
  length     = header[2..3].unpack('S>')[0].to_i

  body = io.readpartial(length - Message::HEADER_LENGTH)

  klass.read(header + body)
end