putInt64

fun ByteArray.putInt64(offset: Int, value: Long, validRange: LongRange = Long.MIN_VALUE..Long.MAX_VALUE)

Writes an Int64 value to the byte array at the specified offset.

This function takes a long value and writes it as eight bytes (Int64) into the byte array at the specified offset. It also validates that the value falls within a specified range, ensuring it can be represented as an eight-byte integer.

Parameters

offset

The offset (index) in the byte array where the Int64 value should be written. Must be within the valid range of the array's indices.

value

The Int64 value to be written.

validRange

The valid range for the value. Defaults to Long.MIN_VALUE to Long.MAX_VALUE (i.e., -9223372036854775808 to 9223372036854775807). Any value outside this range will cause an exception to be thrown.

Throws

If the value is outside the specified validRange.

If the offset or offset + 7 is negative or greater than or equal to the array's size.