lib/snmp/open/parser/value_parser.rb in snmp-open-0.6.0 vs lib/snmp/open/parser/value_parser.rb in snmp-open-0.6.1
- old
+ new
@@ -21,13 +21,15 @@
# parses BITS
class Bits < ValueParser
def parse(tokens)
return @parse if @parse
+
bytes = []
loop do
break unless tokens.peek =~ /\A[0-9A-Za-z]{1,2}\z/
+
bytes << tokens.next.to_i(16)
end
@parse = [@type, bytes]
end
end # class Bits < ValueParser
@@ -48,13 +50,15 @@
# parses objects identified like '= Hex-STRING:'
class HexString < ValueParser
def parse(tokens)
return @parse if @parse
+
bytes = []
loop do
break unless tokens.peek =~ /\A[0-9A-Za-z]{2}\z/
+
bytes << tokens.next
end
string = bytes.map { |b| b.to_i(16).chr }.join
@parse = [@type, string]
end
@@ -70,10 +74,11 @@
# parses objects identified like '= Timeticks:'
# note that 1 second = 100 ticks
class Timeticks < ValueParser
def parse(tokens)
return @parse if @parse
+
ticks = tokens.next.tr('()', '').to_i
# consume tokens through one like 23:59:59.99
loop do
break if tokens.next =~ /\A\d\d:\d\d:\d\d.\d\d\z/
@@ -104,19 +109,19 @@
end
end # class NoSuchObject < ValueParser
KNOWN_TOKENS = {
NOSUCHINSTANCE_STR => NoSuchInstance,
- NOSUCHOBJECT_STR => NoSuchObject,
+ NOSUCHOBJECT_STR => NoSuchObject,
NOMOREVARIABLES_STR => Stop
}.freeze
KNOWN_TYPES = {
nil => Default,
'BITS' => Bits,
- 'INTEGER' => ValueParser::Integer,
- 'Gauge32' => ValueParser::Integer,
- 'Gauge64' => ValueParser::Integer,
+ 'INTEGER' => ValueParser::Integer,
+ 'Gauge32' => ValueParser::Integer,
+ 'Gauge64' => ValueParser::Integer,
'Counter32' => ValueParser::Integer,
'Counter64' => ValueParser::Integer,
'Hex-STRING' => HexString,
'Timeticks' => Timeticks
}.freeze