commands.BakuCommandFactory.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of baku Show documentation
Show all versions of baku Show documentation
helps you focus your REST API back-end on the business logic
package com.github.fluidsonic.baku
import com.github.fluidsonic.fluid.json.*
abstract class BakuCommandFactory(
name: String
) {
val name = BakuCommandName(name)
abstract fun JSONDecoder.decodeCommand(): Command
open fun JSONEncoder.encodeResult(result: Result) {
writeIntoMap {}
}
abstract class Empty(
name: String
) : BakuCommandFactory(name = name) {
abstract fun createCommand(): Command
final override fun JSONDecoder.decodeCommand() =
createCommand().also { skipValue() }
}
}
fun BakuCommandFactory.encodeResult(result: Result, encoder: JSONEncoder) =
encoder.encodeResult(result)