openflow-protocol 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/messages/parser.rb +13 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8e7714d41af75fba41ce2f02671fc712eaddb910
|
4
|
+
data.tar.gz: 1158656d489227146fa789732a35b309f15e4df2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c884f54f0a7de1a348737bbbc657f6794f3ef636dc865b47f2caf5a061559746b37eca767f7078051bf583b34860c828bf94f6376935423ae47934f9b4ac58cf
|
7
|
+
data.tar.gz: ca5f9566a19916c652113b01e10007a2c97317b8a787acef8ff70f7330638e7bcefc19af339811523ffe934420a9abb1f43541545d41ff1376cb2a47b5fb9b75
|
data/lib/messages/parser.rb
CHANGED
@@ -1,12 +1,22 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
Dir[File.expand_path '*.rb', __dir__].each do |file|
|
2
4
|
require_relative file
|
3
5
|
end
|
4
6
|
|
5
7
|
class OFParser
|
6
|
-
def self.read(
|
7
|
-
|
8
|
+
def self.read(io)
|
9
|
+
io = StringIO.new(io) if io.is_a?(String)
|
10
|
+
|
11
|
+
header = io.readpartial(OFMessage::HEADER_LENGTH)
|
12
|
+
|
13
|
+
type = OFMessage::TYPES[header[1].unpack('C')[0].to_i]
|
8
14
|
klass_name = 'OF' + type.to_s.split('_').map(&:capitalize).join
|
9
15
|
klass = Object.const_get(klass_name)
|
10
|
-
|
16
|
+
length = header[2..3].unpack('S>')[0].to_i
|
17
|
+
|
18
|
+
body = io.readpartial(length - OFMessage::HEADER_LENGTH)
|
19
|
+
|
20
|
+
klass.read(header + body)
|
11
21
|
end
|
12
22
|
end
|