is there a multiplatform equivalent for an ObjectI...
# multiplatform
g
is there a multiplatform equivalent for an ObjectInputStream?
m
Look into
kotlinx.serialization
I guess? And serialize to Json instead of Java serialization?
g
Not sure I follow. I want to serialize and deserialize closures, which are serializable in kotlin by default. So I use a ObjectOutputStream to create a bytearray and the base64encode it. Can you show me how kotlinx.serialization would be of use in this scenario?
m
Ah, closures 🤔
Not sure you can serialize closures in MPP
If I'm not mistaken, it serializes the bytecode or so on the JVM so not sure you'll find an equivalent on native/JS
g
if it is, I haven't found the way yet 😄 I did manage to get it to work on JVM, but I need this for mobile.
m
Out of curiosity, what's the need to serialize closures?
g
I'm writing a kotlin DSL to build flutter apps
👀 1
so controllers (think MVC light), are made in the KMM module, UI is made with a DSL in a separate KMM module and any user interaction is written by using closures on those controllers
so I want to (de)serialize the closure and then execute them on the android/ios side, stick to platform method channel invocation on the UI side
m
I see... interesting problem 🙂
g
for sure! 🙂
My swift/objc isn't that great being a JVM dude so I haven't found a way to get this working. I have now changed the design to implement interactions in a KMM module which can be dependent on from flutter iOS/android modules, and then bind the actions to the correct method with an event based factory pattern. It's a bit less versatile then applying entire closures but it does provide a better abstraction between UI - state - backend.