Class SNMP::VarBind
In: lib/snmp/varbind.rb
Parent: Object

Methods

asn1_type   decode   decode_value   each   encode   new   to_s   to_varbind  

Constants

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

External Aliases

name -> oid

Attributes

name  [RW] 
value  [RW] 

Public Class methods

[Source]

# 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

[Source]

# 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

[Source]

# 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

Public Instance methods

[Source]

# File lib/snmp/varbind.rb, line 551
    def asn1_type
        "VarBind"
    end

[Source]

# File lib/snmp/varbind.rb, line 563
    def each
        yield self
    end

[Source]

# File lib/snmp/varbind.rb, line 567
    def encode
        data = encode_object_id(@name) << value.encode
        encode_sequence(data)
    end

[Source]

# File lib/snmp/varbind.rb, line 559
    def to_s
        "[name=#{@name.to_s}, value=#{@value.to_s} (#{@value.asn1_type})]"
    end

[Source]

# File lib/snmp/varbind.rb, line 555
    def to_varbind
        self
    end

[Validate]