ReadWriteBuffer

Interface to represent a read-write buffers. This interface will be used to access and write FlexBuffer messages.

Inheritors

Properties

Link copied to clipboard
abstract val capacity: Int

Maximum size in bytes that the backed buffer supports.

Link copied to clipboard
abstract val limit: Int

Defines the size of the message in the buffer. It also determines last position that buffer can be read. Last byte to be accessed is in position limit() -1.

Link copied to clipboard
abstract val writeLimit: Int

Defines last relative position of the backed buffer that can be written. Any addition to the buffer that goes beyond will throw an exception instead of regrow the buffer (default behavior).

Link copied to clipboard
abstract var writePosition: Int

Current position of the buffer to be written. It will be automatically updated on put operations.

Functions

Link copied to clipboard
abstract fun clear()

Clears (resets) the buffer so that it can be reused. Write position will be set to the start.

Link copied to clipboard
abstract fun data(): ByteArray

Expose ReadBuffer as an array of bytes. This method is meant to be as efficient as possible, so for an array-backed ReadBuffer, it should return its own internal data. In case access to internal data is not possible, a copy of the data into an array of bytes might occur.

Link copied to clipboard
abstract fun fill(value: Byte, start: Int, end: Int)
Link copied to clipboard
abstract fun findFirst(value: Byte, start: Int, end: Int = limit): Int

Scan through the buffer for first byte matching value.

Link copied to clipboard
abstract operator fun get(index: Int): Byte

Read a Byte from the buffer.

Link copied to clipboard
abstract fun getBoolean(index: Int): Boolean

Read boolean from the buffer. Booleans as stored as a single byte

Link copied to clipboard
abstract fun getBytes(array: ByteArray, start: Int, length: Int = array.size)

Read a ByteArray from the buffer.

Link copied to clipboard
abstract fun getDouble(index: Int): Double

Read a 64-bit float from the buffer.

Link copied to clipboard
abstract fun getFloat(index: Int): Float

Read a 32-bit float from the buffer.

Link copied to clipboard
abstract fun getInt(index: Int): Int

Read a Int from the buffer.

Link copied to clipboard
abstract fun getLong(index: Int): Long

Read a Long from the buffer.

Link copied to clipboard
abstract fun getShort(index: Int): Short

Read a Short from the buffer.

Link copied to clipboard
abstract fun getString(start: Int = 0, size: Int = limit): String

Read a UTF-8 string from the buffer.

Link copied to clipboard
abstract fun getUByte(index: Int): UByte

Read a UByte from the buffer.

Link copied to clipboard
abstract fun getUInt(index: Int): UInt

Read a UInt from the buffer.

Link copied to clipboard
abstract fun getULong(index: Int): ULong

Read a ULong from the buffer.

Link copied to clipboard
abstract fun getUShort(index: Int): UShort

Read a UShort from the buffer.

Link copied to clipboard
abstract fun moveWrittenDataToEnd(capacity: Int): Int

Special operation where we increase the backed buffer size to capacity and shift all already written data to the end of the buffer.

Link copied to clipboard
abstract fun put(value: Boolean)

Put a Boolean into the buffer at writePosition . Booleans as stored as single byte. Write position will be incremented.

abstract fun put(value: Byte)

Write a Byte into the buffer at writePosition. Write position will be incremented.

abstract fun put(value: Double)

Write a 64-bit Double into the buffer at writePosition. Write position will be incremented.

abstract fun put(value: Float)

Write a 32-bit Float into the buffer at writePosition. Write position will be incremented.

abstract fun put(value: Int)

Write a Int in the buffer at writePosition. Write position will be incremented.

abstract fun put(value: Long)

Write a Long into in the buffer at writePosition. Write position will be incremented.

abstract fun put(value: Short)

Write a Short into in the buffer at writePosition. Write position will be incremented.

abstract fun put(value: UByte)

Write a UByte into the buffer at writePosition. Write position will be incremented.

abstract fun put(value: UInt)

Write a UInt into in the buffer at writePosition. Write position will be incremented.

abstract fun put(value: ULong)

Write a ULong into in the buffer at writePosition. Write position will be incremented.

abstract fun put(value: UShort)

Write a UShort into in the buffer at writePosition. Write position will be incremented.

abstract fun put(value: CharSequence, encodedLength: Int = -1): Int

Write a String encoded as UTF-8 into the buffer at writePosition. Write position will be incremented.

abstract fun put(value: ReadBuffer, start: Int = 0, length: Int = value.limit - start)
abstract fun put(value: ByteArray, start: Int = 0, length: Int = value.size)

Put an array of bytes into the buffer at writePosition. Write position will be incremented.

Link copied to clipboard
open fun requestAdditionalCapacity(additional: Int, copyAtEnd: Boolean = false): Int

Request capacity of the buffer relative to writePosition. In case buffer is already larger than the requested, this method will just return true. Otherwise, It might try to resize the buffer. In case of being unable to allocate enough memory, an exception will be thrown.

Link copied to clipboard
abstract fun requestCapacity(capacity: Int, copyAtEnd: Boolean = false): Int

Request capacity of the buffer in absolute values. In case buffer is already larger than the requested the method is a no-op. Otherwise, It might try to resize the buffer. In case of being unable to allocate enough memory, an exception will be thrown.

Link copied to clipboard
abstract operator fun set(index: Int, value: Boolean)

Write Boolean into a given position index on the buffer. Booleans as stored as single byte.

abstract operator fun set(index: Int, value: Byte)

Write Byte into a given position index on the buffer.

abstract fun set(index: Int, value: Double)

Write Double into a given position index on the buffer.

abstract fun set(index: Int, value: Float)

Write Float into a given position index on the buffer.

abstract fun set(index: Int, value: Int)

Write Int into a given position index on the buffer.

abstract fun set(index: Int, value: Long)

Write Long into a given position index on the buffer.

abstract fun set(index: Int, value: Short)

Short

abstract operator fun set(index: Int, value: UByte)

Write UByte into a given position index on the buffer.

abstract fun set(index: Int, value: UInt)

Write UInt into a given position index on the buffer.

abstract fun set(index: Int, value: ULong)

Write ULong into a given position index on the buffer.

abstract fun set(index: Int, value: UShort)

Write UShort into a given position index on the buffer.

abstract operator fun set(dstIndex: Int, src: ReadBuffer, srcStart: Int = 0, srcLength: Int)
abstract fun set(dstIndex: Int, src: ByteArray, srcStart: Int = 0, srcLength: Int = src.size)

Write an array of bytes into the buffer.

Link copied to clipboard
abstract fun slice(start: Int, size: Int): ReadBuffer

Creates a new ReadBuffer point to a region of the current buffer, starting at start with size size.

Link copied to clipboard
abstract fun writeSlice(offset: Int, size: Int): ReadWriteBuffer

Creates a new ReadWriteBuffer point to a region of the current buffer, starting at offset with size size.