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

binary_string_to_codes(binary_string) click to toggle source

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
binary_string_to_names(binary_string) click to toggle source

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
code_to_name(number) click to toggle source

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
codes_to_binary_string(codes) click to toggle source

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
codes_to_names(codes) click to toggle source

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
codes_to_string(codes) click to toggle source

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
name_to_code(name) click to toggle source

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
names_string_to_codes(name_string) click to toggle source

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
names_to_codes(names) click to toggle source

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