several more addings

This commit is contained in:
2020-09-26 22:19:20 +06:00
parent dd3b9f3674
commit c7d0f7856c
6 changed files with 84 additions and 0 deletions

6
common/build.gradle Normal file
View File

@@ -0,0 +1,6 @@
plugins {
id "org.jetbrains.kotlin.multiplatform"
id "org.jetbrains.kotlin.plugin.serialization"
}
apply from: "$mppProjectWithSerializationPresetPath"

View File

@@ -0,0 +1,10 @@
package dev.inmo.micro_utils.common
fun <T> Iterable<T>.syncWith(
other: Iterable<T>,
removed: (List<T>) -> Unit = {},
added: (List<T>) -> Unit = {}
) {
removed(filter { it !in other })
added(other.filter { it !in this })
}

View File

@@ -0,0 +1,27 @@
package dev.inmo.micro_utils.common
import kotlinx.serialization.KSerializer
import kotlinx.serialization.builtins.ByteArraySerializer
import kotlinx.serialization.descriptors.SerialDescriptor
import kotlinx.serialization.encoding.Decoder
import kotlinx.serialization.encoding.Encoder
typealias ByteArrayAllocator = () -> ByteArray
val ByteArray.asAllocator: ByteArrayAllocator
get() = { this }
object ByteArrayAllocatorSerializer : KSerializer<ByteArrayAllocator> {
private val realSerializer = ByteArraySerializer()
override val descriptor: SerialDescriptor = realSerializer.descriptor
override fun deserialize(decoder: Decoder): ByteArrayAllocator {
val bytes = realSerializer.deserialize(decoder)
return { bytes }
}
override fun serialize(encoder: Encoder, value: ByteArrayAllocator) {
realSerializer.serialize(encoder, value())
}
}