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.



547
548
549
550
551
552
553
554
# File 'lib/snmp/varbind.rb', line 547

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.



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

def name
  @name
end

#valueObject

Returns the value of attribute value.



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

def value
  @value
end

Class Method Details

.decode(data) ⇒ Object



510
511
512
513
514
515
516
# File 'lib/snmp/varbind.rb', line 510

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



535
536
537
538
539
540
541
542
543
544
# File 'lib/snmp/varbind.rb', line 535

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



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

def asn1_type
  "VarBind"
end

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

Yields:

  • (_self)

Yield Parameters:

  • _self (SNMP::VarBind)

    the object that the method was called on



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

def each
  yield self
end

#encodeObject



572
573
574
575
# File 'lib/snmp/varbind.rb', line 572

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

#to_sObject



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

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

#to_varbindObject



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

def to_varbind
  self
end