Package jnr.ffi
Class Struct
java.lang.Object
jnr.ffi.Struct
- Direct Known Subclasses:
Union
Representation of C structures in java.
Note: This class is not threadsafe.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected class
Base class for Boolean fieldsprotected class
Base implementation of Memberclass
Represents a native memory address.static final class
class
class
final class
final class
final class
final class
A normal C boolean - 1 byte in sizefinal class
final class
final class
final class
final class
final class
final class
class
Struct.Enum<T extends Enum<T>>
class
Struct.Enum16<E extends Enum<E>>
class
Struct.Enum32<E extends Enum<E>>
class
Struct.Enum64<E extends Enum<E>>
class
Struct.Enum8<E extends Enum<E>>
An 8 bit enum field.protected class
Base for all the Enum fields.class
Struct.EnumLong<E extends Enum<E>>
class
final class
final class
final class
final class
final class
final class
final class
final class
final class
final class
final class
final class
final class
class
final class
final class
final class
protected class
Interface all Struct members must implement.final class
final class
class
Base class for all Number structure fields.final class
static final class
protected final class
Specialized padding fields for structs.final class
class
Represents a native memory address.class
final class
final class
class
A 16 bit signed integer field.class
A 32 bit signed integer field.class
A 64 bit signed integer field.class
An 8 bit signed integerclass
A native long integer field.final class
final class
final class
final class
class
class
Struct.StructRef<T extends Struct>
Represents a reference to a Struct or and array of Structsfinal class
final class
final class
final class
final class
final class
final class
final class
final class
class
A 16 bit signed integer field.class
A 32 bit signed integer field.class
A 64 bit unsigned integer field.class
An 8 bit unsigned integerclass
A native long integer field.class
class
class
class
final class
A Windows BOOL - 4 bytesfinal class
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic int
protected final Struct.Address[]
array
(Struct.Address[] array) Creates an array ofAddress
instances.protected final Struct.Double[]
array
(Struct.Double[] array) Creates an array ofDouble
instances.protected <T extends Enum<T>>
Struct.Enum<T>[]array
(Struct.Enum<T>[] array, Class<T> enumClass) Creates an array ofEnum
instances.protected <T extends Enum<T>>
Struct.Enum16<T>[]array
(Struct.Enum16<T>[] array, Class<T> enumClass) Creates an array ofEnum16
instances.protected <T extends Enum<T>>
Struct.Enum32<T>[]array
(Struct.Enum32<T>[] array, Class<T> enumClass) Creates an array ofEnum32
instances.protected <T extends Enum<T>>
Struct.Enum64<T>[]array
(Struct.Enum64<T>[] array, Class<T> enumClass) Creates an array ofEnum64
instances.protected <T extends Enum<T>>
Struct.Enum8<T>[]array
(Struct.Enum8<T>[] array, Class<T> enumClass) Creates an array ofEnum8
instances.protected final Struct.Float[]
array
(Struct.Float[] array) Creates an array ofFloat
instances.protected final Struct.Pointer[]
array
(Struct.Pointer[] array) Creates an array ofPointer
instances.protected final Struct.Signed16[]
array
(Struct.Signed16[] array) Creates an array ofSigned16
instances.protected final Struct.Signed32[]
array
(Struct.Signed32[] array) Creates an array ofSigned32
instances.protected final Struct.Signed64[]
array
(Struct.Signed64[] array) Creates an array ofSigned64
instances.protected final Struct.Signed8[]
array
(Struct.Signed8[] array) Creates an array ofSigned8
instances.protected final Struct.SignedLong[]
array
(Struct.SignedLong[] array) Creates an array ofSignedLong
instances.protected final Struct.Unsigned16[]
array
(Struct.Unsigned16[] array) Creates an array ofUnsigned16
instances.protected final Struct.Unsigned32[]
array
(Struct.Unsigned32[] array) Creates an array ofUnsigned32
instances.protected final Struct.Unsigned64[]
array
(Struct.Unsigned64[] array) Creates an array ofUnsigned64
instances.protected final Struct.Unsigned8[]
array
(Struct.Unsigned8[] array) Creates an array ofUnsigned8
instances.protected final Struct.UnsignedLong[]
array
(Struct.UnsignedLong[] array) Creates an array ofUnsignedLong
instances.protected Struct.UTF8String[]
array
(Struct.UTF8String[] array, int stringLength) Creates an array ofUTF8String
instances.protected <T extends Struct.Member>
T[]array
(T[] array) Creates an array ofMember
instances.protected final void
Starts an array construction sessionprotected final void
arrayEnd()
Ends an array construction sessionstatic <T extends Struct>
T[]protected final <T> Struct.Function
<T> static Pointer
static Pointer
final Runtime
protected final <T extends Struct>
TCreates inner Structs in Struct definitions.protected final <T extends Struct>
Tinner
(T struct) Creates inner Structs in Struct definitions.static boolean
static <T extends Struct>
intGets the size of a Struct type in bytesstatic <T extends Struct>
intGets the size of a Struct type in bytesstatic int
Gets the size of a Struct instance in bytestoString()
Returns a human readableString
representation of the structure.final void
Uses the specified memory address as the backing store for this structure.
-
Constructor Details
-
Struct
Creates a newStruct
.- Parameters:
runtime
- The current runtime.
-
Struct
-
Struct
-
Struct
Creates a newStruct
.- Parameters:
runtime
- the current jnr-ffi runtimeisUnion
- if this Struct is a Union
-
-
Method Details
-
getRuntime
-
useMemory
Uses the specified memory address as the backing store for this structure.- Parameters:
address
- the native memory area.
-
getMemory
-
getMemory
-
size
Gets the size of a Struct instance in bytes- Parameters:
struct
- the Struct instance- Returns:
- the size of the Struct in bytes
-
size
Gets the size of a Struct type in bytes -
size
Gets the size of a Struct type in bytes- Type Parameters:
T
- the Struct type- Parameters:
structClass
- theClass
of the Struct- Returns:
- the size of the Struct in bytes
-
alignment
-
isDirect
-
arrayOf
-
toString
Returns a human readableString
representation of the structure. -
arrayBegin
protected final void arrayBegin()Starts an array construction session -
arrayEnd
protected final void arrayEnd()Ends an array construction session -
array
Creates an array ofMember
instances.- Type Parameters:
T
- The type of theMember
subclass to create.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofEnum8
instances.- Type Parameters:
T
- The type of thejava.lang.Enum
- Parameters:
array
- the array to store the instances inenumClass
- class ofjava.lang.Enum
, theseEnum8
instances will represent- Returns:
- the array that was passed in
-
array
protected <T extends Enum<T>> Struct.Enum16<T>[] array(Struct.Enum16<T>[] array, Class<T> enumClass) Creates an array ofEnum16
instances.- Type Parameters:
T
- The type of thejava.lang.Enum
- Parameters:
array
- the array to store the instances inenumClass
- class ofjava.lang.Enum
, theseEnum16
instances will represent- Returns:
- the array that was passed in
-
array
protected <T extends Enum<T>> Struct.Enum32<T>[] array(Struct.Enum32<T>[] array, Class<T> enumClass) Creates an array ofEnum32
instances.- Type Parameters:
T
- The type of thejava.lang.Enum
- Parameters:
array
- the array to store the instances inenumClass
- class ofjava.lang.Enum
, theseEnum32
instances will represent- Returns:
- the array that was passed in
-
array
protected <T extends Enum<T>> Struct.Enum64<T>[] array(Struct.Enum64<T>[] array, Class<T> enumClass) Creates an array ofEnum64
instances.- Type Parameters:
T
- The type of thejava.lang.Enum
- Parameters:
array
- the array to store the instances inenumClass
- class ofjava.lang.Enum
, theseEnum64
instances will represent- Returns:
- the array that was passed in
-
array
Creates an array ofEnum
instances.- Type Parameters:
T
- The type of thejava.lang.Enum
- Parameters:
array
- the array to store the instances inenumClass
- class ofjava.lang.Enum
, theseEnum
instances will represent- Returns:
- the array that was passed in
-
array
Creates an array ofStruct
instances.- Type Parameters:
T
- the type of Struct- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofSigned8
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofUnsigned8
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofSigned16
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofUnsigned16
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofSigned32
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofUnsigned32
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofSigned64
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofUnsigned64
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofSignedLong
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofUnsignedLong
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofFloat
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofDouble
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofAddress
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofPointer
instances.- Parameters:
array
- the array to store the instances in- Returns:
- the array that was passed in
-
array
Creates an array ofUTF8String
instances.- Parameters:
array
- the array to store the instances instringLength
- length of each string in array- Returns:
- the array that was passed in
-
inner
Creates inner Structs in Struct definitions. Example:public class InnerStruct extends Struct { public final Signed32 innerInt32 = new Signed32(); public final Double innerDouble = new Double(); public InnerStruct(Runtime runtime) {super(runtime);} } public class MyStruct extends Struct { public final Signed32 myInt32 = new Signed32(); public final InnerStruct myInnerStruct = inner(new InnerStruct()); public MyStruct(Runtime runtime) {super(runtime);} }
- Type Parameters:
T
- the type of the inner Struct- Parameters:
struct
- an instance of the inner Struct- Returns:
- the instance of the inner Struct of type
Struct
-
inner
Creates inner Structs in Struct definitions. Example:public class InnerStruct extends Struct { public final Signed32 innerInt32 = new Signed32(); public final Double innerDouble = new Double(); public InnerStruct(Runtime runtime) {super(runtime);} } public class MyStruct extends Struct { public final Signed32 myInt32 = new Signed32(); public final InnerStruct myInnerStruct = inner(InnerStruct.class); public MyStruct(Runtime runtime) {super(runtime);} }
-
function
-