forked from cobalt/cobalt
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5e6b4a1
commit faf1e61
Showing
8 changed files
with
95 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,11 @@ | ||
import Versions.korVersion | ||
import Versions.kotlinxCollectionsImmutableVersion | ||
import Versions.KOR_VERSION | ||
import Versions.KOTLINX_COLLECTIONS_IMMUTABLE_VERSION | ||
|
||
object Libraries { | ||
|
||
const val kotlinReflect = "org.jetbrains.kotlin:kotlin-reflect" | ||
const val kotlinxCollectionsImmutable = | ||
"org.jetbrains.kotlinx:kotlinx-collections-immutable:$kotlinxCollectionsImmutableVersion" | ||
const val KOTLIN_REFLECT = "org.jetbrains.kotlin:kotlin-reflect" | ||
const val KOTLINX_COLLECTIONS_IMMUTABLE = | ||
"org.jetbrains.kotlinx:kotlinx-collections-immutable:$KOTLINX_COLLECTIONS_IMMUTABLE_VERSION" | ||
|
||
|
||
const val korio = "com.soywiz.korlibs.korio:korio:$korVersion" | ||
const val klogger = "com.soywiz.korlibs.klogger:klogger:$korVersion" | ||
|
||
// TEST | ||
const val kotlinTestCommon = "org.jetbrains.kotlin:kotlin-test-common" | ||
const val kotlinTestAnnotationsCommon = "org.jetbrains.kotlin:kotlin-test-annotations-common" | ||
const val kotlinTestJunit = "org.jetbrains.kotlin:kotlin-test-junit" | ||
const val kotlinTestJs = "org.jetbrains.kotlin:kotlin-test-js" | ||
const val KORGE_FOUNDATION = "com.soywiz.korge:korge-foundation:$KOR_VERSION" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
object Versions { | ||
|
||
const val kotlinxCollectionsImmutableVersion = "0.3.5" | ||
const val KOTLINX_COLLECTIONS_IMMUTABLE_VERSION = "0.3.5" | ||
|
||
const val korVersion = "4.0.8" | ||
const val KOR_VERSION = "5.3.0" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 43 additions & 3 deletions
46
cobalt.core/src/commonMain/kotlin/org/hexworks/cobalt/core/internal/DefaultUUID.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,48 @@ | ||
package org.hexworks.cobalt.core.internal | ||
|
||
import org.hexworks.cobalt.core.api.UUID | ||
import kotlin.random.Random | ||
|
||
|
||
internal class DefaultUUID(private val backend: korlibs.io.util.UUID) : UUID { | ||
override fun toString() = backend.toString() | ||
} | ||
@Suppress("EXPERIMENTAL_API_USAGE") | ||
@OptIn(ExperimentalStdlibApi::class, ExperimentalUnsignedTypes::class) | ||
class DefaultUUID(val data: UByteArray) : UUID { | ||
override fun equals(other: Any?): Boolean = other is DefaultUUID && this.data.contentEquals(other.data) | ||
override fun hashCode(): Int = this.data.contentHashCode() | ||
|
||
companion object { | ||
private const val HEX = "0123456789ABCDEF" | ||
|
||
private val regex = | ||
Regex("[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}", RegexOption.IGNORE_CASE) | ||
|
||
val NIL: UUID get() = DefaultUUID("00000000-0000-0000-0000-000000000000") | ||
|
||
private fun fix(data: UByteArray, version: Int, variant: Int): UByteArray { | ||
data[6] = ((data[6].toInt() and 0b0000_1111) or (version shl 4)).toUByte() | ||
data[8] = ((data[8].toInt() and 0x00_111111) or (variant shl 6)).toUByte() | ||
return data | ||
} | ||
|
||
fun randomDefaultUUID(random: Random = Random): UUID = DefaultUUID(fix(UByteArray(16).apply { | ||
random.nextBytes(this.asByteArray()) | ||
}, version = 4, variant = 1)) | ||
|
||
operator fun invoke(str: String): UUID { | ||
if (regex.matchEntire(str) == null) throw IllegalArgumentException("Invalid DefaultUUID") | ||
return DefaultUUID(str.replace("-", "").hexToUByteArray()) | ||
} | ||
} | ||
|
||
val version: Int get() = (data[6].toInt() ushr 4) and 0b1111 | ||
val variant: Int get() = (data[8].toInt() ushr 6) and 0b11 | ||
|
||
override fun toString(): String = buildString(36) { | ||
for (n in 0 until 16) { | ||
val c = data[n].toInt() | ||
append(HEX[c shr 4]) | ||
append(HEX[c and 0xF]) | ||
if (n == 3 || n == 5 || n == 7 || n == 9) append('-') | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,3 @@ | ||
./gradlew publish --no-daemon --no-parallel | ||
#!/usr/bin/env bash | ||
|
||
./gradlew publish --no-parallel --no-daemon |