commands.BakuCommandFactory.kt Maven / Gradle / Ivy
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)