Concise Binary Object Representation
1 Usage
cbor-write
cbor-read
2 Configuration Options
3 Auxiliary Items
cbor-valid-tag-number?
cbor-unassigned-simple-value?
cbor-tag
cbor-simple-value
4 Notes
8.1

Concise Binary Object Representation

 (require cbor) package: cbor

This library implements serialization and deserialization routines for Concise Binary Object Representation (CBOR), as defined in RFC 8949. The library takes in raw data in the form of Racket data structures, outputting a serialized binary stream, and vice versa.

1 Usage

procedure

(cbor-write config v [out])  void?

  config : cbor-config?
  v : any/c
  out : output-port? = (current-output-port)
Writes the value v to out. The following v are accepted:

procedure

(cbor-read config [in])  any/c

  config : cbor-config?
  in : input-port? = (current-input-port)
Reads a binary-serialized CBOR value from in. Major types are decoded as follows:
  • Major type 0 (unsigned integer) and 1 (negative integer) are decoded as standard Racket integers

  • Major type 2 (byte string) and 3 (string) are decoded as Racket bytes? and string?, respectively

  • Major type 4 (list) is decoded as a Racket list? of the contained values

  • Major type 5 (map) is decoded as a Racket hash-equal? of the contained key-value pairs

  • Major type 6 (tag) is decoded as a cbor-tag. TODO detail custom deserializers

  • Major type 7, additional data 20, 21, and 23 (false, true, and undefined) are decoded as #f, #t, and undefined, respectively

  • Major type 7, additional data 22 is decoded as the value of (cbor-config-null-value config)

  • Major type 7, additional data 25, 26, and 27 (half float, single float, and double float, respectively), are all decoded as Racket flonum?. Note that this library decodes all of these three types to Racket’s double-width floating point type.

  • Any other item with major type 7 and additional data matching cbor-unassigned-simple-value? is decoded as a cbor-simple-value

2 Configuration Options

3 Auxiliary Items

procedure

(cbor-valid-tag-number? v)  boolean?

  v : any/c
Equivalent to (integer-in 0 18446744073709551616).

procedure

(cbor-unassigned-simple-value? v)  boolean?

  v : any/c
Equivalent to (or/c (integer-in 0 19) (integer-in 32 255)).

struct

(struct cbor-tag (number content)
    #:extra-constructor-name make-cbor-tag)
  number : cbor-valid-tag-number?
  content : any/c
Raw representation of a CBOR tag with tag number number and tag content content. content must be serializable by cbor-write.

struct

(struct cbor-simple-value (inner)
    #:extra-constructor-name make-cbor-simple-value)
  inner : cbor-unassigned-simple-value?
Represents a CBOR Simple Value. Only simple values that have not been assigned a meaning via RFC can be represented as this struct. Simple Values with predefined meaning such as #f are always serialized and deserialized directly as their meaningful forms.

4 Notes