Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cbor support #1

Open
akelix opened this issue Mar 30, 2023 · 2 comments
Open

Cbor support #1

akelix opened this issue Mar 30, 2023 · 2 comments

Comments

@akelix
Copy link

akelix commented Mar 30, 2023

Cbor support could be added.

fun ByteArray.toSenmlRecords(): List{
return try {
Cbor {
ignoreUnknownKeys = true
}.decodeFromByteArray(this)
} catch (e: kotlinx.serialization.SerializationException) {
Napier.e { e.message ?: "Unknown exception while deserializing SenML pack" }
emptyList()
}
}

@bobeal
Copy link
Owner

bobeal commented Apr 2, 2023

Indeed, it seems that kotlinx.serialization has support for Cbor in its newer versions (https://kotlinlang.org/api/kotlinx.serialization/kotlinx-serialization-cbor/kotlinx.serialization.cbor/).

Will look out how to integrate this into the lib.

@akelix
Copy link
Author

akelix commented Apr 3, 2023

Turns out it's not that easy.
There are a few problems:

  • CBOR serialization from Jetbrains does not support non-string keys ISSUE
  • No support of Number deserialization (for example baseTime and Time could be Long and Double)
  • If you use Double and Long in Serializable object it wil not be optimized according to actual value (For example if you use value:Long = 1 it will be serialized as Long not as Byte)

https://github.com/Kotlin/kotlinx.serialization/blob/master/docs/formats.md#cbor-experimental

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants