jnr.ffi.provider.jffi.ByReferenceParameterConverter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jnr-unixsocket-nodep Show documentation
Show all versions of jnr-unixsocket-nodep Show documentation
com.github.jnr:jnr-unixsocket with orh.objectweb.asm shaded
package jnr.ffi.provider.jffi;
import jnr.ffi.Memory;
import jnr.ffi.Pointer;
import jnr.ffi.byref.ByReference;
import jnr.ffi.mapper.ToNativeContext;
import jnr.ffi.mapper.ToNativeConverter;
import jnr.ffi.provider.ParameterFlags;
/**
*
*/
public final class ByReferenceParameterConverter implements ToNativeConverter, ToNativeConverter.PostInvocation {
final NativeRuntime runtime = NativeRuntime.getInstance();
private final int flags;
public ByReferenceParameterConverter(int flags) {
this.flags = flags;
}
public void postInvoke(ByReference byReference, Pointer pointer, ToNativeContext context) {
if (ParameterFlags.isOut(flags)) {
byReference.unmarshal(pointer, 0);
}
}
public Pointer toNative(ByReference value, ToNativeContext context) {
Pointer memory = Memory.allocate(runtime, value.nativeSize(runtime));
if (ParameterFlags.isIn(flags)) {
value.marshal(memory, 0);
}
return memory;
}
public Class nativeType() {
return Pointer.class;
}
}