Package jnr.ffi.byref
Class NumberByReference
- java.lang.Object
-
- java.lang.Number
-
- jnr.ffi.byref.AbstractNumberReference<java.lang.Number>
-
- jnr.ffi.byref.NumberByReference
-
- All Implemented Interfaces:
java.io.Serializable
,ByReference<java.lang.Number>
public class NumberByReference extends AbstractNumberReference<java.lang.Number>
NumberByReference is used when the address of a primitive integral value must be passed as a parameter to a function, but the exact type is system dependent.For example, the following C code,
extern void get_size(ssize_t *sp); ssize_t foo(void) { ssize_t n; // pass a reference to 'n' so get_size() can fill it out get_size(&n); return n; }
Would be declared in java as
interface Lib { void get_size(@Out NumberByReference ap); }
and used like this
NumberByReference size = new NumberByReference(ssize_t); lib.get_size(size); System.out.printf("size from lib=%d\n", size.longValue());
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description NumberByReference(TypeAlias typeAlias)
NumberByReference(TypeAlias typeAlias, java.lang.Number value)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
fromNative(Runtime runtime, Pointer memory, long offset)
Copies the java value from native memoryint
nativeSize(Runtime runtime)
Gets the size of the native buffer required to store the valuevoid
toNative(Runtime runtime, Pointer memory, long offset)
Copies the java value to native memory-
Methods inherited from class jnr.ffi.byref.AbstractNumberReference
byteValue, checkNull, doubleValue, floatValue, getValue, intValue, longValue, shortValue
-
-
-
-
Method Detail
-
nativeSize
public int nativeSize(Runtime runtime)
Description copied from interface:ByReference
Gets the size of the native buffer required to store the value- Parameters:
runtime
- The current runtime.- Returns:
- the size in bytes of the native type
-
fromNative
public void fromNative(Runtime runtime, Pointer memory, long offset)
Description copied from interface:ByReference
Copies the java value from native memory- Parameters:
runtime
- The current runtime.memory
- the native memory buffer.offset
- The offset of the field.
-
toNative
public void toNative(Runtime runtime, Pointer memory, long offset)
Description copied from interface:ByReference
Copies the java value to native memory- Parameters:
runtime
- The current runtime.memory
- The native memory buffer.offset
- The offset of the field.
-
-