ByteArrayBuilder

class ByteArrayBuilder(var data: ByteArray, size: Int = data.size, val allowGrow: Boolean = true)

Analogous to StringBuilder but for ByteArray. Allows to append values to end calling toByteArray. Provides some methods like s16LE or f32BE to append specific bit representations easily.

Constructors

Link copied to clipboard
constructor(data: ByteArray, size: Int = data.size, allowGrow: Boolean = true)
constructor(initialCapacity: Int = 4096)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
var size: Int

Current size of the buffer

Functions

Link copied to clipboard
inline fun append(v: Byte): ByteArrayBuilder

Appends a byte v to the buffer

fun append(vararg v: Byte)

Appends a sequence vararg of bytes v to the buffer

fun append(vararg v: Int): ByteArrayBuilder

Appends a sequence vararg of bytes v (represented as ints) to the buffer

fun append(array: ByteArray, offset: Int = 0, len: Int = array.size - offset)

Appends a byte array slice (offset and len) to the current buffer

Link copied to clipboard

Appends an 8-bits byte v to the buffer

Link copied to clipboard

Appends a byte v to the buffer

Link copied to clipboard
fun clear()

Clears/resets this ByteArrayBuilder

Link copied to clipboard
fun f32(v: Float, little: Boolean): ByteArrayBuilder

Appends a 32-bit Float v to the buffer in little or big-endian

Link copied to clipboard

Appends a 32-bit Float v to the buffer in big-endian

Link copied to clipboard

Appends a 32-bit Float v to the buffer in little-endian

Link copied to clipboard

Appends a 64-bit Double v to the buffer in little or big-endian

Link copied to clipboard

Appends a 64-bit Double v to the buffer in big-endian

Link copied to clipboard

Appends a 64-bit Double v to the buffer in little-endian

Link copied to clipboard
fun s16(v: Int, little: Boolean): ByteArrayBuilder

Appends a 16-bit v to the buffer in little or big-endian

Link copied to clipboard

Appends a 16-bit v to the buffer in big-endian

Link copied to clipboard

Appends a 16-bit v to the buffer in little-endian

Link copied to clipboard
fun s24(v: Int, little: Boolean): ByteArrayBuilder

Appends a 24-bit integer v to the buffer in little or big-endian

Link copied to clipboard

Appends a 24-bit integer v to the buffer in big-endian

Link copied to clipboard

Appends a 24-bit integer v to the buffer in little-endian

Link copied to clipboard
fun s32(v: Int, little: Boolean): ByteArrayBuilder

Appends a 32-bit Int v to the buffer in little or big-endian

Link copied to clipboard

Appends a 32-bit Int v to the buffer in big-endian

Link copied to clipboard

Appends a 32-bit Int v to the buffer in little-endian

Link copied to clipboard

Appends an 8-bits byte v to the buffer

Link copied to clipboard

Converts this ByteArrayBuilder to a ByteArray with the current size