Class: FFI::StructByReference

Inherits:
Object
  • Object
show all
Includes:
DataConverter
Defined in:
lib/ffi/struct_by_reference.rb

Overview

This class includes the DataConverter module.

Direct Known Subclasses

FFI::Struct::ManagedStructConverter

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(struct_class) ⇒ StructByReference

Returns a new instance of StructByReference.

Parameters:



39
40
41
42
43
44
# File 'lib/ffi/struct_by_reference.rb', line 39

def initialize(struct_class)
  unless Class === struct_class and struct_class < FFI::Struct
    raise TypeError, 'wrong type (expected subclass of FFI::Struct)'
  end
  @struct_class = struct_class
end

Instance Attribute Details

#struct_classObject (readonly)

Returns the value of attribute struct_class.



36
37
38
# File 'lib/ffi/struct_by_reference.rb', line 36

def struct_class
  @struct_class
end

Instance Method Details

#from_native(value, ctx) ⇒ Struct

Create a struct from content of memory value.

Parameters:

Returns:



68
69
70
# File 'lib/ffi/struct_by_reference.rb', line 68

def from_native(value, ctx)
  @struct_class.new(value)
end

#native_typeObject

Always get Type::POINTER.



47
48
49
# File 'lib/ffi/struct_by_reference.rb', line 47

def native_type
  FFI::Type::POINTER
end

#to_native(value, ctx) ⇒ AbstractMemory

Returns Pointer on value.

Parameters:

  • value (nil, Struct)
  • ctx (nil)

Returns:



54
55
56
57
58
59
60
61
62
# File 'lib/ffi/struct_by_reference.rb', line 54

def to_native(value, ctx)
  return Pointer::NULL if value.nil?

  unless @struct_class === value
    raise TypeError, "wrong argument type #{value.class} (expected #{@struct_class})"
  end

  value.pointer
end