Class: DHCP::OptFixedData

Inherits:
OptData show all
Defined in:
lib/dhcp/options.rb

Overview

Class for DHCP options containing a fixed number of bytes

Direct Known Subclasses

OptBool, OptIP, OptInt8

Class Attribute Summary collapse

Attributes inherited from OptData

#data

Attributes inherited from Opt

#name, #opt

Instance Method Summary collapse

Methods inherited from OptData

#bin_to_data, #data_to_bin, #get, #opt_header, #set, #to_opt, #to_s

Methods inherited from Opt

#opt_header, #to_opt, #to_s

Constructor Details

#initialize(opt, name, data = nil) ⇒ OptFixedData

Returns a new instance of OptFixedData.



120
121
122
123
124
# File 'lib/dhcp/options.rb', line 120

def initialize(opt, name, data=nil)
  super(opt, name, data)
  ## Prefill with zeros if needed:
  @data = 0.chr * self.class.size if data.nil? && self.class.size > 0
end

Class Attribute Details

.sizeObject

Returns the value of attribute size.



117
118
119
# File 'lib/dhcp/options.rb', line 117

def size
  @size
end

Instance Method Details

#data=(data) ⇒ Object



126
127
128
129
# File 'lib/dhcp/options.rb', line 126

def data=(data)
  raise "Invalid size for #{self.class} (expected #{size} bytes, not #{data.size} bytes)" unless self.class.size == data.size
  super(data)
end