Search in sources :

Example 1 with CCharPointerBinaryOutput

use of org.graalvm.nativebridge.BinaryOutput.CCharPointerBinaryOutput in project graal by oracle.

the class JNINativeMarshallerAdapter method marshall.

@Override
public JObject marshall(JNIEnv env, T object) {
    if (object == null) {
        return WordFactory.nullPointer();
    }
    int bufSize = BUFFER_SIZE;
    CCharPointer buffer = StackValue.get(bufSize);
    try (CCharPointerBinaryOutput out = BinaryOutput.create(buffer, bufSize, false)) {
        binaryMarshaller.write(out, object);
        int len = out.getPosition();
        JByteArray binaryData = JNIUtil.NewByteArray(env, len);
        JNIUtil.SetByteArrayRegion(env, binaryData, 0, len, out.getAddress());
        return binaryData;
    } catch (IOException e) {
        throw new AssertionError(e.getMessage(), e);
    }
}
Also used : JByteArray(org.graalvm.jniutils.JNI.JByteArray) CCharPointerBinaryOutput(org.graalvm.nativebridge.BinaryOutput.CCharPointerBinaryOutput) IOException(java.io.IOException) CCharPointer(org.graalvm.nativeimage.c.type.CCharPointer)

Aggregations

IOException (java.io.IOException)1 JByteArray (org.graalvm.jniutils.JNI.JByteArray)1 CCharPointerBinaryOutput (org.graalvm.nativebridge.BinaryOutput.CCharPointerBinaryOutput)1 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)1