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.



483
484
485
486
487
488
489
490
# File 'lib/snmp/varbind.rb', line 483

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

Returns the value of attribute name.



442
443
444
# File 'lib/snmp/varbind.rb', line 442

def name
  @name
end

#valueObject

Returns the value of attribute value.



443
444
445
# File 'lib/snmp/varbind.rb', line 443

def value
  @value
end

Class Method Details

.decode(data) ⇒ Object



446
447
448
449
450
451
452
# File 'lib/snmp/varbind.rb', line 446

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



471
472
473
474
475
476
477
478
479
480
# File 'lib/snmp/varbind.rb', line 471

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



492
493
494
# File 'lib/snmp/varbind.rb', line 492

def asn1_type
    "VarBind"
end

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

Yields:

  • (_self)

Yield Parameters:

  • _self (SNMP::VarBind)

    the object that the method was called on



504
505
506
# File 'lib/snmp/varbind.rb', line 504

def each
    yield self
end

#encodeObject



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

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

#to_sObject



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

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

#to_varbindObject



496
497
498
# File 'lib/snmp/varbind.rb', line 496

def to_varbind
    self
end