Module: Net::BER::Extensions::Fixnum

Included in:
Fixnum
Defined in:
lib/net/ber/core_ext/fixnum.rb

Overview

Ber extensions to the Fixnum class.

Instance Method Summary collapse

Instance Method Details

#to_berObject

Converts the fixnum to BER format.



7
8
9
# File 'lib/net/ber/core_ext/fixnum.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/fixnum.rb', line 31

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

#to_ber_enumeratedObject

Converts the fixnum to BER enumerated format.



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

def to_ber_enumerated
  "\012#{to_ber_internal}"
end

#to_ber_length_encodingObject

Converts the fixnum to BER length encodining format.



19
20
21
22
23
24
25
26
# File 'lib/net/ber/core_ext/fixnum.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