https://github.com/kropp/kotlinx.serialization.msgpack
Kotlin Serialization extension for MessagePack - msgpack.org[Kotlin Serialization]
https://github.com/kropp/kotlinx.serialization.msgpack
kotlin kotlin-serialization messagepack msgpack
Last synced: 12 months ago
JSON representation
Kotlin Serialization extension for MessagePack - msgpack.org[Kotlin Serialization]
- Host: GitHub
- URL: https://github.com/kropp/kotlinx.serialization.msgpack
- Owner: kropp
- License: apache-2.0
- Created: 2019-01-07T20:48:08.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-10-02T10:12:11.000Z (over 5 years ago)
- Last Synced: 2025-05-08T20:57:53.905Z (12 months ago)
- Topics: kotlin, kotlin-serialization, messagepack, msgpack
- Language: Kotlin
- Homepage:
- Size: 169 KB
- Stars: 7
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Kotlin Serialization MessagePack library
This library extends [kotlinx.serialization](https://github.com/Kotlin/kotlinx.serialization/) framework to support
[MessagePack](https://msgpack.org/) format.
## Implementation details
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.
## Current Limitations
* Only JVM is supported as of now
* Unsigned integers can't be encoded because kotlinx.serialization framework [doesn't support `inline` classes](https://github.com/Kotlin/kotlinx.serialization/issues/259) (yet)
* MessagePack extensions are not supported
## Verification
The implementation is tested against https://github.com/kawanet/msgpack-test-suite/
## Usage
```kotlin
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)
```