```private suspend inline fun <reified T> en...
# android
z
Copy code
private suspend inline fun <reified T> encodeParams(value: T): String {
    return withContext(<http://Dispatchers.IO|Dispatchers.IO>) {
        URLEncoder.encode(
            /* s = */ ProtoBuf.encodeToByteArray(value).encodeBase64(),
            /* enc = */ Charsets.UTF_8.name
        )
    }
}
Could I improve this code any further? I wasn't sure if there was something simpler i could use
c
I would use
Dispatchers.Default
to not unnecessarily block the IO dispatcher for non IO operations.
Also not sure why You need the url encoder if you encode a base 64 string. 🤔
z
My min api level is 21, so I would have to add extra logic to use that
c
I’d then create a api level switch to not create unnecessary strings on newer phones.
or as you are on Android there is also
android.util.Base64
a
Not sure about simplicity but if the encoding object is too large, then that might be a performance issue, as that would load the entire object into memory once, maybe stream the protocol buffers encoding to avoid loading the entire object.