/kuuid

Primary LanguageKotlinApache License 2.0Apache-2.0

Binom UUID

GitHub license Kotlin 1.9.23

Description

Library UUID v4 implementation

Get starting

Add to your build.gradle.kts file new dependency:

kotlin {
    api("pw.binom:uuid:0.0.7") // uuid library
    api("pw.binom:uuid-serialization:0.0.7") // serialization uuid library for kotlinx-serialization
}

Example

import pw.binom.uuid.UUID

Random.nextUuid() // generate random uuid
"f9d992e7-94f4-4697-88e7-099e580a6bc1".toUUID() // returns uuid or throw exception
"f9d992e7-94f4-4697-88e7-099e580a6bc1".toUUIDOrNull() // returns uuid or null in cases when string content has not valid uuid
UUID.random() // generate random uuid
UUID.create(data = byteArrayOf(/*bytes*/), offset = 0) // create from byte array
UUID.create(mostSigBits = 10L, leastSigBits = 20L) // create from two longs
UUID.fromString("f9d992e7-94f4-4697-88e7-099e580a6bc1") // create from string
UUID.random().toByteArray() // convert uuid to byte array
UUID.random().toByteArray(destination = ByteArray(UUID.SIZE_BYTES), destinationOffset = 0) // convert uuid to given byte array, not creating new
UUID.random().toString() // converting to string
UUID.random().toShortString() // getting uuid as "short uuid" (first 8 bytes of uuid)