Advertisement
Guest User

Untitled

a guest
Jul 16th, 2019
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. package com.neuronrobotics.bowlerkernel.kinematics.limb.link.model
  2.  
  3. import arrow.*
  4. import arrow.core.*
  5. import helios.core.*
  6. import helios.instances.*
  7. import helios.typeclasses.*
  8. import helios.syntax.json.*
  9. import arrow.core.extensions.either.applicative.applicative
  10.  
  11. fun LinkConfigurationData.toJson(): Json = JsObject(mapOf(
  12. "dhParamData" to com.neuronrobotics.bowlerkernel.kinematics.limb.model.DhParamData.encoder().run { dhParamData.encode() }
  13. ,
  14. "type" to com.neuronrobotics.bowlerkernel.kinematics.limb.link.LinkType.encoder().run { type.encode() }
  15. ))
  16.  
  17. fun Json.Companion.toLinkConfigurationData(value: Json): Either<DecodingError, LinkConfigurationData> =
  18. Either.applicative<DecodingError>().map(
  19. value["dhParamData"].fold({Either.Left(KeyNotFound("dhParamData"))}, { com.neuronrobotics.bowlerkernel.kinematics.limb.model.DhParamData.decoder().run { decode(it) } }),
  20. value["type"].fold({Either.Left(KeyNotFound("type"))}, { com.neuronrobotics.bowlerkernel.kinematics.limb.link.LinkType.decoder().run { decode(it) } })
  21. , { (dhParamData,type) ->
  22. LinkConfigurationData(dhParamData = dhParamData,type = type)
  23. }).fix()
  24.  
  25.  
  26.  
  27. fun LinkConfigurationData.Companion.encoder() = object : Encoder<LinkConfigurationData> {
  28. override fun LinkConfigurationData.encode(): Json = this.toJson()
  29. }
  30.  
  31. fun LinkConfigurationData.Companion.decoder() = object : Decoder<LinkConfigurationData> {
  32. override fun decode(value: Json): Either<DecodingError, LinkConfigurationData> =
  33. Json.toLinkConfigurationData(value)
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement