public Object array() { return io.array(); }
public int arrayLength() { return io.arrayLength(); }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { if (!(value instanceof Struct)) { throw context.runtime.newTypeError(value, context.runtime.getFFI().structClass); } Struct s = (Struct) value; if (!s.getLayout(context).equals(sbv.getStructLayout())) { throw context.runtime.newTypeError("incompatible struct layout"); } ByteBuffer src = s.getMemoryIO().asByteBuffer(); if (src.remaining() != sbv.size) { throw context.runtime.newRuntimeError("bad size in " + value.getMetaClass().toString()); } ptr.getMemoryIO().slice(m.offset(), sbv.size).asByteBuffer().put(src); }
/** * Reads a 64 bit floating point value from the memory address. * * @return The value read from the address. */ @JRubyMethod(name = { "read_double" }) public IRubyObject read_double(ThreadContext context) { return RubyFloat.newFloat(context.runtime, getMemoryIO().getDouble(0)); }
/** * Reads an 8 bit unsigned integer value from the memory address. * * @return The value read from the address. */ @JRubyMethod(name = { "read_uchar" }) public IRubyObject read_uchar(ThreadContext context) { return Util.newUnsigned8(context.runtime, getMemoryIO().getByte(0)); }
public SwappedMemoryIO dup() { return new SwappedMemoryIO(runtime, io.dup()); }
public final void get(long offset, int[] dst, int off, int len) { io.get(offset, dst, off, len); for (int i = 0; i < len; ++i) { dst[off + i] = Integer.reverseBytes(dst[off + i]); } }
/** * Gets the native memory address of this pointer. * * @return A long containing the native memory address. */ public final long getAddress() { return getMemoryIO().address(); }
public int arrayOffset() { return io.arrayOffset(); }
public final java.nio.ByteBuffer asByteBuffer() { return io.asByteBuffer().order(order()); }
@Override void put(ThreadContext context, AbstractMemory ptr, long offset, IRubyObject value) { if (!(value instanceof Struct)) { throw context.runtime.newTypeError("expected a struct"); } Struct s = (Struct) value; byte[] tmp = new byte[Struct.getStructSize(context.runtime, s)]; s.getMemoryIO().get(0, tmp, 0, tmp.length); ptr.getMemoryIO().put(offset, tmp, 0, tmp.length); } }
public IRubyObject get(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr) { final long address = ((Pointer) ptr).getMemoryIO().getAddress(m.getOffset(ptr)); AbstractInvoker fptr = (AbstractInvoker) cache.getCachedValue(m); if (fptr != null && fptr.getAddress() == address) { return fptr; } fptr = Factory.getInstance().newFunction(context.runtime, ((Pointer) ptr).getPointer(context.runtime, m.getOffset(ptr)), (CallbackInfo) m.type); cache.putCachedValue(m, fptr); return fptr; }
public void put(ThreadContext context, StructLayout.Storage cache, Member m, AbstractMemory ptr, IRubyObject value) { if (!(value instanceof Struct)) { throw context.runtime.newTypeError(value, context.runtime.getFFI().structClass); } Struct s = (Struct) value; if (!s.getLayout(context).equals(sbv.getStructLayout())) { throw context.runtime.newTypeError("incompatible struct layout"); } ByteBuffer src = s.getMemoryIO().asByteBuffer(); if (src.remaining() != sbv.size) { throw context.runtime.newRuntimeError("bad size in " + value.getMetaClass().toString()); } ptr.getMemoryIO().slice(m.offset(), sbv.size).asByteBuffer().put(src); }
/** * Reads a 64 bit floating point value from the memory address. * * @return The value read from the address. */ @JRubyMethod(name = { "get_float64", "get_double" }) public IRubyObject get_float64(ThreadContext context) { return RubyFloat.newFloat(context.runtime, getMemoryIO().getDouble(0)); }
/** * Reads an 8 bit unsigned integer value from the memory address. * * @return The value read from the address. */ @JRubyMethod(name = { "get_uint8", "get_uchar" }) public IRubyObject get_uint8(ThreadContext context) { return Util.newUnsigned8(context.runtime, getMemoryIO().getByte(0)); }
public SwappedMemoryIO dup() { return new SwappedMemoryIO(runtime, io.dup()); }
public final void get(long offset, float[] dst, int off, int len) { io.get(offset, dst, off, len); for (int i = 0; i < len; ++i) { dst[off + i] = Float.intBitsToFloat(Integer.reverseBytes(Float.floatToRawIntBits(dst[off + i]))); } }
public final void putMemoryIO(long offset, MemoryIO value) { checkBounds(offset, ADDRESS_SIZE >> 3); putAddress(offset, value.address()); } public final byte getByte(long offset) {
public int arrayOffset() { return io.arrayOffset(); }