module Dnsruby::RR::NXT::NxtTypes
Methods used to manipulate the storage and representation of record types as stored in NXT
record bitmaps.
Constants
- MAX_BITMAP_NUMBER_VALUE
Maximum bitmap size is 128 bytes; since it's zero offset values are 0..(2 ** 128 - 1). However, the least significant bit must not be set, so the maximum is 1 less than that.
Public Instance Methods
Assert that the specified number is a legal value with which to instantiate a NXT
type bitmap. Raise on error, do nothing on success.
# File lib/dnsruby/resource/NXT.rb, line 238 def assert_legal_bitmap_value(number) max_value = NxtTypes::MAX_BITMAP_NUMBER_VALUE if number > max_value raise ArgumentError.new("Bitmap maximum value is #{max_value} (0x#{max_value.to_s(16)}).") end if number & 1 == 1 raise ArgumentError.new("Bitmap number must not have low bit set.") end end
From a binary string of type code bits, return an array of type codes.
# File lib/dnsruby/resource/NXT.rb, line 213 def binary_string_to_codes(binary_string) bitmap_number = BitMapping.binary_string_to_number(binary_string) assert_legal_bitmap_value(bitmap_number) BitMapping.number_to_set_bit_positions_array(bitmap_number) end
From a binary string of type code bits, return an array of type names.
# File lib/dnsruby/resource/NXT.rb, line 221 def binary_string_to_names(binary_string) codes = binary_string_to_codes(binary_string) codes_to_names(codes) end
Convert a numeric type code to its corresponding name (e.g. “A” => 1). Unknown types are named “TYPE#{number}”.
# File lib/dnsruby/resource/NXT.rb, line 172 def code_to_name(number) Types.to_string(number) || "TYPE#{number}" end
From an array of type codes, return a binary string.
# File lib/dnsruby/resource/NXT.rb, line 227 def codes_to_binary_string(codes) codes = codes.sort unless legal_code_value?(codes.first) && legal_code_value?(codes.last) raise ArgumentError.new("All codes must be between 1 and 127: #{codes.inspect}.") end bitmap_number = BitMapping.set_bit_position_array_to_number(codes) BitMapping.number_to_binary_string(bitmap_number) end
For the given array of type codes, return an array of their corresponding names.
# File lib/dnsruby/resource/NXT.rb, line 201 def codes_to_names(codes) codes.map { |code| code_to_name(code) } end
Generate a string containing the names corresponding to the numeric type codes. Sort it by the numeric type code, ascending.
# File lib/dnsruby/resource/NXT.rb, line 207 def codes_to_string(codes) codes.sort.map { |code| code_to_name(code) }.join(' ') end
# File lib/dnsruby/resource/NXT.rb, line 248 def legal_code_value?(code) (1..127).include?(code) end
Convert a type name to its corresponding numeric type code. Names matching /^TYPE(d+)$/ are assumed to have a code corresponding to the numeric value of the substring following 'TYPE'.
# File lib/dnsruby/resource/NXT.rb, line 179 def name_to_code(name) code = Types.to_code(name) if code.nil? matches = /^TYPE(\d+)$/.match(name) code = matches[1].to_i if matches end code end
For the specified string containing names (e.g. 'A NS'), return an array containing the corresponding codes.
# File lib/dnsruby/resource/NXT.rb, line 195 def names_string_to_codes(name_string) names_to_codes(name_string.split(' ')) end
For a given array of type names, return an array of codes.
# File lib/dnsruby/resource/NXT.rb, line 189 def names_to_codes(names) names.map { |s| name_to_code(s) } end