jnr.ffi.byref
Class ByteByReference

java.lang.Object
  extended by java.lang.Number
      extended by jnr.ffi.byref.AbstractNumberReference<java.lang.Byte>
          extended by jnr.ffi.byref.ByteByReference
All Implemented Interfaces:
java.io.Serializable, ByReference<java.lang.Byte>

public final class ByteByReference
extends AbstractNumberReference<java.lang.Byte>

ByteByReference is used when the address of a primitive byte value must be passed as a parameter to a function.

For example, the following C code,

 extern void get_a(char *ap);

 int foo(void) {
     char a;
     // pass a reference to 'a' so get_a() can fill it out
     get_a(&a);

     return a;
 }
 
 

Would be declared in java as

 interface Lib {
     void get_a(@Out ByteByReference ap);
 }
 
 

and used like this

 ByteByReference ap = new ByteByReference();
 lib.get_a(ap);
 System.out.printf("a from lib=%d\n", a.byteValue());
 

See Also:
Serialized Form

Constructor Summary
ByteByReference()
          Creates a new reference to a byte value initialized to zero.
ByteByReference(byte value)
          Creates a new reference to a byte value
ByteByReference(java.lang.Byte value)
          Creates a new reference to a byte value
 
Method Summary
 void marshal(Pointer buffer, long offset)
          Copies the Byte value to native memory
 int nativeSize(Runtime runtime)
          Gets the native size of type of reference in bytes.
 void unmarshal(Pointer buffer, long offset)
          Copies the Byte value from native memory
 
Methods inherited from class jnr.ffi.byref.AbstractNumberReference
byteValue, checkNull, doubleValue, floatValue, getValue, intValue, longValue, shortValue
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ByteByReference

public ByteByReference()
Creates a new reference to a byte value initialized to zero.


ByteByReference

public ByteByReference(java.lang.Byte value)
Creates a new reference to a byte value

Parameters:
value - the initial native value

ByteByReference

public ByteByReference(byte value)
Creates a new reference to a byte value

Parameters:
value - the initial native value
Method Detail

marshal

public void marshal(Pointer buffer,
                    long offset)
Copies the Byte value to native memory

Parameters:
buffer - the native memory buffer

unmarshal

public void unmarshal(Pointer buffer,
                      long offset)
Copies the Byte value from native memory

Parameters:
buffer - the native memory buffer.

nativeSize

public final int nativeSize(Runtime runtime)
Gets the native size of type of reference in bytes.

Returns:
the size of a byte in bytes


Copyright © 2012. All Rights Reserved.