Class: SNMP::VarBindList

Inherits:
Array
  • Object
show all
Extended by:
BER::Decode
Includes:
BER::Encode
Defined in:
lib/snmp/varbind.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods included from BER::Decode

assert_no_remainder, build_integer, decode_integer, decode_integer_value, decode_ip_address, decode_object_id, decode_object_id_value, decode_octet_string, decode_sequence, decode_timeticks, decode_tlv, decode_uinteger_value

Methods included from BER::Encode

#encode_exception, #encode_integer, #encode_length, #encode_null, #encode_object_id, #encode_octet_string, #encode_sequence, #encode_tagged_integer, #encode_tlv, #integer_to_octets

Constructor Details

#initialize(varbind_list = []) ⇒ VarBindList

Returns a new instance of VarBindList.



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/snmp/varbind.rb', line 45

def initialize(varbind_list=[])
  super()
  if varbind_list.respond_to? :to_str
    self << ObjectId.new(varbind_list.to_str).to_varbind
  elsif varbind_list.respond_to? :to_varbind
    self << varbind_list.to_varbind
  else
    varbind_list.each do |item|
      if item.respond_to? :to_str
        self << ObjectId.new(item.to_str).to_varbind
      else
        self << item.to_varbind
      end
    end
  end
end

Class Method Details

.decode(data, mib = nil) ⇒ Object



35
36
37
38
39
40
41
42
43
# File 'lib/snmp/varbind.rb', line 35

def self.decode(data, mib=nil)
  list = VarBindList.new
  varbind_data, remainder = decode_sequence(data)
  while varbind_data != ""
    varbind, varbind_data = VarBind.decode(varbind_data, mib)
    list << varbind
  end
  return list, remainder
end

Instance Method Details

#asn1_typeObject



62
63
64
# File 'lib/snmp/varbind.rb', line 62

def asn1_type
  "VarBindList"
end

#encodeObject



66
67
68
69
70
71
72
# File 'lib/snmp/varbind.rb', line 66

def encode
  varbind_data = "".dup
  self.each do |varbind|
    varbind_data << varbind.encode
  end
  encode_sequence(varbind_data)
end