class DHCP::OptInt8List

Class for DHCP options containing a list of 8-bit integers (like lists of requested DHCP options). Also acts as parent class to lists of larger fixed-sized numeric types.

Public Instance Methods

bin_to_data(data) click to toggle source
# File lib/dhcp/options.rb, line 469
def bin_to_data(data)
  data.each_byte.inject(0){|sum,byte| sum<<8|byte}
end
data_to_bin(data) click to toggle source
# File lib/dhcp/options.rb, line 473
def data_to_bin(data)
  raise "Invalid numeric data" unless data.is_a?(Fixnum) && data >= 0
  raise "Invalid number" unless data == data & ([0xff] * self.class.item_size).inject(0){|sum,byte| sum<<8|byte}
  bytes = ''
  while data != 0
    bytes = (data & 0xff).chr + bytes
    data >>= 8
  end
  raise "Impossible: Numeric byte size #{bytes.size} exceeds #{self.class.item_size}" if bytes.size > self.class.item_size
  0.chr * (self.class.item_size - bytes.size) + bytes
end
to_s() click to toggle source
# File lib/dhcp/options.rb, line 485
def to_s
  opt_header + '=[' + map{|x| x.to_s}.join(',') + ']'
end