Class BinaryOutput

java.lang.Object
org.graalvm.nativebridge.BinaryOutput
Direct Known Subclasses:
BinaryOutput.ByteArrayBinaryOutput, BinaryOutput.CCharPointerBinaryOutput

public abstract class BinaryOutput extends Object
A buffer used by the BinaryMarshaller to marshall parameters and results passed by value.
See Also:
  • Nested Class Summary

    Nested Classes
    Modifier and Type
    Class
    Description
    static final class 
    A BinaryOutput backed by a byte array.
    static final class 
    A BinaryOutput backed by an off-heap memory.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected int
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Creates a new buffer backed by a byte array.
    create(byte[] initialBuffer)
    Creates a new buffer wrapping the initialBuffer.
    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
    Returns this buffer's position.
    static boolean
    Returns true if a value is a typed value writable using writeTypedValue(Object), else false.
    abstract void
    skip(int numberOfBytes)
    Reserves a buffer space.
    final void
    write(boolean[] array, int off, int len)
    Writes len bytes from the boolean array starting at offset off.
    abstract void
    write(byte[] array, int off, int len)
    Writes len bytes from the byte array starting at offset off.
    final void
    write(char[] array, int off, int len)
    Writes len chars from the array starting at offset off.
    final void
    write(double[] array, int off, int len)
    Writes len doubles from the array starting at offset off.
    final void
    write(float[] array, int off, int len)
    Writes len floats from the array starting at offset off.
    abstract void
    write(int b)
    Writes the lowest byte of the argument as a single byte value.
    final void
    write(int[] array, int off, int len)
    Writes len ints from the array starting at offset off.
    final void
    write(long[] array, int off, int len)
    Writes len longs from the array starting at offset off.
    final void
    write(short[] array, int off, int len)
    Writes len shorts from the array starting at offset off.
    final void
    writeBoolean(boolean value)
    Writes a boolean as a single byte value.
    final void
    writeByte(int value)
    Writes a byte as a single byte value.
    final void
    writeChar(int value)
    Writes a char as two bytes, high byte first.
    final 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.
    final 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.
    final void
    writeInt(int value)
    Writes an int as four bytes, high byte first.
    final void
    writeLong(long value)
    Writes a long as eight bytes, high byte first.
    final void
    writeShort(int value)
    Writes a short as two bytes, high byte first.
    final void
    Writes the value that is represented by the given object, together with information on the value's data type.
    final void
    writeUTF(String string)
    Writes a string using a modified UTF-8 encoding in a machine-independent manner.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • pos

      protected int pos
  • Method Details

    • writeBoolean

      public final void writeBoolean(boolean value)
      Writes a 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.
    • writeByte

      public final void writeByte(int value)
      Writes a byte as a single byte value. The buffer position is incremented by 1.
    • writeShort

      public final void writeShort(int value)
      Writes a short as two bytes, high byte first. The buffer position is incremented by 2.
    • writeChar

      public final void writeChar(int value)
      Writes a char as two bytes, high byte first. The buffer position is incremented by 2.
    • writeInt

      public final void writeInt(int value)
      Writes an int as four bytes, high byte first. The buffer position is incremented by 4.
    • writeLong

      public final void writeLong(long value)
      Writes a long as eight bytes, high byte first. The buffer position is incremented by 8.
    • writeFloat

      public final 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. The buffer position is incremented by 4.
    • writeDouble

      public final 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. The buffer position is incremented by 8.
    • write

      public abstract void write(int b)
      Writes the lowest byte of the argument as a single byte value. The buffer position is incremented by 1.
    • write

      public abstract void write(byte[] array, int off, int len)
      Writes len bytes from the byte array starting at offset off. The buffer position is incremented by len.
    • 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

      public final void writeUTF(String string) throws IllegalArgumentException
      Writes a string using a modified UTF-8 encoding in a machine-independent manner.
      Throws:
      IllegalArgumentException - if the string cannot be encoded using modified UTF-8 encoding.
    • getPosition

      public int getPosition()
      Returns this buffer's position.
    • isTypedValue

      public static boolean isTypedValue(Object value)
      Returns true if a value is a typed value writable using writeTypedValue(Object), else false.
    • writeTypedValue

      public final void writeTypedValue(Object value) throws IllegalArgumentException
      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 the value type is not supported or the value is a string which cannot be encoded using modified UTF-8 encoding.
      See Also:
    • write

      public final void write(boolean[] array, int off, int len)
      Writes len bytes from the boolean array starting at offset off. 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 len.
    • write

      public final void write(short[] array, int off, int len)
      Writes len shorts from the array starting at offset off. The buffer position is incremented by 2 * len.
    • write

      public final void write(char[] array, int off, int len)
      Writes len chars from the array starting at offset off. The buffer position is incremented by 2 * len.
    • write

      public final void write(int[] array, int off, int len)
      Writes len ints from the array starting at offset off. The buffer position is incremented by 4 * len.
    • write

      public final void write(long[] array, int off, int len)
      Writes len longs from the array starting at offset off. The buffer position is incremented by 8 * len.
    • write

      public final void write(float[] array, int off, int len)
      Writes len floats from the array starting at offset off. Each float value is converted to an int using the Float.floatToIntBits(float) and written as an int. The buffer position is incremented by 4 * len.
    • write

      public final void write(double[] array, int off, int len)
      Writes len doubles from the array starting at offset off. Each double value is converted to an lang using the Double.doubleToLongBits(double) and written as a long. The buffer position is incremented by 8 * len.
    • create

      public static BinaryOutput.ByteArrayBinaryOutput create()
      Creates a new buffer backed by a byte array.
    • create

      public static BinaryOutput.ByteArrayBinaryOutput create(byte[] initialBuffer)
      Creates a new buffer wrapping the 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.
    • 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 at 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.
      Parameters:
      address - the off-heap memory address
      length - the off-heap memory size
      dynamicallyAllocated - true if the memory was dynamically allocated and should be freed when the buffer is closed; false for the stack allocated memory.