CborReader

class CborReader(data: ByteArray, start: Int = 0, end: Int = data.size, maxDepth: Int = 32)(source)

Reads CBOR data items one at a time from data, for protocol code that parses a fixed structure or a CBOR sequence (RFC 8742), as EDHOC messages are:

val reader = CborReader(message1)
val method = reader.readInt()
val suites = reader.readValue()

Accepted: definite-length items of every major type except floating point. Rejected with CborException: indefinite lengths, floats, reserved encodings, integers outside the Long range, invalid UTF-8, truncated input, and nesting deeper than maxDepth.

Encodings that are valid but not the shortest are accepted, so peers with less strict encoders still interoperate. Use readEncodedItem when the exact received bytes matter, as they do for EDHOC transcript hashes.

Constructors

Link copied to clipboard
constructor(data: ByteArray, start: Int = 0, end: Int = data.size, maxDepth: Int = 32)

Properties

Link copied to clipboard
Link copied to clipboard

Offset of the next unread byte in data.

Link copied to clipboard

Functions

Link copied to clipboard

Whether the next item is null, without consuming it.

Link copied to clipboard

The major type of the next item, without consuming it.

Link copied to clipboard

Reads an array header and returns the number of items that follow.

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

The exact bytes of the next complete data item, as received.

Link copied to clipboard
fun readInt(): Long
Link copied to clipboard

Reads a map header and returns the number of key/value pairs that follow.

Link copied to clipboard
fun readNull()
Link copied to clipboard
fun readTag(): Long
Link copied to clipboard
Link copied to clipboard

Reads the next complete data item.

Link copied to clipboard
fun skip()