Net::LDAP::Extensions::Fixnum

Constants

MAX_SIZE

Public Instance Methods

to_ber() click to toggle source

to_ber

    # File lib/net/ldap/core_ext/fixnum.rb, line 8
 8:         def to_ber
 9:           "\0002" + to_ber_internal
10:         end
to_ber_application(tag) click to toggle source

Generate a BER-encoding for an application-defined INTEGER. Example: SNMP’s Counter, Gauge, and TimeTick types.

    # File lib/net/ldap/core_ext/fixnum.rb, line 34
34:         def to_ber_application tag
35:             [0x40 + tag].pack("C") + to_ber_internal
36:         end
to_ber_enumerated() click to toggle source

to_ber_enumerated

    # File lib/net/ldap/core_ext/fixnum.rb, line 15
15:         def to_ber_enumerated
16:           "\0012" + to_ber_internal
17:         end
to_ber_length_encoding() click to toggle source

to_ber_length_encoding

    # File lib/net/ldap/core_ext/fixnum.rb, line 22
22:         def to_ber_length_encoding
23:           if self <= 127
24:             [self].pack('C')
25:           else
26:             i = [self].pack('N').sub(/^[\00]]+/,"")
27:             [0x80 + i.length].pack('C') + i
28:           end
29:         end

Private Instance Methods

to_ber_internal() click to toggle source
    # File lib/net/ldap/core_ext/fixnum.rb, line 43
43:         def to_ber_internal
44:           # CAUTION: Bit twiddling ahead. You might want to shield your eyes 
45:           # or something. 
46:           
47:           # Looks for the first byte in the fixnum that is not all zeroes. It
48:           # does this by masking one byte after another, checking the result
49:           # for bits that are left on. 
50:           size = MAX_SIZE
51:           while size>1
52:             break if (self & (0xff << (size-1)*8)) > 0 
53:             size -= 1
54:           end
55:           
56:           # Store the size of the fixnum in the result
57:           result = [size]
58: 
59:           # Appends bytes to result, starting with higher orders first.
60:           # Extraction of bytes is done by right shifting the original fixnum
61:           # by an amount and then masking that with 0xff.
62:           while size>0
63:             # right shift size-1 bytes, mask with 0xff 
64:             result << ((self >> ((size-1)*8)) & 0xff)
65:             size -= 1
66:           end
67: 
68:           result.pack('C*')
69:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.