class DHCP::OptInt8
Class for single-byte unsigned integer value DHCP options Also acts as parent class for fixed-sized multi-byte value DHCP options
Public Instance Methods
bin_to_data(data)
click to toggle source
# File lib/dhcp/options.rb, line 430 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 418 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.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.size}" if bytes.size > self.class.size 0.chr * (self.class.size - bytes.size) + bytes end
to_s()
click to toggle source
# File lib/dhcp/options.rb, line 434 def to_s opt_header + "=#{self.get}" end