Edward Taylor
01/20/2020, 9:00 PMsealed class ManyHandsData: JSAction() {
@Serializable
data class handError(val message: String, val errorCode: Int): ManyHandsData()
@Serializable
data class DATA_INPUT(val openSensorInput: Int, val closeSensorInput: Int): ManyHandsData()
@Serializable
data class currentGripDidChangeExtended(val currentGrip: Int, val buttonSelected: Int, val currentButtonIndex: Int): ManyHandsData()
}
I've tried this:
internal val handDataActionSerializers = listOf(
JSAction.ManyHandsData.handError.serializer(),
JSAction.ManyHandsData.DATA_INPUT.serializer(),
JSAction.ManyHandsData.currentGripDidChangeExtended.serializer()
).associateBy { it.descriptor.name}
which doesn't have the simple name.
I was thinking maybe Delegates are the way to go (doing this for mapping js methods) but I'm struggling to think how to integrate that with data classes..
The goal would a mapping similar to above which allows me to retrieve a serializer by the string of an identifier (eg "DATA_INPUT")Edward Taylor
01/20/2020, 9:04 PMEdward Taylor
01/20/2020, 9:20 PMinternal val handDataActionSerializers = listOf(
JSAction.ManyHandsData.handError.serializer(),
JSAction.ManyHandsData.DATA_INPUT.serializer(),
JSAction.ManyHandsData.currentGripDidChangeExtended.serializer()
).associateBy { it.descriptor.name.split(".").last() }
Let me know if you come up with a better solution.
Would be great if I didn't have to list them out.