Код: Выделить всё
ErrorCode_t GetBlob(Handle_const_t hHandle, uint8_t* const pValue, size_t* const pnSize);
Заголовок можно преобразовать в исходный код Java с помощью jextract, что дает:
Код: Выделить всё
public static long GetBlob(MemorySegment hHandle, MemorySegment pValue, MemorySegment pnSize) {
// ..
}
Код: Выделить всё
MemorySegment handle = ..;
MemorySegment arrayPointer = Arena.global().allocate(C_POINTER);
MemorySegment sizePointer = Arena.global().allocate(JAVA_LONG);
Accessor_h.GetBlob(handle, arrayPointer, sizePointer);
Но чтение данных массива не выполняется. Я попробовал следующее:
Код: Выделить всё
arrayPointer.get(C_POINTER, 0L)
.toArray(JAVA_BYTE); // fails with "Segment is too large to wrap as byte[]. Size: 9223372036854775807"
Код: Выделить всё
arrayPointer.get(C_POINTER, 0L)
.asSlice(0L, sizePointer.get(JAVA_LONG, 0L))
.toArray(JAVA_BYTE); // SIGSEGV (0xb)
Код: Выделить всё
arrayPointer
.toArray(JAVA_BYTE); // seems to contain the correct data, but only the first eight bytes
Код: Выделить всё
arrayPointer
.asSlice(0L, sizePointer.get(JAVA_LONG, 0L))
.toArray(JAVA_BYTE); // fails with "java.lang.IndexOutOfBoundsException: Out of bound access on segment MemorySegment"
Подробнее здесь: https://stackoverflow.com/questions/784 ... known-leng