Is this possible to de serialize the data with kot...
# multiplatform
m
Is this possible to de serialize the data with kotlinx.serialization which is serialized using java
r
Serialized using Java to what?
You probably should ask this in #serialization
m
octet-stream
r
A stream of bytes sure, but using what format? Do you mean via
ObjectOutputStream
?
m
Yes
r
If you can't change the serialization format to something else (like Protobuf or JSON), then you'll probably need to write a custom decoder. See https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/formats.md#basic-decoder.
m
I am converting the libphonenumber java library to kotlin to use it in kotlin Multiplatform
r
What platforms do you need to support?
m
Ios, android and desktop
r
If you are writing a pure-Kotlin port, why do you need to deserialize Java classes?
m
I have files that contains information like phone number patterns, and validations, example numbers e.t.c
But they are serialized by Google using java output stream
r
Another option is to use the Java libphonenumber on Android/desktop, and an existing port for iOS e.g. https://github.com/marmelroy/PhoneNumberKit. You can make all this transparent to your common code via some expect/actuals.
m
But this is already exists on github but that one uses moko resources but I want to use compose resources
😕 1
r
> But they are serialized by Google using java output stream From what I can tell, it looks like they do this for the Java version via some tooling e.g. https://github.com/google/libphonenumber/blob/259c5917d05a7c9613ecf7c9e4a3af959bdb27e3/tools/java/java-build/src/com/google/i18n/phonenumbers/buildtools/GeneratePhonePrefixData.java , but if you are writing a pure-Kotlin port, just use the source data instead and load them into similar Kotlin classes. It looks like they also expose some protobufs, see https://github.com/google/libphonenumber/blob/259c5917d05a7c9613ecf7c9e4a3af959bdb27e3/resources/phonemetadata.proto and https://github.com/google/libphonenumber/blob/259c5917d05a7c9613ecf7c9e4a3af959bdb27e3/resources/phonenumber.proto.
l
@Muhammad Rehan I already started a mostly working direct port of the android one if you want to help getting it to pass all tests on all targets https://github.com/luca992/libphonenumber-kotlin I figured out how to deserialize the java data resources as well.
here’s my port of ObjectInputStream for common koltin using okio
e
Hi @Luca , I'm trying to use your libphonenumber-kotlin library but I don't want to use moko resources. Is there any way to do it?
l
@Emirhan Emmez well for the library I need to use some sort of multiplatform resources library and the only real options are moko-resources and compose resources. I would use compose resources, but that includes a dependency on compose and I wanted to avoid that. My goal is to use moko-resources to pack them correctly inside the library and whatever project adds libphonenumber-kotlin can use whatever resources library they want
If things are working as I want them to you shouldn’t have to add moko-resources to your own project
(I’m not saying they are working as I want them to yet 🤔)