Class: SNMP::VarBind
Constant Summary
collapse
- ValueDecoderMap =
{
BER::INTEGER_TAG => Integer,
BER::OCTET_STRING_TAG => OctetString,
BER::NULL_TAG => Null,
BER::OBJECT_IDENTIFIER_TAG => ObjectId,
BER::IpAddress_TAG => IpAddress,
BER::Counter32_TAG => Counter32,
BER::Gauge32_TAG => Gauge32,
BER::TimeTicks_TAG => TimeTicks,
BER::Opaque_TAG => Opaque,
BER::Counter64_TAG => Counter64,
BER::NoSuchObject_TAG => NoSuchObject,
BER::NoSuchInstance_TAG => NoSuchInstance,
BER::EndOfMibView_TAG => EndOfMibView
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
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
#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(name, value = Null) ⇒ VarBind
Returns a new instance of VarBind.
598
599
600
601
602
603
604
605
|
# File 'lib/snmp/varbind.rb', line 598
def initialize(name, value=Null)
if name.kind_of? ObjectId
@name = name
else
@name = ObjectName.new(name)
end
@value = value
end
|
Instance Attribute Details
#name ⇒ Object
Also known as:
oid
Returns the value of attribute name.
555
556
557
|
# File 'lib/snmp/varbind.rb', line 555
def name
@name
end
|
#value ⇒ Object
Returns the value of attribute value.
556
557
558
|
# File 'lib/snmp/varbind.rb', line 556
def value
@value
end
|
Class Method Details
.decode(data, mib = nil) ⇒ Object
561
562
563
564
565
566
567
|
# File 'lib/snmp/varbind.rb', line 561
def decode(data, mib=nil)
varbind_data, remaining_varbind_data = decode_sequence(data)
name, remainder = decode_object_id(varbind_data)
value, remainder = decode_value(remainder)
assert_no_remainder(remainder)
return VarBind.new(name, value).with_mib(mib), remaining_varbind_data
end
|
.decode_value(data) ⇒ Object
586
587
588
589
590
591
592
593
594
595
|
# File 'lib/snmp/varbind.rb', line 586
def decode_value(data)
value_tag, value_data, remainder = decode_tlv(data)
decoder_class = ValueDecoderMap[value_tag]
if decoder_class
value = decoder_class.decode(value_data)
else
raise UnsupportedValueTag, value_tag.to_s
end
return value, remainder
end
|
Instance Method Details
#asn1_type ⇒ Object
616
617
618
|
# File 'lib/snmp/varbind.rb', line 616
def asn1_type
"VarBind"
end
|
#each {|_self| ... } ⇒ Object
628
629
630
|
# File 'lib/snmp/varbind.rb', line 628
def each
yield self
end
|
#encode ⇒ Object
632
633
634
635
|
# File 'lib/snmp/varbind.rb', line 632
def encode
data = encode_object_id(@name) << value.encode
encode_sequence(data)
end
|
#to_s ⇒ Object
624
625
626
|
# File 'lib/snmp/varbind.rb', line 624
def to_s
"[name=#{@name.to_s}, value=#{@value.to_s} (#{@value.asn1_type})]"
end
|
#to_varbind ⇒ Object
620
621
622
|
# File 'lib/snmp/varbind.rb', line 620
def to_varbind
self
end
|
#with_mib(mib) ⇒ Object
Adds MIB information to this varbind for use with to_s.
610
611
612
613
614
|
# File 'lib/snmp/varbind.rb', line 610
def with_mib(mib)
@name.with_mib(mib) if @name
@value.with_mib(mib) if @value.respond_to? :with_mib
self
end
|