def self.encode_types(nsec)
output=""
type_codes = []
nsec.types.each do |type|
type_codes.push(type.code)
end
type_codes.sort!
window = -1
0.step(65536,256) { |step|
types_to_go = []
while (!type_codes.empty? && type_codes[0] < step)
types_to_go.push(type_codes[0])
type_codes=type_codes.last(type_codes.length-1)
break if (type_codes.empty?)
end
if (!types_to_go.empty?)
bitmap=""
pos = 0
bitmap_pos = 0
while (!types_to_go.empty?)
byte = 0
pos += 8
while (types_to_go[0] < pos + step-256)
byte = byte | (1 << (pos-1-(types_to_go[0] - (step-256) )))
types_to_go =types_to_go.last(types_to_go.length-1)
break if (types_to_go.empty?)
end
bitmap += " "
if (bitmap[bitmap_pos].class == String)
bitmap.setbyte(bitmap_pos, byte)
else
bitmap[bitmap_pos]=byte
end
bitmap_pos+=1
end
start = output.length
(2+bitmap.length).times do
output += " "
end
if (output[start].class == String)
output.setbyte(start, window)
output.setbyte(start+1, bitmap.length)
bitmap.length.times do |i|
output.setbyte(start+2+i, bitmap[i].getbyte(0))
end
else
output[start] = window
output[start+1] = bitmap.length
bitmap.length.times do |i|
output[start+2+i] = bitmap[i]
end
end
end
window += 1
if (type_codes.empty?)
break
end
}
if (output[0].class == String)
output = output.force_encoding("ascii-8bit")
end
return output
end