Module: Unpacker

Included in:
ExternObject
Defined in:
lib/white_gold/abi/unpacker.rb

Instance Method Summary collapse

Instance Method Details

#abi_unpack(host, type, object) ⇒ Object



24
25
26
# File 'lib/white_gold/abi/unpacker.rb', line 24

def abi_unpack host, type, object
  Interface.parse_unpacker(type).call host, object
end

#abi_unpacker(base, &body) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
# File 'lib/white_gold/abi/unpacker.rb', line 4

def abi_unpacker base, &body
  if block_given?
    define_method abi_unpacker_method_name(base), &body
  elsif base.is_a? Module
    define_method abi_unpacker_method_name(base) do |o|
      base.new pointer: o
    end
  else
    raise "..."
  end
end

#abi_unpacker_method_name(base) ⇒ Object



16
17
18
19
20
21
22
# File 'lib/white_gold/abi/unpacker.rb', line 16

def abi_unpacker_method_name base
  case base
  when String then "abi_unpack#{Interface.abi_const_string_method_suffix base}".to_sym
  when Symbol then base.to_s.start_with?("_") ? "abi_unpack#{base}".to_sym : base
  else "abi_unpack#{Interface.abi_const_string_method_suffix base.name}".to_sym
  end
end