Class: DHCP::OptInt8
- Inherits:
-
OptFixedData
- Object
- Opt
- OptData
- OptFixedData
- DHCP::OptInt8
- Defined in:
- lib/dhcp/options.rb
Overview
Class for single-byte unsigned integer value DHCP options Also acts as parent class for fixed-sized multi-byte value DHCP options
Instance Attribute Summary
Attributes inherited from OptData
Attributes inherited from Opt
Instance Method Summary collapse
Methods inherited from OptFixedData
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::OptFixedData
Instance Method Details
#bin_to_data(data) ⇒ Object
463 464 465 |
# File 'lib/dhcp/options.rb', line 463 def bin_to_data(data) data.each_byte.inject(0){|sum,byte| sum<<8|byte} end |
#data_to_bin(data) ⇒ Object
451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/dhcp/options.rb', line 451 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 ⇒ Object
467 468 469 |
# File 'lib/dhcp/options.rb', line 467 def to_s opt_header + "=#{self.get}" end |