Module: Net::SNMP::Debug

Class Attribute Summary collapse

Instance Method Summary collapse

Class Attribute Details

.loggerObject

Returns the value of attribute logger.



5
6
7
# File 'lib/net/snmp/debug.rb', line 5

def logger
  @logger
end

Instance Method Details



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/net/snmp/debug.rb', line 26

def print_packet(packet)
  byte_string = (packet.kind_of?(Array) ? packet[0] : packet)

  byte_array = byte_string.unpack("C*")
  binary =  byte_array.map{|n| n.to_s(2).rjust(8, '0')}

  puts " # | Decimal |  Hex  |  Binary  | Character"
  puts "-------------------------------------------"

  i = 0
  prev = 0
  byte_array.zip(binary).each do |byte, binary_string|
    puts "#{i.to_s.ljust(5)}#{byte.to_s.ljust(10)}0x#{byte.to_s(16).ljust(6)}#{binary_string.ljust(11)}#{byte.chr}   #{'Sequence Length' if byte == 130 && prev == 48}"
    prev = byte
    i += 1
  end
end

#time(label, &block) ⇒ Object



19
20
21
22
23
24
# File 'lib/net/snmp/debug.rb', line 19

def time(label, &block)
  t_start = Time.now
  block[]
  t_end = Time.now
  debug "#{label}: #{(t_end - t_start)*1000}ms"
end