Lilly
07/21/2020, 3:59 PMval responsePacketsChannel = ConflatedBroadcastChannel<ResponsePacket>()
ResponsePacket is a interface because I have multiple packets which I want to offer, e.g. ParameterPacket: ResponsePacket
or TimePacket: ResponsePacket
. Now I'm wondering what would be the proper way to differentiate between the specific packets when I start to observe them. My first thought was using Pair<ResponsePacketType, ResponsePacket>
combined with an enum ResponsePacketType
->
val responsePacketsChannel = ConflatedBroadcastChannel<Pair<ResponsePacketType, ResponsePacket>>()
Is there maybe a better solution?João Gonçalves
07/21/2020, 4:02 PMLilly
07/21/2020, 4:08 PMZach Klippenstein (he/him) [MOD]
07/21/2020, 4:43 PMwhen
on the actual packet type, which is much better than adding the abstraction of creating an enum to represent that. Enum doesn't add any type safety, and just creates more opportunities for bugs (eg incorrect mappings, more code to update for every change, etc).Lilly
07/23/2020, 9:43 AMZach Klippenstein (he/him) [MOD]
07/23/2020, 3:40 PM