Module: Net::BER::Extensions::Integer

Included in:
Integer
Defined in:
lib/net/ber/core_ext/integer.rb

Overview

BER extensions to the Integer class, affecting Fixnum and Bignum objects.

Instance Method Summary collapse

Instance Method Details

#to_berObject

Converts the Integer to BER format.



7
8
9
# File 'lib/net/ber/core_ext/integer.rb', line 7

def to_ber
  "\002#{to_ber_internal}"
end

#to_ber_application(tag) ⇒ Object

Generate a BER-encoding for an application-defined INTEGER. Examples of such integers are SNMP’s Counter, Gauge, and TimeTick types.



31
32
33
# File 'lib/net/ber/core_ext/integer.rb', line 31

def to_ber_application(tag)
  [0x40 + tag].pack("C") + to_ber_internal
end

#to_ber_enumeratedObject

Converts the Integer to BER enumerated format.



13
14
15
# File 'lib/net/ber/core_ext/integer.rb', line 13

def to_ber_enumerated
  "\012#{to_ber_internal}"
end

#to_ber_length_encodingObject

Converts the Integer to BER length encoding format.



19
20
21
22
23
24
25
26
# File 'lib/net/ber/core_ext/integer.rb', line 19

def to_ber_length_encoding
  if self <= 127
    [self].pack('C')
  else
    i = [self].pack('N').sub(/^[\0]+/, "")
    [0x80 + i.length].pack('C') + i
  end
end