Tobi
04/10/2019, 7:30 AMByteArray
representation of a String
, but just realised that String.toByteArray()
(https://kotlinlang.org/api/latest/jvm/stdlib/kotlin.text/to-byte-array.html) is just available on the jvm 😞
Any suggestion how I can do this in the common part?addamsson
04/10/2019, 7:40 AMexpect fun String.toByteArray(): ByteArray
Tobi
04/10/2019, 7:41 AMaddamsson
04/10/2019, 7:42 AMtoByteArray
on the JVMTODO()
for native 😄Tobi
04/10/2019, 7:44 AMaddamsson
04/10/2019, 7:45 AM/**
* Encodes the contents of this string using the specified character set and returns the resulting byte array.
* @sample samples.text.Strings.stringToByteArray
*/
@kotlin.internal.InlineOnly
public inline fun String.toByteArray(charset: Charset = Charsets.UTF_8): ByteArray = (this as java.lang.String).getBytes(charset)
public byte[] getBytes(Charset charset) {
if (charset == null) throw new NullPointerException();
return StringCoding.encode(charset, value, 0, value.length);
}
Tobi
04/10/2019, 7:46 AMaddamsson
04/10/2019, 7:47 AMTobi
04/10/2019, 7:47 AMaddamsson
04/10/2019, 7:57 AMTobi
04/10/2019, 8:00 AM