All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.copperleaf.ballast.debugger.models.json.kt Maven / Gradle / Ivy

There is a newer version: 3.0.2
Show newest version
package com.copperleaf.ballast.debugger.models

import com.benasher44.uuid.uuid4
import com.copperleaf.ballast.BallastNotification
import kotlinx.serialization.json.Json

public val debuggerEventJson: Json = Json {
    isLenient = true
}

public fun  BallastNotification.serialize(
    connectionId: String,
    uuid: String = uuid4().toString(),
): BallastDebuggerEvent {
    return when (this) {
        is BallastNotification.ViewModelStarted -> {
            BallastDebuggerEvent.ViewModelStarted(connectionId, vm.name, uuid)
        }
        is BallastNotification.ViewModelCleared -> {
            BallastDebuggerEvent.ViewModelCleared(connectionId, vm.name, uuid)
        }
        is BallastNotification.InputAccepted -> {
            BallastDebuggerEvent.InputAccepted(connectionId, vm.name, uuid, input.type, input.toString())
        }
        is BallastNotification.InputRejected -> {
            BallastDebuggerEvent.InputRejected(connectionId, vm.name, uuid, input.type, input.toString())
        }
        is BallastNotification.InputDropped -> {
            BallastDebuggerEvent.InputDropped(connectionId, vm.name, uuid, input.type, input.toString())
        }
        is BallastNotification.InputHandledSuccessfully -> {
            BallastDebuggerEvent.InputHandledSuccessfully(connectionId, vm.name, uuid, input.type, input.toString())
        }
        is BallastNotification.InputCancelled -> {
            BallastDebuggerEvent.InputCancelled(connectionId, vm.name, uuid, input.type, input.toString())
        }
        is BallastNotification.InputHandlerError -> {
            BallastDebuggerEvent.InputHandlerError(connectionId, vm.name, uuid, input.type, input.toString())
        }
        is BallastNotification.EventEmitted -> {
            BallastDebuggerEvent.EventEmitted(connectionId, vm.name, uuid, event.type, event.toString())
        }
        is BallastNotification.EventHandledSuccessfully -> {
            BallastDebuggerEvent.EventHandledSuccessfully(connectionId, vm.name, uuid, event.type, event.toString())
        }
        is BallastNotification.EventHandlerError -> {
            BallastDebuggerEvent.EventHandlerError(connectionId, vm.name, uuid, event.type, event.toString())
        }
        is BallastNotification.EventProcessingStarted -> {
            BallastDebuggerEvent.EventProcessingStarted(connectionId, vm.name, uuid)
        }
        is BallastNotification.EventProcessingStopped -> {
            BallastDebuggerEvent.EventProcessingStopped(connectionId, vm.name, uuid)
        }
        is BallastNotification.StateChanged -> {
            BallastDebuggerEvent.StateChanged(connectionId, vm.name, uuid, state.toString())
        }
        is BallastNotification.SideEffectStarted -> {
            BallastDebuggerEvent.SideEffectStarted(connectionId, vm.name, uuid, key, restartState)
        }
        is BallastNotification.SideEffectCompleted -> {
            BallastDebuggerEvent.SideEffectCompleted(connectionId, vm.name, uuid, key)
        }
        is BallastNotification.SideEffectError -> {
            BallastDebuggerEvent.SideEffectError(connectionId, vm.name, uuid, key)
        }
        is BallastNotification.UnhandledError -> {
            BallastDebuggerEvent.UnhandledError(connectionId, vm.name, uuid)
        }
    }
}

private val Any.type: String get() = this::class.simpleName ?: ""




© 2015 - 2025 Weber Informatics LLC | Privacy Policy