Class BinaryOutput
java.lang.Object
org.graalvm.nativebridge.BinaryOutput
- Direct Known Subclasses:
BinaryOutput.ByteArrayBinaryOutput,BinaryOutput.CCharPointerBinaryOutput
A buffer used by the
BinaryMarshaller to marshall parameters and results passed by value.- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classABinaryOutputbacked by a byte array.static final classABinaryOutputbacked by an off-heap memory. -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncreate()Creates a new buffer backed by a byte array.create(byte[] initialBuffer) Creates a new buffer wrapping theinitialBuffer.create(org.graalvm.nativeimage.c.type.CCharPointer address, int length, boolean dynamicallyAllocated) Creates a new buffer wrapping an off-heap memory segment starting ataddresshavinglengthbytes.intReturns this buffer's position.static booleanisTypedValue(Object value) abstract voidskip(int numberOfBytes) Reserves a buffer space.final voidwrite(boolean[] array, int off, int len) Writeslenbytes from the booleanarraystarting at offsetoff.abstract voidwrite(byte[] array, int off, int len) Writeslenbytes from the bytearraystarting at offsetoff.final voidwrite(char[] array, int off, int len) Writeslenchars from thearraystarting at offsetoff.final voidwrite(double[] array, int off, int len) Writeslendoubles from thearraystarting at offsetoff.final voidwrite(float[] array, int off, int len) Writeslenfloats from thearraystarting at offsetoff.abstract voidwrite(int b) Writes the lowest byte of the argument as a single byte value.final voidwrite(int[] array, int off, int len) Writeslenints from thearraystarting at offsetoff.final voidwrite(long[] array, int off, int len) Writeslenlongs from thearraystarting at offsetoff.final voidwrite(short[] array, int off, int len) Writeslenshorts from thearraystarting at offsetoff.final voidwriteBoolean(boolean value) Writes abooleanas a single byte value.final voidwriteByte(int value) Writes abyteas a single byte value.final voidwriteChar(int value) Writes acharas two bytes, high byte first.final voidwriteDouble(double value) Converts adoublevalue to alongusing theDouble.doubleToLongBits(double), and then writes thatlongas eight bytes, high byte first.final voidwriteFloat(float value) Converts afloatvalue to anintusing theFloat.floatToIntBits(float), and then writes thatintas four bytes, high byte first.final voidwriteInt(int value) Writes anintas four bytes, high byte first.final voidwriteLong(long value) Writes alongas eight bytes, high byte first.final voidwriteShort(int value) Writes ashortas two bytes, high byte first.final voidwriteTypedValue(Object value) Writes the value that is represented by the given object, together with information on the value's data type.final voidWrites a string using a modified UTF-8 encoding in a machine-independent manner.
-
Field Details
-
pos
protected int pos
-
-
Method Details
-
writeBoolean
public final void writeBoolean(boolean value) Writes abooleanas a single byte value. The valuetrueis written as the value(byte)1, the valuefalseis written as the value(byte)0. The buffer position is incremented by1. -
writeByte
public final void writeByte(int value) Writes abyteas a single byte value. The buffer position is incremented by1. -
writeShort
public final void writeShort(int value) Writes ashortas two bytes, high byte first. The buffer position is incremented by2. -
writeChar
public final void writeChar(int value) Writes acharas two bytes, high byte first. The buffer position is incremented by2. -
writeInt
public final void writeInt(int value) Writes anintas four bytes, high byte first. The buffer position is incremented by4. -
writeLong
public final void writeLong(long value) Writes alongas eight bytes, high byte first. The buffer position is incremented by8. -
writeFloat
public final void writeFloat(float value) Converts afloatvalue to anintusing theFloat.floatToIntBits(float), and then writes thatintas four bytes, high byte first. The buffer position is incremented by4. -
writeDouble
public final void writeDouble(double value) Converts adoublevalue to alongusing theDouble.doubleToLongBits(double), and then writes thatlongas eight bytes, high byte first. The buffer position is incremented by8. -
write
public abstract void write(int b) Writes the lowest byte of the argument as a single byte value. The buffer position is incremented by1. -
write
public abstract void write(byte[] array, int off, int len) Writeslenbytes from the bytearraystarting at offsetoff. The buffer position is incremented bylen. -
skip
public abstract void skip(int numberOfBytes) Reserves a buffer space. The reserved space can be used for out parameters.- Parameters:
numberOfBytes- number of bytes to reserve.
-
writeUTF
Writes a string using a modified UTF-8 encoding in a machine-independent manner.- Throws:
IllegalArgumentException- if thestringcannot be encoded using modified UTF-8 encoding.
-
getPosition
public int getPosition()Returns this buffer's position. -
isTypedValue
-
writeTypedValue
Writes the value that is represented by the given object, together with information on the value's data type. Supported types are boxed Java primitive types,String,null, and arrays of these types.- Throws:
IllegalArgumentException- when thevaluetype is not supported or thevalueis a string which cannot be encoded using modified UTF-8 encoding.- See Also:
-
write
public final void write(boolean[] array, int off, int len) Writeslenbytes from the booleanarraystarting at offsetoff. The valuetrueis written as the value(byte)1, the valuefalseis written as the value(byte)0. The buffer position is incremented bylen. -
write
public final void write(short[] array, int off, int len) Writeslenshorts from thearraystarting at offsetoff. The buffer position is incremented by2 * len. -
write
public final void write(char[] array, int off, int len) Writeslenchars from thearraystarting at offsetoff. The buffer position is incremented by2 * len. -
write
public final void write(int[] array, int off, int len) Writeslenints from thearraystarting at offsetoff. The buffer position is incremented by4 * len. -
write
public final void write(long[] array, int off, int len) Writeslenlongs from thearraystarting at offsetoff. The buffer position is incremented by8 * len. -
write
public final void write(float[] array, int off, int len) Writeslenfloats from thearraystarting at offsetoff. Eachfloatvalue is converted to anintusing theFloat.floatToIntBits(float)and written as an int. The buffer position is incremented by4 * len. -
write
public final void write(double[] array, int off, int len) Writeslendoubles from thearraystarting at offsetoff. Eachdoublevalue is converted to anlangusing theDouble.doubleToLongBits(double)and written as a long. The buffer position is incremented by8 * len. -
create
Creates a new buffer backed by a byte array. -
create
Creates a new buffer wrapping theinitialBuffer. If theinitialBuffercapacity is not sufficient for writing the data, a new array is allocated. Always useBinaryOutput.ByteArrayBinaryOutput.getArray()to obtain the marshaled data. -
create
public static BinaryOutput.CCharPointerBinaryOutput create(org.graalvm.nativeimage.c.type.CCharPointer address, int length, boolean dynamicallyAllocated) Creates a new buffer wrapping an off-heap memory segment starting ataddresshavinglengthbytes. If the capacity of an off-heap memory segment is not sufficient for writing the data, a new off-heap memory is allocated. Always useBinaryOutput.CCharPointerBinaryOutput.getAddress()to obtain the marshaled data.- Parameters:
address- the off-heap memory addresslength- the off-heap memory sizedynamicallyAllocated-trueif the memory was dynamically allocated and should be freed when the buffer is closed;falsefor the stack allocated memory.
-