Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.neuronrobotics.bowlerkernel.kinematics.limb.link.model
- import arrow.*
- import arrow.core.*
- import helios.core.*
- import helios.instances.*
- import helios.typeclasses.*
- import helios.syntax.json.*
- import arrow.core.extensions.either.applicative.applicative
- fun LinkConfigurationData.toJson(): Json = JsObject(mapOf(
- "dhParamData" to com.neuronrobotics.bowlerkernel.kinematics.limb.model.DhParamData.encoder().run { dhParamData.encode() }
- ,
- "type" to com.neuronrobotics.bowlerkernel.kinematics.limb.link.LinkType.encoder().run { type.encode() }
- ))
- fun Json.Companion.toLinkConfigurationData(value: Json): Either<DecodingError, LinkConfigurationData> =
- Either.applicative<DecodingError>().map(
- value["dhParamData"].fold({Either.Left(KeyNotFound("dhParamData"))}, { com.neuronrobotics.bowlerkernel.kinematics.limb.model.DhParamData.decoder().run { decode(it) } }),
- value["type"].fold({Either.Left(KeyNotFound("type"))}, { com.neuronrobotics.bowlerkernel.kinematics.limb.link.LinkType.decoder().run { decode(it) } })
- , { (dhParamData,type) ->
- LinkConfigurationData(dhParamData = dhParamData,type = type)
- }).fix()
- fun LinkConfigurationData.Companion.encoder() = object : Encoder<LinkConfigurationData> {
- override fun LinkConfigurationData.encode(): Json = this.toJson()
- }
- fun LinkConfigurationData.Companion.decoder() = object : Decoder<LinkConfigurationData> {
- override fun decode(value: Json): Either<DecodingError, LinkConfigurationData> =
- Json.toLinkConfigurationData(value)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement