All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jnr.ffi.provider.jffi.ByReferenceParameterConverter Maven / Gradle / Ivy

There is a newer version: 2.2.16
Show newest version
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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy