All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.io.eqoty.secretk.utils.UByteArrayUtils.kt Maven / Gradle / Ivy

Go to download

A Kotlin multiplatform REST client utilizing secret network's gRPC gateway endpoints.

There is a newer version: 6.4.1-rc
Show newest version
package io.eqoty.secretk.utils

import okio.ByteString
import okio.ByteString.Companion.toByteString


fun UByteArray.toIntArray(): IntArray =
    map { it.toInt() }.toIntArray()

fun IntArray.toUByteArray(): UByteArray =
    map { it.toUByte() }.toUByteArray()


fun UByteArray.toByteString(): ByteString =
    toByteArray().toByteString()

fun UByteArray.decodeToString(): String =
    toByteArray().decodeToString()

fun ByteString.toUByteArray(): UByteArray =
    toByteArray().toUByteArray()

fun UByteArray.getPadded(length: Int): UByteArray {
    val paddingLength = length - this.size
    if (paddingLength < 0) {
        throw Error("Length too small to hold parameter r")
    }
    val padding = UByteArray(paddingLength) { 0u }
    return padding + this
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy