class Rstruct::ContainerType
Public Class Methods
new(*args, &block)
click to toggle source
Calls superclass method
# File lib/rstruct/base_types/container_type.rb, line 54 def initialize(*args, &block) @countainer = true super(*args, &block) end
Public Instance Methods
claim_value(vals, obj=nil)
click to toggle source
# File lib/rstruct/base_types/container_type.rb, line 100 def claim_value(vals, obj=nil) if @claim_cb @claim_cb.call(vals, obj) else # create our struct container s = instance() # iterate through the fields assigning values in the # container and pass it along with values to each # field's claim_value method. self.fields.do {|f| s[f.name] = f.typ.claim_value(vals,s) } return s end end
field_names()
click to toggle source
# File lib/rstruct/base_types/container_type.rb, line 83 def field_names self.fields.map{|f| f.name } end
field_types()
click to toggle source
# File lib/rstruct/base_types/container_type.rb, line 87 def field_types self.fields.map{|f| f.typ } end
format()
click to toggle source
# File lib/rstruct/base_types/container_type.rb, line 63 def format self.fields.map do |f| if f.groupable? f.format else return nil end end.join end
groupable?()
click to toggle source
# File lib/rstruct/base_types/container_type.rb, line 59 def groupable? self.fields.find {|f| not f.groupable? }.nil? end
read(raw, obj=nil)
click to toggle source
# File lib/rstruct/base_types/container_type.rb, line 91 def read(raw, obj=nil) raw = StringIO.new(raw) if raw.is_a?(String) obj = self.instance() fields.each do |f| obj[f.name] = f.typ.read(raw, obj) end return obj end
sizeof()
click to toggle source
# File lib/rstruct/base_types/container_type.rb, line 73 def sizeof self.fields.inject(0) do |s,v| if vs=v.typ.sizeof s+=vs else return nil end end end