Hex serialization

This extension set our standard for all of combined functionality under single context

val randomUuidString = UUID.randomUUID().toString() // "376e2d32-59b7-410b-8c41-1da220f3ccca"
val byteArrayValue = randomUuidString.toByteArray() // [51, 55, 54, 101, 50, 100, 51, 50, 45, 53, 57, 98, 55, 45, 52, 49, 48, 98, 45, 56, 99, 52, 49, 45, 49, 100, 97, 50, 50, 48, 102, 51, 99, 99, 99, 97]
// includePrefix = false by default
val hexValue = byteArrayValue.hex.encode(includePrefix = true) // "0x33373665326433322d353962372d343130622d386334312d316461323230663363636361"
val byteArrayFromHex = hexValue.hex.decode() // [51, 55, 54, 101, 50, 100, 51, 50, 45, 53, 57, 98, 55, 45, 52, 49, 48, 98, 45, 56, 99, 52, 49, 45, 49, 100, 97, 50, 50, 48, 102, 51, 99, 99, 99, 97]
val stringFromData = String(byteArray, Charsets.UTF_8) // "376e2d32-59b7-410b-8c41-1da220f3ccca"

Last updated