How To Receive Bytes From Server?

106 Views Asked by At

the sever is sending me an array of arrays of bytes [[Byte]] or List<List<Byte>>. A small sample looks like this [[102, 222, 111], [92, 22, 111], [142, 122, 32]] when writing this into a file, we get an executable, don't mean to compare with iOS but there I simnply do something like let data = Data(bytes) and then data.write(to: "path/file.jpg"). I can't get far as right when my application receives the JSON with the bytes and tried to deserialize it into:

import kotlinx.serialization.Serializable

@Serializable
data class ServerResponse(
    val fileRaw: List<List<Byte>>?
)

The application with the following error --> Unexpected JSON token at offset 1829: Failed to parse 'byte'

I know I will still have some troubleshooting after solving this, like actually writing this into an executable, but that is outside of the scope of this question.

How can I receive and serially an array of arrays of bytes (VISUALLY [[Byte]] or List<List<Byte>>)?

0

There are 0 best solutions below