putInt32Le

fun ByteArray.putInt32Le(offset: Int, value: Int, validRange: IntRange = Int.MIN_VALUE..Int.MAX_VALUE)

Writes an Int32 value to the byte array at the specified offset in little-endian order.

This function takes an integer value and writes it as four bytes (Int32) into the byte array at the specified offset using little-endian byte order. It also validates that the value falls within a specified range, ensuring it can be represented as a four-byte integer.

Parameters

offset

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

value

The Int32 value to be written.

validRange

The valid range for the value. Defaults to Int.MIN_VALUE to Int.MAX_VALUE (i.e., -2147483648 to 2147483647). 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 + 3 is negative or greater than or equal to the array's size.