Replace custom json coders with default

This commit is contained in:
Andrey Stoyan 2022-05-25 13:51:26 +03:00
parent 77f8f045e6
commit 114d310fdc
4 changed files with 6 additions and 71 deletions

View File

@ -1,6 +1,7 @@
package space.kscience.dataforge.distributed
import io.ktor.utils.io.core.*
import io.lambdarpc.coding.coders.JsonCoder
import io.lambdarpc.dsl.LibService
import io.lambdarpc.dsl.def
import io.lambdarpc.dsl.j
@ -13,10 +14,8 @@ import space.kscience.dataforge.context.gather
import space.kscience.dataforge.data.DataSet
import space.kscience.dataforge.data.DataTree
import space.kscience.dataforge.distributed.serialization.DataSetPrototype
import space.kscience.dataforge.distributed.serialization.MetaCoder
import space.kscience.dataforge.distributed.serialization.NameCoder
import space.kscience.dataforge.distributed.serialization.TaskRegistryCoder
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.MetaSerializer
import space.kscience.dataforge.names.Name
import space.kscience.dataforge.names.asName
import space.kscience.dataforge.workspace.SerializableResultTask
@ -114,6 +113,9 @@ public class ServiceWorkspace(
public companion object {
internal val serviceId = ServiceId("d41b95b1-828b-4444-8ff0-6f9c92a79246")
internal val execute by serviceId.def(NameCoder, MetaCoder, TaskRegistryCoder, j<DataSetPrototype>())
internal val execute by serviceId.def(
JsonCoder(Name.serializer()), JsonCoder(MetaSerializer), j<TaskRegistry>(),
j<DataSetPrototype>()
)
}
}

View File

@ -1,23 +0,0 @@
package space.kscience.dataforge.distributed.serialization
import io.lambdarpc.coding.Coder
import io.lambdarpc.coding.CodingContext
import io.lambdarpc.transport.grpc.Entity
import io.lambdarpc.transport.serialization.Entity
import io.lambdarpc.transport.serialization.RawData
import kotlinx.serialization.json.Json
import space.kscience.dataforge.meta.Meta
import space.kscience.dataforge.meta.MetaSerializer
import java.nio.charset.Charset
internal object MetaCoder : Coder<Meta> {
override suspend fun decode(entity: Entity, context: CodingContext): Meta {
val string = entity.data.toString(Charset.defaultCharset())
return Json.decodeFromString(MetaSerializer, string)
}
override suspend fun encode(value: Meta, context: CodingContext): Entity {
val string = Json.encodeToString(MetaSerializer, value)
return Entity(RawData.copyFrom(string, Charset.defaultCharset()))
}
}

View File

@ -1,22 +0,0 @@
package space.kscience.dataforge.distributed.serialization
import io.lambdarpc.coding.Coder
import io.lambdarpc.coding.CodingContext
import io.lambdarpc.transport.grpc.Entity
import io.lambdarpc.transport.serialization.Entity
import io.lambdarpc.transport.serialization.RawData
import kotlinx.serialization.json.Json
import space.kscience.dataforge.names.Name
import java.nio.charset.Charset
internal object NameCoder : Coder<Name> {
override suspend fun decode(entity: Entity, context: CodingContext): Name {
val string = entity.data.toString(Charset.defaultCharset())
return Json.decodeFromString(Name.serializer(), string)
}
override suspend fun encode(value: Name, context: CodingContext): Entity {
val string = Json.encodeToString(Name.serializer(), value)
return Entity(RawData.copyFrom(string, Charset.defaultCharset()))
}
}

View File

@ -1,22 +0,0 @@
package space.kscience.dataforge.distributed.serialization
import io.lambdarpc.coding.Coder
import io.lambdarpc.coding.CodingContext
import io.lambdarpc.transport.grpc.Entity
import io.lambdarpc.transport.serialization.Entity
import io.lambdarpc.transport.serialization.RawData
import kotlinx.serialization.json.Json
import space.kscience.dataforge.distributed.TaskRegistry
import java.nio.charset.Charset
internal object TaskRegistryCoder : Coder<TaskRegistry> {
override suspend fun decode(entity: Entity, context: CodingContext): TaskRegistry {
val string = entity.data.toString(Charset.defaultCharset())
return Json.decodeFromString(TaskRegistry.serializer(), string)
}
override suspend fun encode(value: TaskRegistry, context: CodingContext): Entity {
val string = Json.encodeToString(TaskRegistry.serializer(), value)
return Entity(RawData.copyFrom(string, Charset.defaultCharset()))
}
}