packUnsafe
Packs 2
bytes from source Short into dest ByteArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = 2702.toShort()
val dest = ByteArray(2) { -100 }
println(dest.toList())
// [-100, -100]
Endian.Big.packUnsafe(source, dest, 0)
println(dest.toList())
// [10, -114]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
println(dest.toList())
// [-114, 10]
Return
The dest array
Parameters
The Short to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
See also
Throws
if an invalid index in dest is accessed.
Packs bytes from source Short (max 2
bytes) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest ByteArray, starting at destOffset. If sourceIndexStart is 0
and sourceIndexEnd is Short.SIZE_BYTES, the more performant packUnsafe function will be utilized.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = 2702.toShort()
val dest = ByteArray(2) { -100 }
println(dest.toList())
// [-100, -100]
Endian.Big.packUnsafe(source, dest, 0)
println(dest.toList())
// [10, -114]
dest.fill(-100)
Endian.Big.packUnsafe(source, dest, 1, sourceIndexStart = 0, sourceIndexEnd = 1)
println(dest.toList())
// [-100, 10]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
println(dest.toList())
// [-114, 10]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 1, sourceIndexStart = 1)
println(dest.toList())
// [-100, 10]
Return
The dest array
Parameters
The Short to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
The beginning (inclusive) of the source byte subrange.
The end (exclusive) of the source byte subrange, Short.SIZE_BYTES by default.
See also
Throws
if an invalid index in dest is accessed.
Packs bytes from source ShortArray (max size * 2
bytes) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest ByteArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = ShortArray(3) { i -> (i + 2701).toShort() }
val dest = ByteArray(source.size * Short.SIZE_BYTES) { -100 }
println(dest.toList())
println(source.toList())
// [-100, -100, -100, -100, -100, -100]
// [2701, 2702, 2703]
Endian.Big.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Big.packUnsafe(source = dest, dest = source, 0, 0, sourceIndexEnd = dest.size)
println(dest.toList())
println(source.toList())
// [10, -115, 10, -114, 10, -113]
// [2701, 2702, 2703]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Little.packUnsafe(source = dest, dest = source, 1, dest.size - 4, dest.size)
println(dest.toList())
println(source.toList())
// [-115, 10, -114, 10, -113, 10]
// [0, 2702, 2703]
Return
The dest array
Parameters
The ShortArray to retrieve Shorts from to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
The beginning (inclusive) of the source subrange, 0
by default.
The end (exclusive) of the source subrange, source.size
by default.
See also
Throws
Packs Shorts from source ByteArray (max size / 2
Shorts) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest ShortArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = ShortArray(3) { i -> (i + 2701).toShort() }
val dest = ByteArray(source.size * Short.SIZE_BYTES) { -100 }
println(dest.toList())
println(source.toList())
// [-100, -100, -100, -100, -100, -100]
// [2701, 2702, 2703]
Endian.Big.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Big.packUnsafe(source = dest, dest = source, 0, 0, sourceIndexEnd = dest.size)
println(dest.toList())
println(source.toList())
// [10, -115, 10, -114, 10, -113]
// [2701, 2702, 2703]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Little.packUnsafe(source = dest, dest = source, 1, dest.size - 4, dest.size)
println(dest.toList())
println(source.toList())
// [-115, 10, -114, 10, -113, 10]
// [0, 2702, 2703]
Return
The dest array
Parameters
The ByteArray to retrieve bytes from to convert into Shorts.
The ShortArray to pack Shorts into.
The position in dest to start packing.
The beginning (inclusive) of the source subrange.
The end (exclusive) of the source subrange.
See also
Throws
Packs 4
bytes from source Int into dest ByteArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = -77362181
val dest = ByteArray(4) { -100 }
println(dest.toList())
// [-100, -100, -100, -100]
Endian.Big.packUnsafe(source, dest, 0)
println(dest.toList())
// [-5, 99, -117, -5]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
println(dest.toList())
// [-5, -117, 99, -5]
Return
The dest array
Parameters
The Int to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
See also
Throws
if an invalid index in dest is accessed.
Packs bytes from source Int (max 4
bytes) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest ByteArray, starting at destOffset. If sourceIndexStart is 0
and sourceIndexEnd is Int.SIZE_BYTES, the more performant packUnsafe function will be utilized.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = -77362181
val dest = ByteArray(4) { -100 }
println(dest.toList())
// [-100, -100, -100, -100]
Endian.Big.packUnsafe(source, dest, 0)
println(dest.toList())
// [-5, 99, -117, -5]
dest.fill(-100)
Endian.Big.packUnsafe(source, dest, 2, sourceIndexStart = 1, sourceIndexEnd = 3)
println(dest.toList())
// [-100, -100, 99, -117]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
println(dest.toList())
// [-5, -117, 99, -5]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 1, sourceIndexStart = 3)
println(dest.toList())
// [-100, -5, -100, -100]
Return
The dest array
Parameters
The Int to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
The beginning (inclusive) of the source byte subrange, 0 by default.
The end (exclusive) of the source byte subrange, Int.SIZE_BYTES by default.
See also
Throws
if an invalid index in dest is accessed.
Packs bytes from source IntArray (max size * 4
bytes) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest ByteArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = IntArray(2) { i -> i - 77362181 }
val dest = ByteArray(source.size * Int.SIZE_BYTES) { -100 }
println(dest.toList())
println(source.toList())
// [-100, -100, -100, -100, -100, -100, -100, -100]
// [-77362181, -77362180]
Endian.Big.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Big.packUnsafe(source = dest, dest = source, 0, 0, sourceIndexEnd = dest.size)
println(dest.toList())
println(source.toList())
// [-5, 99, -117, -5, -5, 99, -117, -4]
// [-77362181, -77362180]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Little.packUnsafe(source = dest, dest = source, 1, dest.size - 4, dest.size)
println(dest.toList())
println(source.toList())
// [-5, -117, 99, -5, -4, -117, 99, -5]
// [0, -77362180]
Return
The dest array
Parameters
The IntArray to retrieve Ints from to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
The beginning (inclusive) of the source subrange, 0
by default.
The end (exclusive) of the source subrange, source.size
by default.
See also
Throws
Packs Ints from source ByteArray (max size / 4
Ints) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest IntArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = IntArray(2) { i -> i - 77362181 }
val dest = ByteArray(source.size * Int.SIZE_BYTES) { -100 }
println(dest.toList())
println(source.toList())
// [-100, -100, -100, -100, -100, -100, -100, -100]
// [-77362181, -77362180]
Endian.Big.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Big.packUnsafe(source = dest, dest = source, 0, 0, sourceIndexEnd = dest.size)
println(dest.toList())
println(source.toList())
// [-5, 99, -117, -5, -5, 99, -117, -4]
// [-77362181, -77362180]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
source.fill(0)
Endian.Little.packUnsafe(source = dest, dest = source, 1, dest.size - 4, dest.size)
println(dest.toList())
println(source.toList())
// [-5, -117, 99, -5, -4, -117, 99, -5]
// [0, -77362180]
Return
The dest array
Parameters
The ByteArray to retrieve bytes from to convert into Ints.
The IntArray to pack Ints into.
The position in dest to start packing.
The beginning (inclusive) of the source subrange.
The end (exclusive) of the source subrange.
See also
Throws
Packs 8
bytes from source Long into dest ByteArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = 9223372034707292160L
val dest = ByteArray(8) { -100 }
println(dest.toList())
// [-100, -100, -100, -100, -100, -100, -100, -100]
Endian.Big.packUnsafe(source, dest, 0)
println(dest.toList())
// [127, -1, -1, -1, -128, 0, 0, 0]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
println(dest.toList())
// [0, 0, 0, -128, -1, -1, -1, 127]
Return
The dest array
Parameters
The Long to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
See also
Throws
if an invalid index in dest is accessed.
Packs bytes from source Long (max 8
bytes) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest ByteArray, starting at destOffset. If sourceIndexStart is 0
and sourceIndexEnd is Long.SIZE_BYTES, the more performant packUnsafe function will be utilized.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = 9223372034707292160L
val dest = ByteArray(8) { -100 }
println(dest.toList())
// [-100, -100, -100, -100, -100, -100, -100, -100]
Endian.Big.packUnsafe(source, dest, 0)
println(dest.toList())
// [127, -1, -1, -1, -128, 0, 0, 0]
dest.fill(-100)
Endian.Big.packUnsafe(source, dest, 2, sourceIndexStart = 1, sourceIndexEnd = 7)
println(dest.toList())
// [-100, -100, -1, -1, -1, -128, 0, 0]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
println(dest.toList())
// [0, 0, 0, -128, -1, -1, -1, 127]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 1, sourceIndexStart = 3)
println(dest.toList())
// [-100, -128, -1, -1, -1, 127, -100, -100]
Return
The dest array
Parameters
The Long to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
The beginning (inclusive) of the source byte subrange.
The end (exclusive) of the source byte subrange, Long.SIZE_BYTES by default.
See also
Throws
if an invalid index in dest is accessed.
Packs bytes from source LongArray (max size * 8
bytes) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest ByteArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = LongArray(2) { i -> i + 9223372034707292160L }
val dest = ByteArray(source.size * Long.SIZE_BYTES) { -100 }
println(dest.toList())
println(source.toList())
// [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100]
// [9223372034707292160, 9223372034707292161]
Endian.Big.packUnsafe(source, dest, 0)
source.fill(0L)
Endian.Big.packUnsafe(source = dest, dest = source, 0, 0, sourceIndexEnd = dest.size)
println(dest.toList())
println(source.toList())
// [127, -1, -1, -1, -128, 0, 0, 0, 127, -1, -1, -1, -128, 0, 0, 1]
// [9223372034707292160, 9223372034707292161]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
source.fill(0L)
Endian.Little.packUnsafe(source = dest, dest = source, 1, dest.size - 8, dest.size)
println(dest.toList())
println(source.toList())
// [0, 0, 0, -128, -1, -1, -1, 127, 1, 0, 0, -128, -1, -1, -1, 127]
// [0, 9223372034707292161]
Return
The dest array
Parameters
The LongArray to retrieve Longs from to convert into bytes.
The ByteArray to pack bytes into.
The position in dest to start packing.
The beginning (inclusive) of the source subrange, 0
by default.
The end (exclusive) of the source subrange, source.size
by default.
See also
Throws
Packs Longs from source ByteArray (max size / 8
Longs) from sourceIndexStart (inclusive) to sourceIndexEnd (exclusive) into dest LongArray, starting at destOffset.
NOTE: This function does not check input parameters for correctness before altering the dest array, but is faster than pack because of it.
e.g.
val source = LongArray(2) { i -> i + 9223372034707292160L }
val dest = ByteArray(source.size * Long.SIZE_BYTES) { -100 }
println(dest.toList())
println(source.toList())
// [-100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100, -100]
// [9223372034707292160, 9223372034707292161]
Endian.Big.packUnsafe(source, dest, 0)
source.fill(0L)
Endian.Big.packUnsafe(source = dest, dest = source, 0, 0, sourceIndexEnd = dest.size)
println(dest.toList())
println(source.toList())
// [127, -1, -1, -1, -128, 0, 0, 0, 127, -1, -1, -1, -128, 0, 0, 1]
// [9223372034707292160, 9223372034707292161]
dest.fill(-100)
Endian.Little.packUnsafe(source, dest, 0)
source.fill(0L)
Endian.Little.packUnsafe(source = dest, dest = source, 1, dest.size - 8, dest.size)
println(dest.toList())
println(source.toList())
// [0, 0, 0, -128, -1, -1, -1, 127, 1, 0, 0, -128, -1, -1, -1, 127]
// [0, 9223372034707292161]
Return
The dest array
Parameters
The ByteArray to retrieve bytes from to convert into Longs.
The LongArray to pack Longs into.
The position in dest to start packing.
The beginning (inclusive) of the source subrange.
The end (exclusive) of the source subrange.