more sugar & unsigned support

This commit is contained in:
Sergey Chernov 2024-06-30 12:50:52 +07:00
parent 1fd229fdb1
commit 904a91b8de
8 changed files with 247 additions and 1063 deletions

3
bin/pubdocs Executable file
View File

@ -0,0 +1,3 @@
#!/bin/bash
rsync -avz ./build/dokka/* 77.37.192.214:/bigstore/sergeych_pub/code/docs/mp_bintools

View File

@ -1,14 +1,14 @@
plugins {
kotlin("multiplatform") version "2.0.0"
kotlin("plugin.serialization") version "2.0.0"
id("org.jetbrains.dokka") version "1.9.10"
id("org.jetbrains.dokka") version "1.9.20"
`maven-publish`
}
val serialization_version = "1.6.5-SNAPSHOT"
group = "net.sergeych"
version = "0.1.5-SNAPSHOT"
version = "0.1.6-SNAPSHOT"
repositories {
mavenCentral()
@ -51,7 +51,7 @@ kotlin {
wasmJs {
browser()
binaries.executable()
// binaries.executable()
}

File diff suppressed because it is too large Load Diff

View File

@ -1,5 +1,6 @@
package net.sergeych.bintools
@Suppress("unused")
interface DataSink {
fun writeByte(data: Byte)
@ -24,9 +25,9 @@ interface DataSink {
}
fun writeVarUInt(value: UInt) { Varint.encodeUnsigned(value.toULong(), this)}
fun writeVarInt(value: UInt) { Varint.encodeSigned(value.toLong(), this)}
fun writeVarInt(value: Int) { Varint.encodeSigned(value.toLong(), this)}
fun writeSmartUInt(value: UInt) { Smartint.encodeUnsigned(value.toULong(), this)}
fun writeSmartInt(value: UInt) { Smartint.encodeSigned(value.toLong(), this)}
fun writeSmartInt(value: Int) { Smartint.encodeSigned(value.toLong(), this)}
}
inline fun <reified T:Any>DataSink.writeNumber(value: T) {

View File

@ -3,6 +3,7 @@ package net.sergeych.bipack
import kotlinx.datetime.Instant
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.KSerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.descriptors.StructureKind
import kotlinx.serialization.encoding.AbstractDecoder
@ -143,7 +144,16 @@ class BipackDecoder(
inline fun <reified T> decode(source: DataSource): T = decode(source, serializer())
inline fun <reified T> decode(source: ByteArray): T =
decode(source.toDataSource(), serializer())
fun <T> decode(serializer: KSerializer<T>, source: ByteArray): T =
decode(source.toDataSource(), serializer)
inline fun <reified T> decode(source: UByteArray): T =
decode(source.toDataSource(), serializer())
fun <T> decode(serializer: KSerializer<T>, source: UByteArray): T =
decode(source.toDataSource(), serializer)
}
}
inline fun <reified T> ByteArray.decodeFromBipack() = BipackDecoder.decode<T>(this)
@Suppress("unused")
inline fun <reified T> UByteArray.decodeFromBipack() = BipackDecoder.decode<T>(this)

View File

@ -126,3 +126,8 @@ class BipackEncoder(val output: DataSink) : AbstractEncoder() {
}
}
@Suppress("unused")
inline fun <reified T> toBipackUByteArray(value: T): UByteArray = BipackEncoder.encode(value).toUByteArray()
@Suppress("unused")
inline fun <reified T> toBipackByteArray(value: T): ByteArray = BipackEncoder.encode(value)

View File

@ -0,0 +1,9 @@
import kotlin.test.Test
class EmptyTest {
@Test
fun emptyTest() {
println("hello!")
}
}

View File

@ -5,6 +5,11 @@ import kotlin.test.assertNull
import kotlin.test.assertTrue
class StorageTest {
@Test
fun emptyTest() {
println("hello")
}
@Test
fun storageTest() {
val s1 = defaultNamedStorage("test_mp_bintools")