• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // This file was automatically generated from formats.md by Knit tool. Do not edit.
2 package example.exampleFormats06
3 
4 import kotlinx.serialization.*
5 import kotlinx.serialization.protobuf.*
6 
<lambda>null7 fun 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 @OptIn(ExperimentalSerializationApi::class)
13 @Serializable
14 class Data(
15     @ProtoType(ProtoIntegerType.DEFAULT)
16     val a: Int,
17     @ProtoType(ProtoIntegerType.SIGNED)
18     val b: Int,
19     @ProtoType(ProtoIntegerType.FIXED)
20     val c: Int
21 )
22 
23 @OptIn(ExperimentalSerializationApi::class)
mainnull24 fun main() {
25     val data = Data(1, -2, 3)
26     println(ProtoBuf.encodeToByteArray(data).toAsciiHexString())
27 }
28