Class: Fiddle::Packer

Inherits:
Object
  • Object
show all
Includes:
PackInfo
Defined in:
lib/fiddle/pack.rb

Overview

:nodoc: all

Constant Summary

Constants included from PackInfo

Fiddle::PackInfo::ALIGN_MAP, Fiddle::PackInfo::PACK_MAP, Fiddle::PackInfo::SIZE_MAP

Class Method Summary collapse

Instance Method Summary collapse

Methods included from PackInfo

align

Constructor Details

#initialize(types) ⇒ Packer

Returns a new instance of Packer.



72
73
74
# File 'lib/fiddle/pack.rb', line 72

def initialize(types)
  parse_types(types)
end

Class Method Details

.[](*types) ⇒ Object



68
69
70
# File 'lib/fiddle/pack.rb', line 68

def self.[](*types)
  new(types)
end

Instance Method Details

#pack(ary) ⇒ Object



80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/fiddle/pack.rb', line 80

def pack(ary)
  case SIZEOF_VOIDP
  when SIZEOF_LONG
    ary.pack(@template)
  else
    if defined?(TYPE_LONG_LONG) and
      SIZEOF_VOIDP == SIZEOF_LONG_LONG
      ary.pack(@template)
    else
      raise(RuntimeError, "sizeof(void*)?")
    end
  end
end

#sizeObject



76
77
78
# File 'lib/fiddle/pack.rb', line 76

def size()
  @size
end

#unpack(ary) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/fiddle/pack.rb', line 94

def unpack(ary)
  case SIZEOF_VOIDP
  when SIZEOF_LONG
    ary.join().unpack(@template)
  else
    if defined?(TYPE_LONG_LONG) and
      SIZEOF_VOIDP == SIZEOF_LONG_LONG
      ary.join().unpack(@template)
    else
      raise(RuntimeError, "sizeof(void*)?")
    end
  end
end