Class: SNMP::VarBind
- Inherits:
-
Object
- Object
- SNMP::VarBind
- Defined in:
- lib/snmp/varbind.rb
Constant Summary collapse
- ValueDecoderMap =
{ INTEGER_TAG => Integer, OCTET_STRING_TAG => OctetString, NULL_TAG => Null, OBJECT_IDENTIFIER_TAG => ObjectId, IpAddress_TAG => IpAddress, Counter32_TAG => Counter32, Gauge32_TAG => Gauge32, # note Gauge32 tag same as Unsigned32 TimeTicks_TAG => TimeTicks, Opaque_TAG => Opaque, Counter64_TAG => Counter64, NoSuchObject_TAG => NoSuchObject, NoSuchInstance_TAG => NoSuchInstance, EndOfMibView_TAG => EndOfMibView }
Instance Attribute Summary collapse
-
#name ⇒ Object
(also: #oid)
Returns the value of attribute name.
-
#value ⇒ Object
Returns the value of attribute value.
Class Method Summary collapse
Instance Method Summary collapse
- #asn1_type ⇒ Object
- #each {|_self| ... } ⇒ Object
- #encode ⇒ Object
-
#initialize(name, value = Null) ⇒ VarBind
constructor
A new instance of VarBind.
- #to_s ⇒ Object
- #to_varbind ⇒ Object
-
#with_mib(mib) ⇒ Object
Adds MIB information to this varbind for use with to_s.
Constructor Details
#initialize(name, value = Null) ⇒ VarBind
Returns a new instance of VarBind.
564 565 566 567 568 569 570 571 |
# File 'lib/snmp/varbind.rb', line 564 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.
521 522 523 |
# File 'lib/snmp/varbind.rb', line 521 def name @name end |
#value ⇒ Object
Returns the value of attribute value.
522 523 524 |
# File 'lib/snmp/varbind.rb', line 522 def value @value end |
Class Method Details
.decode(data, mib = nil) ⇒ Object
527 528 529 530 531 532 533 |
# File 'lib/snmp/varbind.rb', line 527 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
552 553 554 555 556 557 558 559 560 561 |
# File 'lib/snmp/varbind.rb', line 552 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
582 583 584 |
# File 'lib/snmp/varbind.rb', line 582 def asn1_type "VarBind" end |
#each {|_self| ... } ⇒ Object
594 595 596 |
# File 'lib/snmp/varbind.rb', line 594 def each yield self end |
#encode ⇒ Object
598 599 600 601 |
# File 'lib/snmp/varbind.rb', line 598 def encode data = encode_object_id(@name) << value.encode encode_sequence(data) end |
#to_s ⇒ Object
590 591 592 |
# File 'lib/snmp/varbind.rb', line 590 def to_s "[name=#{@name.to_s}, value=#{@value.to_s} (#{@value.asn1_type})]" end |
#to_varbind ⇒ Object
586 587 588 |
# File 'lib/snmp/varbind.rb', line 586 def to_varbind self end |
#with_mib(mib) ⇒ Object
Adds MIB information to this varbind for use with to_s.
576 577 578 579 580 |
# File 'lib/snmp/varbind.rb', line 576 def with_mib(mib) @name.with_mib(mib) if @name @value.with_mib(mib) if @value.respond_to? :with_mib self end |