All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.soywiz.kmem.ByteArraySlice.kt Maven / Gradle / Ivy

Go to download

kmem: Fast memory for Kotlin Common (JVM and JS) using Buffers and Typed Arrays

The newest version!
package com.soywiz.kmem

class ByteArraySlice(val data: ByteArray, val position: Int, val length: Int) {
	fun getPointer(): Pointer = Pointer(data, position)
	override fun toString() = "ByteArraySlice(data=$data, position=$position, length=$length)"

	operator fun get(n: Int): Byte = data[position + n]
	operator fun set(n: Int, value: Byte): Unit = run { data[position + n] = value }

	companion object {
		fun create(start: Pointer, end: Pointer): ByteArraySlice {
			if (start.ba != end.ba) throw RuntimeException("Pointer must reference the samea array")
			return ByteArraySlice(start.ba, start.offset, end.offset - start.offset)
		}
	}
}

fun ByteArray.toByteArraySlice() = ByteArraySlice(this, 0, size)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy