Compare commits
No commits in common. "895193ba1c1023f2a47ee5dec9b6c88fa235d707" and "748f273fb93199d53cf6ae85d86229b6d5b71d62" have entirely different histories.
895193ba1c
...
748f273fb9
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,5 +1,3 @@
|
|||||||
.gradle
|
.gradle
|
||||||
.idea
|
.idea
|
||||||
build
|
build
|
||||||
.gigaide
|
|
||||||
.kotlin
|
|
@ -3,14 +3,14 @@ val kotlin_version: String by project
|
|||||||
val logback_version: String by project
|
val logback_version: String by project
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
kotlin("multiplatform") version "2.1.0"
|
kotlin("multiplatform") version "1.7.21"
|
||||||
kotlin("plugin.serialization") version "2.1.0"
|
kotlin("plugin.serialization") version "1.7.21"
|
||||||
id("org.jetbrains.dokka") version "1.9.20"
|
id("org.jetbrains.dokka") version "1.7.20"
|
||||||
`maven-publish`
|
`maven-publish`
|
||||||
}
|
}
|
||||||
|
|
||||||
group = "net.sergeych"
|
group = "net.sergeych"
|
||||||
version = "0.5.2"
|
version = "0.4.6"
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
@ -24,9 +24,9 @@ kotlin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
jvm {
|
jvm {
|
||||||
// compilations.all {
|
compilations.all {
|
||||||
// kotlinOptions.jvmTarget = "1.8"
|
kotlinOptions.jvmTarget = "1.8"
|
||||||
// }
|
}
|
||||||
withJava()
|
withJava()
|
||||||
testRuns["test"].executionTask.configure {
|
testRuns["test"].executionTask.configure {
|
||||||
useJUnitPlatform()
|
useJUnitPlatform()
|
||||||
@ -35,7 +35,7 @@ kotlin {
|
|||||||
js(IR) {
|
js(IR) {
|
||||||
browser {
|
browser {
|
||||||
commonWebpackConfig {
|
commonWebpackConfig {
|
||||||
// cssSupport.enabled = true
|
cssSupport.enabled = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
kotlin.code.style=official
|
kotlin.code.style=official
|
||||||
|
kotlin.mpp.enableGranularSourceSetsMetadata=true
|
||||||
|
kotlin.native.enableDependencyPropagation=false
|
||||||
kotlin.js.generate.executable.default=false
|
kotlin.js.generate.executable.default=false
|
||||||
ktor_version=2.1.1
|
ktor_version=2.1.1
|
||||||
logback_version=1.2.10
|
logback_version=1.2.10
|
||||||
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
@ -1,5 +1,5 @@
|
|||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-8.2-bin.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-7.4.2-bin.zip
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
@ -2,10 +2,6 @@ package net.sergeych.parsec3
|
|||||||
|
|
||||||
import net.sergeych.boss_serialization.BossDecoder
|
import net.sergeych.boss_serialization.BossDecoder
|
||||||
import net.sergeych.boss_serialization_mp.BossEncoder
|
import net.sergeych.boss_serialization_mp.BossEncoder
|
||||||
import net.sergeych.mp_logger.LogTag
|
|
||||||
import net.sergeych.mp_logger.exception
|
|
||||||
import net.sergeych.mp_logger.info
|
|
||||||
import net.sergeych.mptools.encodeToHex
|
|
||||||
import net.sergeych.mptools.toDump
|
import net.sergeych.mptools.toDump
|
||||||
import kotlin.reflect.KProperty
|
import kotlin.reflect.KProperty
|
||||||
import kotlin.reflect.KType
|
import kotlin.reflect.KType
|
||||||
@ -62,21 +58,20 @@ interface KVStorage {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline operator fun <reified T> KVStorage.invoke(defaultValue: T, overrideName: String? = null) =
|
inline operator fun <reified T> KVStorage.invoke(defaultValue: T,overrideName: String? = null) =
|
||||||
KVStorageDelegate<T>(this, typeOf<T>(), defaultValue, overrideName)
|
KVStorageDelegate<T>(this, typeOf<T>(), defaultValue, overrideName)
|
||||||
|
|
||||||
inline fun <reified T> KVStorage.stored(defaultValue: T, overrideName: String? = null) =
|
inline fun <reified T> KVStorage.stored(defaultValue: T, overrideName: String? = null) =
|
||||||
KVStorageDelegate<T>(this, typeOf<T>(), defaultValue, overrideName)
|
KVStorageDelegate<T>(this, typeOf<T>(), defaultValue, overrideName)
|
||||||
|
inline fun <reified T> KVStorage.optStored(defaultValue: T?=null, overrideName: String? = null) =
|
||||||
inline fun <reified T> KVStorage.optStored(defaultValue: T? = null, overrideName: String? = null) =
|
KVStorageDelegate<T?>(this, typeOf<T?>(), defaultValue, overrideName)
|
||||||
KVStorageDelegate<T?>(this, typeOf<T>(), defaultValue, overrideName)
|
|
||||||
|
|
||||||
class KVStorageDelegate<T>(
|
class KVStorageDelegate<T>(
|
||||||
private val storage: KVStorage,
|
private val storage: KVStorage,
|
||||||
private val type: KType,
|
private val type: KType,
|
||||||
private val defaultValue: T,
|
private val defaultValue: T,
|
||||||
private val overrideName: String? = null,
|
private val overrideName: String? = null,
|
||||||
): LogTag("KVSD") {
|
) {
|
||||||
|
|
||||||
private fun name(property: KProperty<*>): String = overrideName ?: property.name
|
private fun name(property: KProperty<*>): String = overrideName ?: property.name
|
||||||
|
|
||||||
@ -89,24 +84,17 @@ class KVStorageDelegate<T>(
|
|||||||
if (data == null)
|
if (data == null)
|
||||||
cachedValue = defaultValue
|
cachedValue = defaultValue
|
||||||
else
|
else
|
||||||
cachedValue = try {
|
cachedValue = BossDecoder.decodeFrom(type, data)
|
||||||
info { " get ${name(property)}: ${type} [{${data.encodeToHex()}" }
|
|
||||||
BossDecoder.decodeFrom<T>(type, data)
|
|
||||||
.also { println("decoded as $it") }
|
|
||||||
} catch (e: Exception) {
|
|
||||||
exception { "failed to decode ${name(property)}: ${type}" to e }
|
|
||||||
defaultValue
|
|
||||||
}
|
|
||||||
cacheReady = true
|
cacheReady = true
|
||||||
return cachedValue
|
return cachedValue
|
||||||
}
|
}
|
||||||
|
|
||||||
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
operator fun setValue(thisRef: Any?, property: KProperty<*>, value: T) {
|
||||||
// if (!cacheReady || value != cachedValue) {
|
// if (!cacheReady || value != cachedValue) {
|
||||||
cachedValue = value
|
cachedValue = value
|
||||||
cacheReady = true
|
cacheReady = true
|
||||||
println("set ${name(property)} to ${BossEncoder.encode(type, value).toDump()}")
|
println("set ${name(property)} to ${BossEncoder.encode(type, value).toDump()}")
|
||||||
storage[name(property)] = BossEncoder.encode(type, value)
|
storage[name(property)] = BossEncoder.encode(type, value)
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user