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

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

Instance Method Summary collapse

Instance Method Details

#to_berObject

Converts the fixnum to BER format.



4
5
6
# File 'lib/net/ber/core_ext/fixnum.rb', line 4

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.



28
29
30
# File 'lib/net/ber/core_ext/fixnum.rb', line 28

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

#to_ber_enumeratedObject

Converts the fixnum to BER enumerated format.



10
11
12
# File 'lib/net/ber/core_ext/fixnum.rb', line 10

def to_ber_enumerated
  "\012#{to_ber_internal}"
end

#to_ber_length_encodingObject

Converts the fixnum to BER length encodining format.



16
17
18
19
20
21
22
23
# File 'lib/net/ber/core_ext/fixnum.rb', line 16

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