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.



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

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.



487
488
489
# File 'lib/snmp/varbind.rb', line 487

def name
  @name
end

#valueObject

Returns the value of attribute value.



488
489
490
# File 'lib/snmp/varbind.rb', line 488

def value
  @value
end

Class Method Details

.decode(data) ⇒ Object



493
494
495
496
497
498
499
# File 'lib/snmp/varbind.rb', line 493

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



518
519
520
521
522
523
524
525
526
527
# File 'lib/snmp/varbind.rb', line 518

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



539
540
541
# File 'lib/snmp/varbind.rb', line 539

def asn1_type
    "VarBind"
end

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

Yields:

  • (_self)

Yield Parameters:

  • _self (SNMP::VarBind)

    the object that the method was called on



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

def each
    yield self
end

#encodeObject



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

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

#to_sObject



547
548
549
# File 'lib/snmp/varbind.rb', line 547

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

#to_varbindObject



543
544
545
# File 'lib/snmp/varbind.rb', line 543

def to_varbind
    self
end