Class: DHCP::OptListFixedData

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

Overview

Class for DHCP options that contain lists of fixed sized data

Direct Known Subclasses

OptIPList, OptInt8List, OptStaticRoutes

Class Attribute Summary collapse

Attributes inherited from OptData

#data

Attributes inherited from Opt

#name, #opt

Instance Method Summary collapse

Methods inherited from OptListData

#append, #data=, #each, #get, #initialize, #is_list?, #set, #size, #to_s

Methods inherited from OptData

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

Methods inherited from Opt

#initialize, #opt_header, #to_opt, #to_s

Constructor Details

This class inherits a constructor from DHCP::OptListData

Class Attribute Details

.item_sizeObject

Returns the value of attribute item_size.



299
300
301
# File 'lib/dhcp/options.rb', line 299

def item_size
  @item_size
end

Instance Method Details

#data_to_bin(item) ⇒ Object



313
314
315
316
317
318
319
# File 'lib/dhcp/options.rb', line 313

def data_to_bin(item)  ## Override in child, but call super(item)
                       ## with the resulting translated data after
                       ## data translation so the size check is
                       ## applied (or do a size check in the child):
  raise "Invalid data item length #{item.size} (expected #{self.class.item_size})" unless item.size == self.class.item_size
  item
end

#split_data(data) ⇒ Object



302
303
304
305
306
307
308
309
310
311
# File 'lib/dhcp/options.rb', line 302

def split_data(data)
  raise "Child class #{self.class} MUST override class item_size variable with non-zero value!" if self.class.item_size == 0
  raise "Invalid data length #{data.size} (expected even multiple of #{self.class.item_size})" unless data.size % self.class.item_size == 0
  list = []
  data = data.dup
  while data.size > 0
    list << bin_to_data(data.slice!(0,self.class.item_size))
  end
  list
end