Class MessageBody

All Implemented Interfaces:
Proxy

@Generated("org.javagi.JavaGI") public class MessageBody extends ProxyInstance

MessageBody represents the request or response body of a Message.

Note that while length always reflects the full length of the message body, data is normally null, and will only be filled in after flatten() is called. For client-side messages, this automatically happens for the response body after it has been fully read. Likewise, for server-side messages, the request body is automatically filled in after being read.

As an added bonus, when data is filled in, it is always terminated with a \\0 byte (which is not reflected in length).

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new MessageBody
    Create a MessageBody proxy instance for the provided memory address.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    append(@Nullable byte @Nullable [] data)
    Appends length bytes from data to body.
    void
    appendBytes(byte[] buffer)
    Appends the data from buffer to body.
    void
    Tags this MessageBody as being complete.
    byte[]
    Fills in body's data field with a buffer containing all of the data in body.
    boolean
    Gets the accumulate flag on body.
    byte @Nullable []
    getChunk(long offset)
    Gets a GLib.Bytes containing data from this MessageBody starting at offset.
    The memory layout of the native struct.
    static @Nullable Type
    Get the GType of the MessageBody class.
    void
    gotChunk(byte[] chunk)
    Handles the MessageBody part of receiving a chunk of data from the network.
    @Nullable byte @Nullable []
    Read the value of the field data.
    long
    Read the value of the field length.
    ref()
    Atomically increments the reference count of this MessageBody by one.
    void
    setAccumulate(boolean accumulate)
    Sets or clears the accumulate flag on body.
    void
    Deletes all of the data in body.
    void
    Atomically decrements the reference count of this MessageBody by one.
    void
    writeData(@Nullable byte @Nullable [] data, Arena _arena)
    Write a value in the field data.
    void
    writeLength(long length)
    Write a value in the field length.
    void
    wroteChunk(byte[] chunk)
    Handles the MessageBody part of writing a chunk of data to the network.

    Methods inherited from class ProxyInstance

    equals, handle, hashCode

    Methods inherited from class Object

    clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MessageBody

      public MessageBody(MemorySegment address)
      Create a MessageBody proxy instance for the provided memory address.
      Parameters:
      address - the memory address of the native object
    • MessageBody

      public MessageBody()

      Creates a new MessageBody

      Message uses this internally; you will not normally need to call it yourself.

  • Method Details

    • getType

      public static @Nullable Type getType()
      Get the GType of the MessageBody class.
      Returns:
      the GType
    • getMemoryLayout

      public static MemoryLayout getMemoryLayout()
      The memory layout of the native struct.
      Returns:
      the memory layout
    • readData

      public @Nullable byte @Nullable [] readData()
      Read the value of the field data.
      Returns:
      The value of the field data
    • writeData

      public void writeData(@Nullable byte @Nullable [] data, Arena _arena)
      Write a value in the field data.
      Parameters:
      data - The new value for the field data
      _arena - to control the memory allocation scope
    • readLength

      public long readLength()
      Read the value of the field length.
      Returns:
      The value of the field length
    • writeLength

      public void writeLength(long length)
      Write a value in the field length.
      Parameters:
      length - The new value for the field length
    • appendBytes

      public void appendBytes(byte[] buffer)
      Appends the data from buffer to body.
      Parameters:
      buffer - a GBytes
    • append

      public void append(@Nullable byte @Nullable [] data)

      Appends length bytes from data to body.

      This function is exactly equivalent to append(byte[]) with MemoryUse.TAKE as second argument; it exists mainly for convenience and simplifying language bindings.

      Parameters:
      data - data to append
    • complete

      public void complete()

      Tags this MessageBody as being complete.

      Call this when using chunked encoding after you have appended the last chunk.

    • flatten

      public byte[] flatten()

      Fills in body's data field with a buffer containing all of the data in body.

      Adds an additional \\0 byte not counted by body's length field.

      Returns:
      a GBytes containing the same data as body. (You must org.gnome.glib.Bytes.unref this if you do not want it.)
    • getAccumulate

      public boolean getAccumulate()

      Gets the accumulate flag on body.

      See [methodMessageBody.setAccumulate. for details.

      Returns:
      the accumulate flag for body.
    • getChunk

      public byte @Nullable [] getChunk(long offset)

      Gets a GLib.Bytes containing data from this MessageBody starting at offset.

      The size of the returned chunk is unspecified. You can iterate through the entire body by first calling getChunk(long) with an offset of 0, and then on each successive call, increment the offset by the length of the previously-returned chunk.

      If offset is greater than or equal to the total length of body, then the return value depends on whether or not complete() has been called or not; if it has, then getChunk(long) will return a 0-length chunk (indicating the end of body). If it has not, then getChunk(long) will return null (indicating that this MessageBody may still potentially have more data, but that data is not currently available).

      Parameters:
      offset - an offset
      Returns:
      a GBytes
    • gotChunk

      public void gotChunk(byte[] chunk)

      Handles the MessageBody part of receiving a chunk of data from the network.

      Normally this means appending chunk to body, exactly as with appendBytes(byte[]), but if you have set body's accumulate flag to false, then that will not happen.

      This is a low-level method which you should not normally need to use.

      Parameters:
      chunk - a GBytes received from the network
    • ref

      public MessageBody ref()
      Atomically increments the reference count of this MessageBody by one.
      Returns:
      the passed in SoupMessageBody
    • setAccumulate

      public void setAccumulate(boolean accumulate)

      Sets or clears the accumulate flag on body.

      (The default value is true.) If set to false, body's data field will not be filled in after the body is fully sent/received, and the chunks that make up this MessageBody may be discarded when they are no longer needed.

      If you set the flag to false on the Message request_body of a client-side message, it will block the accumulation of chunks into body's data field, but it will not normally cause the chunks to be discarded after being written like in the server-side Message response_body case, because the request body needs to be kept around in case the request needs to be sent a second time due to redirection or authentication.

      Parameters:
      accumulate - whether or not to accumulate body chunks in this MessageBody
    • truncate

      public void truncate()
      Deletes all of the data in body.
    • unref

      public void unref()

      Atomically decrements the reference count of this MessageBody by one.

      When the reference count reaches zero, the resources allocated by this MessageBody are freed

    • wroteChunk

      public void wroteChunk(byte[] chunk)

      Handles the MessageBody part of writing a chunk of data to the network.

      Normally this is a no-op, but if you have set body's accumulate flag to false, then this will cause chunk to be discarded to free up memory.

      This is a low-level method which you should not need to use, and there are further restrictions on its proper use which are not documented here.

      Parameters:
      chunk - a GBytes returned from getChunk(long)