Class FFIType

All Implemented Interfaces:
AutoCloseable, NativeResource, Pointer

public class FFIType extends Struct<FFIType> implements NativeResource

 struct ffi_type {
     size_t size;
     unsigned short alignment;
     unsigned short type;
     ffi_type * elements;
 }
  • Field Details

    • SIZEOF

      public static final int SIZEOF
      The struct size in bytes.
    • ALIGNOF

      public static final int ALIGNOF
      The struct alignment in bytes.
    • SIZE

      public static final int SIZE
      The struct member offsets.
    • ALIGNMENT

      public static final int ALIGNMENT
      The struct member offsets.
    • TYPE

      public static final int TYPE
      The struct member offsets.
    • ELEMENTS

      public static final int ELEMENTS
      The struct member offsets.
  • Constructor Details

    • FFIType

      public FFIType(ByteBuffer container)
      Creates a FFIType instance at the current position of the specified ByteBuffer container. Changes to the buffer's content will be visible to the struct instance and vice versa.

      The created instance holds a strong reference to the container object.

  • Method Details

    • sizeof

      public int sizeof()
      Description copied from class: Struct
      Returns sizeof(struct).
      Specified by:
      sizeof in class Struct<FFIType>
    • size

      public long size()
      Returns:
      the value of the size field.
    • alignment

      public short alignment()
      Returns:
      the value of the alignment field.
    • type

      public short type()
      Returns:
      the value of the type field.
    • elements

      public @Nullable PointerBuffer elements(int capacity)
      Returns:
      a PointerBuffer view of the data pointed to by the elements field.
    • size

      public FFIType size(long value)
      Sets the specified value to the size field.
    • alignment

      public FFIType alignment(short value)
      Sets the specified value to the alignment field.
    • type

      public FFIType type(short value)
      Sets the specified value to the type field.
    • elements

      public FFIType elements(@Nullable PointerBuffer value)
      Sets the address of the specified PointerBuffer to the elements field.
    • set

      public FFIType set(long size, short alignment, short type, @Nullable PointerBuffer elements)
      Initializes this struct with the specified values.
    • set

      public FFIType set(FFIType src)
      Copies the specified struct data to this struct.
      Parameters:
      src - the source struct
      Returns:
      this struct
    • malloc

      public static FFIType malloc()
      Returns a new FFIType instance allocated with memAlloc. The instance must be explicitly freed.
    • calloc

      public static FFIType calloc()
      Returns a new FFIType instance allocated with memCalloc. The instance must be explicitly freed.
    • create

      public static FFIType create()
      Returns a new FFIType instance allocated with BufferUtils.
    • create

      public static FFIType create(long address)
      Returns a new FFIType instance for the specified memory address.
    • createSafe

      public static @Nullable FFIType createSafe(long address)
      Like create, but returns null if address is NULL.
    • malloc

      public static FFIType.Buffer malloc(int capacity)
      Returns a new FFIType.Buffer instance allocated with memAlloc. The instance must be explicitly freed.
      Parameters:
      capacity - the buffer capacity
    • calloc

      public static FFIType.Buffer calloc(int capacity)
      Returns a new FFIType.Buffer instance allocated with memCalloc. The instance must be explicitly freed.
      Parameters:
      capacity - the buffer capacity
    • create

      public static FFIType.Buffer create(int capacity)
      Returns a new FFIType.Buffer instance allocated with BufferUtils.
      Parameters:
      capacity - the buffer capacity
    • create

      public static FFIType.Buffer create(long address, int capacity)
      Create a FFIType.Buffer instance at the specified memory.
      Parameters:
      address - the memory address
      capacity - the buffer capacity
    • createSafe

      public static @Nullable FFIType.Buffer createSafe(long address, int capacity)
      Like create, but returns null if address is NULL.
    • malloc

      public static FFIType malloc(MemoryStack stack)
      Returns a new FFIType instance allocated on the specified MemoryStack.
      Parameters:
      stack - the stack from which to allocate
    • calloc

      public static FFIType calloc(MemoryStack stack)
      Returns a new FFIType instance allocated on the specified MemoryStack and initializes all its bits to zero.
      Parameters:
      stack - the stack from which to allocate
    • malloc

      public static FFIType.Buffer malloc(int capacity, MemoryStack stack)
      Returns a new FFIType.Buffer instance allocated on the specified MemoryStack.
      Parameters:
      capacity - the buffer capacity
      stack - the stack from which to allocate
    • calloc

      public static FFIType.Buffer calloc(int capacity, MemoryStack stack)
      Returns a new FFIType.Buffer instance allocated on the specified MemoryStack and initializes all its bits to zero.
      Parameters:
      capacity - the buffer capacity
      stack - the stack from which to allocate
    • nsize

      public static long nsize(long struct)
      Unsafe version of size().
    • nalignment

      public static short nalignment(long struct)
      Unsafe version of alignment().
    • ntype

      public static short ntype(long struct)
      Unsafe version of type().
    • nelements

      public static @Nullable PointerBuffer nelements(long struct, int capacity)
      Unsafe version of elements.
    • nsize

      public static void nsize(long struct, long value)
      Unsafe version of size.
    • nalignment

      public static void nalignment(long struct, short value)
      Unsafe version of alignment.
    • ntype

      public static void ntype(long struct, short value)
      Unsafe version of type.
    • nelements

      public static void nelements(long struct, @Nullable PointerBuffer value)
      Unsafe version of elements.