Class: Fiddle::Packer
Overview
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.
85
86
87
|
# File 'ext/fiddle/lib/fiddle/pack.rb', line 85
def initialize(types)
parse_types(types)
end
|
Class Method Details
.[](*types) ⇒ Object
81
82
83
|
# File 'ext/fiddle/lib/fiddle/pack.rb', line 81
def self.[](*types)
new(types)
end
|
Instance Method Details
#pack(ary) ⇒ Object
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'ext/fiddle/lib/fiddle/pack.rb', line 93
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
|
89
90
91
|
# File 'ext/fiddle/lib/fiddle/pack.rb', line 89
def size()
@size
end
|
#unpack(ary) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
|
# File 'ext/fiddle/lib/fiddle/pack.rb', line 107
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
|