You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What is your use-case and why do you need this feature?
According to the documentation, CBOR's @ByteString annotation can be used in data classes to encode or decode a ByteArray as a byte string (major type 2). This is fine if you're dealing with CBOR data that can be represented as a data class, but there cases where a data class is not suitable (one of which is covered in #2037).
My use-case is to decode a single raw byte string, without any kind of wrapper. Other primitive types can be serialized directly (e.g. Cbor.decodeFromByteArray<Int>(data)) or using a value class:
@JvmInline
@Serializable
value class Value(val data: Int)
which can then be decoded with Cbor.decodeFromByteArray<Value>(data).
This is not possible with byte strings.
Describe the solution you'd like
I would like to be able to define a value class as such:
@JvmInline
@Serializable
value class Value(@ByteString val data: ByteArray)
Currently, if I try using this to decode the byte string 4401020304, I get the following error: kotlinx.serialization.cbor.internal.CborDecodingException: Expected start of array, but found 44.
The text was updated successfully, but these errors were encountered:
What is your use-case and why do you need this feature?
According to the documentation, CBOR's
@ByteString
annotation can be used in data classes to encode or decode aByteArray
as a byte string (major type 2). This is fine if you're dealing with CBOR data that can be represented as a data class, but there cases where a data class is not suitable (one of which is covered in #2037).My use-case is to decode a single raw byte string, without any kind of wrapper. Other primitive types can be serialized directly (e.g.
Cbor.decodeFromByteArray<Int>(data)
) or using a value class:which can then be decoded with
Cbor.decodeFromByteArray<Value>(data)
.This is not possible with byte strings.
Describe the solution you'd like
I would like to be able to define a value class as such:
Currently, if I try using this to decode the byte string
4401020304
, I get the following error:kotlinx.serialization.cbor.internal.CborDecodingException: Expected start of array, but found 44
.The text was updated successfully, but these errors were encountered: