1 // This file was automatically generated from formats.md by Knit tool. Do not edit. 2 package example.exampleFormats03 3 4 import kotlinx.serialization.* 5 import kotlinx.serialization.cbor.* 6 <lambda>null7fun ByteArray.toAsciiHexString() = joinToString("") { 8 if (it in 32..127) it.toInt().toChar().toString() else 9 "{${it.toUByte().toString(16).padStart(2, '0').uppercase()}}" 10 } 11 12 @Serializable 13 data class Data( 14 @ByteString 15 val type2: ByteArray, // CBOR Major type 2 16 val type4: ByteArray // CBOR Major type 4 17 ) 18 mainnull19fun main() { 20 val data = Data(byteArrayOf(1, 2, 3, 4), byteArrayOf(5, 6, 7, 8)) 21 val bytes = Cbor.encodeToByteArray(data) 22 println(bytes.toAsciiHexString()) 23 val obj = Cbor.decodeFromByteArray<Data>(bytes) 24 println(obj) 25 } 26