123456789_123456789_123456789_123456789_123456789_

Class: FFI::StructByReference

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Subclasses:
Super Chains via Extension / Inclusion / Inheritance
Instance Chain:
Inherits: Object
Defined in: lib/ffi/struct_by_reference.rb

Overview

This class includes the DataConverter module.

Class Method Summary

Instance Attribute Summary

Instance Method Summary

DataConverter - Included

#from_native

Convert from a native type.

#native_type

Get native type.

#to_native

Convert to a native type.

Constructor Details

.new(struct_class) ⇒ StructByReference

Parameters:

[ GitHub ]

  
# 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_class (readonly)

[ GitHub ]

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

attr_reader :struct_class

Instance Method Details

#from_native(value, ctx) ⇒ Struct

Create a struct from content of memory value.

Parameters:

[ GitHub ]

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

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

#native_type

Always get Type::POINTER.

[ GitHub ]

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

def native_type
  FFI::Type::POINTER
end

#to_native(value, ctx) ⇒ AbstractMemory

Parameters:

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

Returns:

[ GitHub ]

  
# 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