Class SNMP::ObjectId
In: lib/snmp/varbind.rb
Parent: Array

Methods

asn1_type   decode   encode   index   inspect   new   subtree_of?   to_oid   to_s   to_varbind  

Included Modules

Comparable

Public Class methods

[Source]

# File lib/snmp/varbind.rb, line 140
    def self.decode(value_data)
        ObjectId.new(decode_object_id_value(value_data))
    end

Create an object id. The input is expected to be either a string in the format "n.n.n.n.n.n" or an array of integers.

[Source]

# File lib/snmp/varbind.rb, line 152
    def initialize(id=[])
        if id.nil?
            raise ArgumentError
        elsif id.respond_to? :to_str
            super(make_integers(id.to_str.split(".")))
        else
            super(make_integers(id.to_ary))
        end
    rescue ArgumentError
        raise ArgumentError, "#{id.inspect}:#{id.class} not a valid object ID"
    end

Public Instance methods

[Source]

# File lib/snmp/varbind.rb, line 144
    def asn1_type
        "OBJECT IDENTIFIER"
    end

[Source]

# File lib/snmp/varbind.rb, line 180
    def encode
        encode_object_id(self)
    end

Returns an index based on the difference between this ObjectId and the provided parent ObjectId.

For example, ObjectId.new("1.3.6.1.5").index("1.3.6.1") returns an ObjectId of "5".

[Source]

# File lib/snmp/varbind.rb, line 207
    def index(parent_tree)
        parent_tree = make_object_id(parent_tree)
        if not subtree_of?(parent_tree)
            raise ArgumentError, "#{self.to_s} not a subtree of #{parent_tree.to_s}"
        elsif self.length == parent_tree.length
            raise ArgumentError, "OIDs are the same"
        else
            ObjectId.new(self[parent_tree.length..-1])
        end
    end

[Source]

# File lib/snmp/varbind.rb, line 176
    def inspect
        "[#{self.to_s}]"
    end

Returns true if this ObjectId is a subtree of the provided parent tree ObjectId. For example, "1.3.6.1.5" is a subtree of "1.3.6.1".

[Source]

# File lib/snmp/varbind.rb, line 188
    def subtree_of?(parent_tree)
        parent_tree = make_object_id(parent_tree)
        if parent_tree.length > self.length
            false
        else
            parent_tree.each_index do |i|
                return false if parent_tree[i] != self[i]
            end
            true
        end
    end

[Source]

# File lib/snmp/varbind.rb, line 168
    def to_oid
        self
    end

[Source]

# File lib/snmp/varbind.rb, line 172
    def to_s
        self.join('.')
    end

[Source]

# File lib/snmp/varbind.rb, line 164
    def to_varbind
        VarBind.new(self, Null)
    end

[Validate]