putUuid

Writes the specified uuid value at this buffer's current position.

This function writes 16 bytes containing the given uuid value into this buffer at the current position. As a result, the buffer's position is incremented by 16.

Note that this function ignores the buffer's byte order. The 16 bytes are written sequentially, with each byte representing the next 8 bits of the uuid, starting from the first byte representing the most significant 8 bits to the last byte representing the least significant 8 bits.

This function is equivalent to:

byteBuffer.put(uuid.toByteArray())

Since Kotlin

2.0

Return

This byte buffer.

Parameters

uuid

The uuid value to write.

See also

Throws

If there is insufficient space in this buffer for 16 bytes.

If this buffer is read-only.

Samples

import kotlin.uuid.*

fun main() { 
   //sampleStart 
   val uuid = Uuid.parse("550e8400-e29b-41d4-a716-446655440000")
val bytes = ByteArray(16)
val buffer = java.nio.ByteBuffer.wrap(bytes)
buffer.putUuid(uuid)

// The written 16 bytes are exactly equal to the uuid bytes
println(bytes.contentEquals(uuid.toByteArray())) // true 
   //sampleEnd
}

Writes the specified uuid value at the specified index.

This function writes 16 bytes containing the given uuid value into this buffer at the specified index. The buffer's position, however, is not updated.

Note that this function ignores the buffer's byte order. The 16 bytes are written sequentially, with each byte representing the next 8 bits of the uuid, starting from the first byte representing the most significant 8 bits to the last byte representing the least significant 8 bits.

This function is equivalent to:

val bytes = uuid.toByteArray()
bytes.forEachIndexed { i, byte ->
byteBuffer.put(index + i, byte)
}

except that this function first checks that there is sufficient space in the buffer.

Since Kotlin

2.0

Return

This byte buffer.

Parameters

index

The index to write the specified uuid value at.

uuid

The uuid value to write.

See also

Throws

If index is negative or index + 15 is not smaller than this buffer's limit.

If this buffer is read-only.

Samples

import kotlin.uuid.*

fun main() { 
   //sampleStart 
   val uuid = Uuid.parse("550e8400-e29b-41d4-a716-446655440000")
val bytes = ByteArray(20)
val buffer = java.nio.ByteBuffer.wrap(bytes)
buffer.putUuid(index = 2, uuid)

// The written 16 bytes are exactly equal to the uuid bytes
val writtenBytes = bytes.sliceArray(2..<18)
println(writtenBytes.contentEquals(uuid.toByteArray())) // true 
   //sampleEnd
}