Class: Zippo::BinaryStructure::BinaryUnpacker
- Inherits:
-
Object
- Object
- Zippo::BinaryStructure::BinaryUnpacker
- Defined in:
- lib/zippo/binary_structure/binary_unpacker.rb
Class Attribute Summary collapse
-
.structure ⇒ Object
Returns the value of attribute structure.
Instance Method Summary collapse
-
#initialize(io) ⇒ BinaryUnpacker
constructor
A new instance of BinaryUnpacker.
-
#unpack ⇒ Object
default implementation note that this will generally be overridden by define_unpack_method for optimisation.
Constructor Details
#initialize(io) ⇒ BinaryUnpacker
Returns a new instance of BinaryUnpacker.
10 11 12 13 |
# File 'lib/zippo/binary_structure/binary_unpacker.rb', line 10 def initialize(io) @io = io @io = StringIO.new @io if @io.is_a? String end |
Class Attribute Details
.structure ⇒ Object
Returns the value of attribute structure.
7 8 9 |
# File 'lib/zippo/binary_structure/binary_unpacker.rb', line 7 def structure @structure end |
Instance Method Details
#unpack ⇒ Object
default implementation note that this will generally be overridden by define_unpack_method for optimisation
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/zippo/binary_structure/binary_unpacker.rb', line 18 def unpack self.class.structure.owner_class.new.tap do |obj| self.class.structure.fields.each do |field| if field.[:size] obj.instance_variable_set "@#{field.name}", @io.read(obj.send field.[:size]) else buf = @io.read field.width obj.instance_variable_set "@#{field.name}", buf.unpack(field.pack).first end end end end |