binary-streams / loggersoft.kotlin.streams / kotlin.ByteArray

Extensions for kotlin.ByteArray

asArea

Creates ByteArea for this with specified size and offset.

fun ByteArray.asArea(size: Int, offset: Int = 0): ByteArea

copyFrom

Copies length bytes from src byte array starting from srcOffset into this array starting from offset.

fun ByteArray.copyFrom(length: Int, src: ByteArray, offset: Int = 0, srcOffset: Int = 0): Unit

copyTo

Copies length bytes from this starting from offset into dest byte array starting from destOffset.

fun ByteArray.copyTo(length: Int, dest: ByteArray, offset: Int = 0, destOffset: Int = 0): ByteArray

crc16

Calculates CRC16 of ByteArray from offset with size starting from startValue.

fun ByteArray.crc16(startValue: Int = CRC16_START_VALUE, offset: Int = 0, size: Int = this.size - offset): Int

crc32

Calculates CRC32 of ByteArray from offset with size starting from startValue. If finalize is true returned value will be final (when data processed partially for the last block).

fun ByteArray.crc32(startValue: Int = CRC32_START_VALUE, finalize: Boolean = true, offset: Int = 0, size: Int = this.size - offset): Int

decodeUtf8

Decodes UTF-8 code point starting from offset.

fun ByteArray.decodeUtf8(offset: Int): Int

hasUtf8At

Returns bytes count of UTF-8 code point at offset or -1 if the valid code point wasn't found in that position.

fun ByteArray.hasUtf8At(offset: Int): Int

toBigInteger

Extracts BigInteger value from this byte array starting from offset with specified bytes count and byteOrder. If signed is true the last bit interprets as a sign.

fun ByteArray.toBigInteger(bytes: Int, signed: Boolean = true, byteOrder: ByteOrder = nativeByteOrder, offset: Int = 0): BigInteger

toInteger

Extracts Long value from this byte array starting from offset with specified bytes count and byteOrder. If signed is true the last bit interprets as a sign. This means that if last bit is 1 the rest of the bits higher than last bit would be filled by 1. The bytes should be in range 1..8.

fun ByteArray.toInteger(bytes: Int = 8, signed: Boolean = true, byteOrder: ByteOrder = nativeByteOrder, offset: Int = 0): Long

toUnsigned

Extracts ULong value from this byte array starting from offset with specified bytes count and byteOrder. The bytes should be in range 1..8.

fun ByteArray.toUnsigned(bytes: Int = ULong.SIZE_BYTES, byteOrder: ByteOrder = nativeByteOrder, offset: Int = 0): ULong