Add MetaConverter for DoubleArray and ByteArray

This commit is contained in:
Alexander Nozik 2024-07-22 11:48:39 +03:00
parent 523db20e4a
commit 5196d85da1

View File

@ -50,6 +50,7 @@ public class DoubleArrayValue(override val value: DoubleArray) : Value, Iterable
override fun iterator(): Iterator<Double> = value.iterator() override fun iterator(): Iterator<Double> = value.iterator()
} }
/** /**
* A zero-copy wrapping of this [DoubleArray] in a [Value] * A zero-copy wrapping of this [DoubleArray] in a [Value]
*/ */
@ -81,6 +82,14 @@ public fun MutableMetaProvider.doubleArray(
reader = { it?.doubleArray ?: doubleArrayOf(*default) }, reader = { it?.doubleArray ?: doubleArrayOf(*default) },
) )
private object DoubleArrayMetaConverter : MetaConverter<DoubleArray> {
override fun readOrNull(source: Meta): DoubleArray? = source.doubleArray
override fun convert(obj: DoubleArray): Meta = Meta(obj.asValue())
}
public val MetaConverter.Companion.doubleArray: MetaConverter<DoubleArray> get() = DoubleArrayMetaConverter
/** /**
* A [Value] wrapping a [ByteArray] * A [Value] wrapping a [ByteArray]
*/ */
@ -131,4 +140,12 @@ public fun MutableMetaProvider.byteArray(
key, key,
writer = { ByteArrayValue(it) }, writer = { ByteArrayValue(it) },
reader = { it?.byteArray ?: byteArrayOf(*default) }, reader = { it?.byteArray ?: byteArrayOf(*default) },
) )
private object ByteArrayMetaConverter : MetaConverter<ByteArray> {
override fun readOrNull(source: Meta): ByteArray? = source.byteArray
override fun convert(obj: ByteArray): Meta = Meta(obj.asValue())
}
public val MetaConverter.Companion.byteArray: MetaConverter<ByteArray> get() = ByteArrayMetaConverter