From 5196d85da1cd87996a1232683855a3119f8318c1 Mon Sep 17 00:00:00 2001 From: Alexander Nozik Date: Mon, 22 Jul 2024 11:48:39 +0300 Subject: [PATCH] Add MetaConverter for DoubleArray and ByteArray --- .../kscience/dataforge/meta/exoticValues.kt | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/exoticValues.kt b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/exoticValues.kt index 91811390..17436990 100644 --- a/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/exoticValues.kt +++ b/dataforge-meta/src/commonMain/kotlin/space/kscience/dataforge/meta/exoticValues.kt @@ -50,6 +50,7 @@ public class DoubleArrayValue(override val value: DoubleArray) : Value, Iterable override fun iterator(): Iterator = value.iterator() } + /** * A zero-copy wrapping of this [DoubleArray] in a [Value] */ @@ -81,6 +82,14 @@ public fun MutableMetaProvider.doubleArray( reader = { it?.doubleArray ?: doubleArrayOf(*default) }, ) +private object DoubleArrayMetaConverter : MetaConverter { + override fun readOrNull(source: Meta): DoubleArray? = source.doubleArray + + override fun convert(obj: DoubleArray): Meta = Meta(obj.asValue()) +} + +public val MetaConverter.Companion.doubleArray: MetaConverter get() = DoubleArrayMetaConverter + /** * A [Value] wrapping a [ByteArray] */ @@ -131,4 +140,12 @@ public fun MutableMetaProvider.byteArray( key, writer = { ByteArrayValue(it) }, reader = { it?.byteArray ?: byteArrayOf(*default) }, -) \ No newline at end of file +) + +private object ByteArrayMetaConverter : MetaConverter { + override fun readOrNull(source: Meta): ByteArray? = source.byteArray + + override fun convert(obj: ByteArray): Meta = Meta(obj.asValue()) +} + +public val MetaConverter.Companion.byteArray: MetaConverter get() = ByteArrayMetaConverter \ No newline at end of file