Class: Zippo::BinaryStructure::BinaryPacker

Inherits:
Object
  • Object
show all
Defined in:
lib/zippo/binary_structure/binary_packer.rb

Class Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io) ⇒ BinaryPacker

Returns a new instance of BinaryPacker.



8
9
10
# File 'lib/zippo/binary_structure/binary_packer.rb', line 8

def initialize(io)
  @io = io
end

Class Attribute Details

.structureObject

Returns the value of attribute structure.



5
6
7
# File 'lib/zippo/binary_structure/binary_packer.rb', line 5

def structure
  @structure
end

Instance Method Details

#pack(obj) ⇒ Object



12
13
14
# File 'lib/zippo/binary_structure/binary_packer.rb', line 12

def pack(obj)
  @io << self.class.structure.fields.map { |f| obj.send f.name }.pack(self.class.structure.fields.map(&:pack).join(""))
end