public abstract class BinaryOutput extends Object
BinaryMarshaller to marshall parameters and results passed by value.| Modifier and Type | Class and Description |
|---|---|
static class |
BinaryOutput.ByteArrayBinaryOutput
A
BinaryOutput backed by a byte array. |
static class |
BinaryOutput.CCharPointerBinaryOutput
A
BinaryOutput backed by an off-heap memory. |
| Modifier and Type | Field and Description |
|---|---|
protected int |
pos |
| Modifier and Type | Method and Description |
|---|---|
static BinaryOutput.ByteArrayBinaryOutput |
create()
Creates a new buffer backed by a byte array.
|
static BinaryOutput.ByteArrayBinaryOutput |
create(byte[] initialBuffer)
Creates a new buffer wrapping the
initialBuffer. |
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 at
address having
length bytes. |
int |
getPosition()
Returns this buffer's position.
|
abstract void |
write(byte[] array,
int off,
int len)
Writes
len bytes from the byte array starting at offset off. |
abstract void |
write(int b)
Writes the lowest byte of the argument as a single byte value.
|
void |
writeBoolean(boolean value)
Writes a
boolean as a single byte value. |
void |
writeByte(int value)
Writes a
byte as a single byte value. |
void |
writeChar(int value)
Writes a
char as two bytes, high byte first. |
void |
writeDouble(double value)
Converts a
double value to a long using the
Double.doubleToLongBits(double), and then writes that long as eight bytes,
high byte first. |
void |
writeFloat(float value)
Converts a
float value to an int using the
Float.floatToIntBits(float), and then writes that int as four bytes, high
byte first. |
void |
writeInt(int value)
Writes an
int as four bytes, high byte first. |
void |
writeLong(long value)
Writes a
long as eight bytes, high byte first. |
void |
writeShort(int value)
Writes a
short as two bytes, high byte first. |
void |
writeTypedValue(Object value)
Writes the value that is represented by the given object, together with information on the
value's data type.
|
void |
writeUTF(String string)
Writes a string using a modified UTF-8 encoding in a machine-independent manner.
|
public final void writeBoolean(boolean value)
boolean as a single byte value. The value true is written as the
value (byte)1, the value false is written as the value (byte)0. The
buffer position is incremented by 1.public final void writeByte(int value)
byte as a single byte value. The buffer position is incremented by
1.public final void writeShort(int value)
short as two bytes, high byte first. The buffer position is incremented by
2.public final void writeChar(int value)
char as two bytes, high byte first. The buffer position is incremented by
2.public final void writeInt(int value)
int as four bytes, high byte first. The buffer position is incremented by
4.public final void writeLong(long value)
long as eight bytes, high byte first. The buffer position is incremented by
8.public final void writeFloat(float value)
float value to an int using the
Float.floatToIntBits(float), and then writes that int as four bytes, high
byte first. The buffer position is incremented by 4.public final void writeDouble(double value)
double value to a long using the
Double.doubleToLongBits(double), and then writes that long as eight bytes,
high byte first. The buffer position is incremented by 8.public abstract void write(int b)
1.public abstract void write(byte[] array,
int off,
int len)
len bytes from the byte array starting at offset off. The
buffer position is incremented by len.public final void writeUTF(String string) throws IllegalArgumentException
IllegalArgumentException - if the string cannot be encoded using modified UTF-8
encoding.public int getPosition()
public final void writeTypedValue(Object value) throws IllegalArgumentException
String,
null, and arrays of these types.IllegalArgumentException - when the value type is not supported or the
value is a string which cannot be encoded using modified UTF-8 encoding.public static BinaryOutput.ByteArrayBinaryOutput create()
public static BinaryOutput.ByteArrayBinaryOutput create(byte[] initialBuffer)
initialBuffer. If the initialBuffer
capacity is not sufficient for writing the data, a new array is allocated. Always use
BinaryOutput.ByteArrayBinaryOutput.getArray() to obtain the marshaled data.public static BinaryOutput.CCharPointerBinaryOutput create(org.graalvm.nativeimage.c.type.CCharPointer address, int length, boolean dynamicallyAllocated)
address having
length bytes. If the capacity of an off-heap memory segment is not sufficient for
writing the data, a new off-heap memory is allocated. Always use
BinaryOutput.CCharPointerBinaryOutput.getAddress() to obtain the marshaled data.address - the off-heap memory addresslength - the off-heap memory sizedynamicallyAllocated - true if the memory was dynamically allocated and should
be freed when the buffer is closed; false for the stack allocated memory.