Class: SNMP::VarBind

Inherits:
Object
  • Object
show all
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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, value = Null) ⇒ VarBind

Returns a new instance of VarBind.



542
543
544
545
546
547
548
549
# File 'lib/snmp/varbind.rb', line 542

def initialize(name, value=Null)
    if name.kind_of? ObjectId
        @name = name
    else
        @name = ObjectName.new(name)
    end
    @value = value
end

Instance Attribute Details

#nameObject Also known as: oid

Returns the value of attribute name.



499
500
501
# File 'lib/snmp/varbind.rb', line 499

def name
  @name
end

#valueObject

Returns the value of attribute value.



500
501
502
# File 'lib/snmp/varbind.rb', line 500

def value
  @value
end

Class Method Details

.decode(data) ⇒ Object



505
506
507
508
509
510
511
# File 'lib/snmp/varbind.rb', line 505

def decode(data)
    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), remaining_varbind_data
end

.decode_value(data) ⇒ Object



530
531
532
533
534
535
536
537
538
539
# File 'lib/snmp/varbind.rb', line 530

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_typeObject



551
552
553
# File 'lib/snmp/varbind.rb', line 551

def asn1_type
    "VarBind"
end

#each {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:

  • _self (SNMP::VarBind)

    the object that the method was called on



563
564
565
# File 'lib/snmp/varbind.rb', line 563

def each
    yield self
end

#encodeObject



567
568
569
570
# File 'lib/snmp/varbind.rb', line 567

def encode
    data = encode_object_id(@name) << value.encode
    encode_sequence(data)
end

#to_sObject



559
560
561
# File 'lib/snmp/varbind.rb', line 559

def to_s
    "[name=#{@name.to_s}, value=#{@value.to_s} (#{@value.asn1_type})]"
end

#to_varbindObject



555
556
557
# File 'lib/snmp/varbind.rb', line 555

def to_varbind
    self
end