This library extends kotlinx.serialization framework to support MessagePack format.
When multiple equivalent encodings exist, the shortest (in terms of number of bytes) is used. Decoders decode any format and convert it to a required type (possibly loosing precision or significant higher digits)
Thus, not for any input decoding and encoding back will produce the exact same byte array. However, for any @Serializable class
encoding and decoding should result in the equivalent instance.
- Only JVM is supported as of now
- Unsigned integers can't be encoded because kotlinx.serialization framework doesn't support
inlineclasses (yet) - MessagePack extensions are not supported
The implementation is tested against https://github.com/kawanet/msgpack-test-suite/
import com.github.kropp.messagepack.MessagePack
@Serializable
data class Demo(val compact: Boolean, val schema: Int)
val bytes = byteArrayOf(0x82.toByte(), 0xA7.toByte(), 0x63, 0x6F, 0x6D, 0x70, 0x61, 0x63, 0x74, 0xC3.toByte(), 0xA6.toByte(), 0x73, 0x63, 0x68, 0x65, 0x6D, 0x61, 0x00)
val demo = MessagePack.decode(Demo.serializer(), bytes)
assertEquals(demo.compact, true)
assertEquals(demo.schema, 0)