Class: DHCP::OptInt8List
- Inherits:
-
OptListFixedData
- Object
- Opt
- OptData
- OptListData
- OptListFixedData
- DHCP::OptInt8List
- Defined in:
- lib/dhcp/options.rb
Overview
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.
Direct Known Subclasses
Instance Attribute Summary
Attributes inherited from OptData
Attributes inherited from Opt
Instance Method Summary collapse
Methods inherited from OptListFixedData
Methods inherited from OptListData
#append, #data=, #each, #get, #initialize, #is_list?, #set, #size, #split_data
Methods inherited from OptData
#get, #initialize, #opt_header, #set, #to_opt
Methods inherited from Opt
#initialize, #opt_header, #to_opt
Constructor Details
This class inherits a constructor from DHCP::OptListData
Instance Method Details
#bin_to_data(data) ⇒ Object
502 503 504 |
# File 'lib/dhcp/options.rb', line 502 def bin_to_data(data) data.each_byte.inject(0){|sum,byte| sum<<8|byte} end |
#data_to_bin(data) ⇒ Object
506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/dhcp/options.rb', line 506 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 ⇒ Object
518 519 520 |
# File 'lib/dhcp/options.rb', line 518 def to_s opt_header + '=[' + map{|x| x.to_s}.join(',') + ']' end |