ByteStringWrapper

class ByteStringWrapper<T>(val value: T, val serialized: ByteArray = byteArrayOf())(source)

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>,
)

Serializing this CoseHeader object would result in a10143a10126, in diagnostic notation:

A1           # map(1)
01 # unsigned(1)
43 # bytes(3)
A10126 # "\xA1\u0001&"

so the protectedHeader got serialized first and then encoded as a @ByteString.

Note that equals() and hashCode() only use value, not serialized.

Constructors

Link copied to clipboard
constructor(value: T, serialized: ByteArray = byteArrayOf())

Properties

Link copied to clipboard
Link copied to clipboard
val value: T

Functions

Link copied to clipboard
open operator override fun equals(other: Any?): Boolean
Link copied to clipboard
open override fun hashCode(): Int
Link copied to clipboard
open override fun toString(): String