# File lib/net/ldap/core_ext/fixnum.rb, line 8
8: def to_ber
9: "\0002" + to_ber_internal
10: end
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
# File lib/net/ldap/core_ext/fixnum.rb, line 15
15: def to_ber_enumerated
16: "\0012" + to_ber_internal
17: end
# 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.
Generated with the Darkfish Rdoc Generator 1.1.6.