Class: Rstruct::ContainerType
- Inherits:
-
Type
- Object
- Type
- Rstruct::ContainerType
show all
- Includes:
- Packable
- Defined in:
- lib/rstruct/base_types/container_type.rb
Instance Attribute Summary
Attributes inherited from Type
#name, #params
Instance Method Summary
collapse
Methods included from Packable
#pack_value
Methods inherited from Type
#claim_value, #container?, #register
Constructor Details
#initialize(*args, &block) ⇒ ContainerType
Returns a new instance of ContainerType.
54
55
56
57
|
# File 'lib/rstruct/base_types/container_type.rb', line 54
def initialize(*args, &block)
@countainer = true
super(*args, &block)
end
|
Instance Method Details
#field_names ⇒ Object
83
84
85
|
# File 'lib/rstruct/base_types/container_type.rb', line 83
def field_names
@field_names ||= self.fields.map{|f| f.name }
end
|
#field_types ⇒ Object
87
88
89
|
# File 'lib/rstruct/base_types/container_type.rb', line 87
def field_types
@field_types ||= self.fields.map{|f| f.typ }
end
|
63
64
65
66
67
68
69
70
71
|
# 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? ⇒ Boolean
59
60
61
|
# 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) ⇒ Object
91
92
93
94
95
96
97
98
|
# 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.read(raw, obj)
end
return obj
end
|
#sizeof ⇒ Object
73
74
75
76
77
78
79
80
81
|
# 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
|