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.



91
92
93
# File 'lib/fiddle/pack.rb', line 91

def initialize(types)
  parse_types(types)
end

Class Method Details

.[](*types) ⇒ Object



87
88
89
# File 'lib/fiddle/pack.rb', line 87

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

Instance Method Details

#pack(ary) ⇒ Object



99
100
101
102
103
104
105
106
107
108
109
110
111
# File 'lib/fiddle/pack.rb', line 99

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



95
96
97
# File 'lib/fiddle/pack.rb', line 95

def size()
  @size
end

#unpack(ary) ⇒ Object



113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/fiddle/pack.rb', line 113

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