getBytes

Returns a ByteArray containing the target value.

Return

An array containing the target byte.


fun Byte.getBytes(buffer: ByteArray, offset: Int = 0): Int
fun UByte.getBytes(buffer: ByteArray, offset: Int = 0): Int

Fills the given buffer, starting from the given offset, with the target value.

If the given array's size is less than offset + 1, an exception will be thrown.

Return

1, the number of bytes written to the buffer.

Parameters

buffer

ByteArray that will be filled with the target byte.

offset

Offset position in the buffer array to start writing at.

Default: 0


fun Int.getBytes(be: Boolean = true): ByteArray

Returns a ByteArray containing the 4 bytes that make up the target Int value.

Return

An array of 4 bytes.

Parameters

be

Whether the bytes should be in Big Endian order.

Default: true


fun Int.getBytes(buffer: ByteArray, offset: Int = 0, be: Boolean = true): Int

Fills the given buffer, starting from the given offset, with the 4 bytes that make up the target Int value.

If the given array's size is less than offset + 4, an exception will be thrown.

Return

4, the number of bytes written to the buffer.

Parameters

buffer

ByteArray that will be filled with the bytes from the target Int.

offset

Offset position in the buffer array to start writing at.

Default: 0

be

Whether the bytes should be written in Big Endian order.

Default: true


fun Long.getBytes(be: Boolean = true): ByteArray

Returns a ByteArray containing the 8 bytes that make up the target Long value.

Return

An array of 8 bytes.

Parameters

be

Whether the bytes should be in Big Endian order.

Default: true


fun Long.getBytes(buffer: ByteArray, offset: Int = 0, be: Boolean = true): Int

Fills the given buffer, starting from the given offset, with the 8 bytes that make up the target Long value.

If the given array's size is less than offset + 8, an exception will be thrown.

Return

8, the number of bytes written to the buffer.

Parameters

buffer

ByteArray that will be filled with the bytes from the target Long.

offset

Offset position in the buffer array to start writing at.

Default: 0

be

Whether the bytes should be written in Big Endian order.

Default: true


fun Short.getBytes(be: Boolean = true): ByteArray

Returns a ByteArray containing the 2 bytes that make up the target Short value.

Return

An array of 2 bytes.

Parameters

be

Whether the bytes should be in Big Endian order.

Default: true


fun Short.getBytes(buffer: ByteArray, offset: Int = 0, be: Boolean = true): Int

Fills the given buffer, starting from the given offset, with the 2 bytes that make up the target Short value.

If the given array's size is less than offset + 2, an exception will be thrown.

Return

2, the number of bytes written to the buffer.

Parameters

buffer

ByteArray that will be filled with the bytes from the target Short.

offset

Offset position in the buffer array to start writing at.

Default: 0

be

Whether the bytes should be written in Big Endian order.

Default: true


fun UInt.getBytes(be: Boolean = true): ByteArray

Returns a ByteArray containing the 4 bytes that make up the target UInt value.

Return

An array of 4 bytes.

Parameters

be

Whether the bytes should be in Big Endian order.

Default: true


fun UInt.getBytes(buffer: ByteArray, offset: Int = 0, be: Boolean = true): Int

Fills the given buffer, starting from the given offset, with the 4 bytes that make up the target UInt value.

If the given array's size is less than offset + 4, an exception will be thrown.

Order is Big Endian.

Return

4, the number of bytes written to the buffer.

Parameters

buffer

ByteArray that will be filled with the bytes from the target UInt.

offset

Offset position in the buffer array to start writing at.

Default: 0

be

Whether the bytes should be written in Big Endian order.

Default: true


fun ULong.getBytes(be: Boolean = true): ByteArray

Returns a ByteArray containing the 8 bytes that make up the target ULong value.

Return

An array of 8 bytes.

Parameters

be

Whether the bytes should be in Big Endian order.

Default: true


fun ULong.getBytes(buffer: ByteArray, offset: Int = 0, be: Boolean = true): Int

Fills the given buffer, starting from the given offset, with the 8 bytes that make up the target ULong value.

If the given array's size is less than offset + 8, an exception will be thrown.

Order is Big Endian.

Return

8, the number of bytes written to the buffer.

Parameters

buffer

ByteArray that will be filled with the bytes from the target ULong.

offset

Offset position in the buffer array to start writing at.

Default: 0

be

Whether the bytes should be written in Big Endian order.

Default: true


fun UShort.getBytes(be: Boolean = true): ByteArray

Returns a ByteArray containing the 2 bytes that make up the target UShort value.

Return

An array of 2 bytes.

Parameters

be

Whether the bytes should be in Big Endian order.

Default: true


fun UShort.getBytes(buffer: ByteArray, offset: Int = 0, be: Boolean = true): Int

Fills the given buffer, starting from the given offset, with the 2 bytes that make up the target UShort value.

If the given array's size is less than offset + 2, an exception will be thrown.

Order is Big Endian.

Return

2, the number of bytes written to the buffer.

Parameters

buffer

ByteArray that will be filled with the bytes from the target UShort.

offset

Offset position in the buffer array to start writing at.

Default: 0

be

Whether the bytes should be written in Big Endian order.

Default: true