refactoring
This commit is contained in:
27
src/main/kotlin/eventDemo/app/command/GameCommandStream.kt
Normal file
27
src/main/kotlin/eventDemo/app/command/GameCommandStream.kt
Normal file
@@ -0,0 +1,27 @@
|
||||
package eventDemo.app.command
|
||||
|
||||
import eventDemo.libs.command.CommandStream
|
||||
import eventDemo.libs.command.CommandStreamChannel
|
||||
import eventDemo.libs.command.CommandStreamInMemory
|
||||
import io.ktor.websocket.Frame
|
||||
import kotlinx.coroutines.channels.ReceiveChannel
|
||||
import kotlinx.coroutines.channels.SendChannel
|
||||
import kotlinx.serialization.json.Json
|
||||
|
||||
/**
|
||||
* A stream to publish and read the game command.
|
||||
*/
|
||||
class GameCommandStreamInMemory : CommandStreamInMemory<GameCommand>()
|
||||
|
||||
/**
|
||||
* A stream to publish and read the game command.
|
||||
*/
|
||||
class GameCommandStream(
|
||||
incoming: ReceiveChannel<Frame>,
|
||||
outgoing: SendChannel<Frame>,
|
||||
) : CommandStream<GameCommand> by CommandStreamChannel(
|
||||
incoming,
|
||||
outgoing,
|
||||
{ Json.encodeToString(GameCommand.serializer(), it) },
|
||||
{ Json.decodeFromString(GameCommand.serializer(), it) },
|
||||
)
|
||||
Reference in New Issue
Block a user