class FFI::StructByReference

This class includes the {FFI::DataConverter} module.

Attributes

Public Class Methods

@param [Struct] struct_class

# 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

Public Instance Methods

@param [AbstractMemory] value @param [nil] ctx @return [Struct] Create a struct from content of memory value.

# File lib/ffi/struct_by_reference.rb, line 68
def from_native(value, ctx)
  @struct_class.new(value)
end

Always get {FFI::Type}::POINTER.

# File lib/ffi/struct_by_reference.rb, line 47
def native_type
  FFI::Type::POINTER
end

@param [nil, Struct] value @param [nil] ctx @return [AbstractMemory] Pointer on value.

# 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