ByteStringWrapper
Use this class if you'll need to serialize a complex type as a byte string before encoding it, i.e. as it is the case with the protected header in COSE structures.
An example for a COSE header data class would be:
@Serializable
data class CoseHeader(
@CborLabel(1)
@SerialName("alg")
val alg: Int? = null
)
@Serializable
data class CoseSigned(
@ByteString
@CborLabel(1)
@SerialName("protectedHeader")
val protectedHeader: ByteStringWrapper<CoseHeader>,
)
Content copied to clipboard
Serializing this CoseHeader
object would result in a10143a10126
, in diagnostic notation:
A1 # map(1)
01 # unsigned(1)
43 # bytes(3)
A10126 # "\xA1\u0001&"
Content copied to clipboard
so the protectedHeader
got serialized first and then encoded as a @ByteString
.
Note that equals()
and hashCode()
only use value
, not serialized
.