clj-cbor.header

Functions for reading and writing CBOR headers.

decode

(decode header)

Determines the major type keyword and additional information encoded by the header byte. §2.1

major-types

Vector of major type keywords, indexed by the three-bit values 0-7. (§2.1)

read-byte

(read-byte in)

Read an unsigned byte (8-bit) value from the data input stream. Promotes the value to a long for consistency.

read-code

(read-code in info)

Reads a size value from the initial bytes of the input stream. Returns either a number, the keyword :indefinite, or calls the error handler on reserved info codes.

read-int

(read-int in)

Read an unsigned int (32-bit) value from the data input stream. Promotes the value to a long for consistency.

read-long

(read-long in)

Read an unsigned long (64-bit) value from the data input stream. Handles overflowing values by promoting them to a bigint.

https://tools.ietf.org/html/rfc7049#section-1.2

read-short

(read-short in)

Read an unsigned short (16-bit) value from the data input stream. Promotes the value to a long for consistency.

write

(write out mtype i)

Writes a header byte for the given major-type, plus extra bytes to encode the given integer code. Always writes the smallest possible representation. Returns the number of bytes written.

write-byte

(write-byte out i)

Write an unsigned byte (8-bit) value to the data output stream.

write-int

(write-int out i)

Write an unsigned int (32-bit) value to the data output stream. Coerces the value into a signed representation before writing if necessary.

write-leader

(write-leader out mtype info)

Writes a header byte for the given major-type and additional info numbers.

write-long

(write-long out i)

Write a long (32-bit) value to the data output stream. Coerces the value into a signed representation before writing if necessary.

write-short

(write-short out i)

Write an unsigned short (16-bit) value to the data output stream.