package cborl

  1. Overview
  2. Docs

Serialization is done by converting CBOR data items to a sequence of signals. Signals can be directly translated to and from bytes. This module provides direct access to signals. This can be used to stream large CBOR data items and also provides the ability to work with indefinite-length CBOR data items.

type t =
  1. | Null
  2. | Undefined
  3. | Bool of bool
  4. | Integer of Z.t
    (*

    The integer value must fit into 8 bytes.

    *)
  5. | ByteString of int
    (*

    In a well-formed sequence of signals, a ByteString n element is always followed by exactly n Byte b elements.

    *)
  6. | TextString of int
    (*

    In a well-formed sequence of signals, a TextString n element is always followed by exactly n Byte b elements.

    *)
  7. | Byte of char
  8. | Array of int option
    (*

    In a well-formed sequence of signals, an Array n_opt element is followed by exaclty n well-formed sequence of CBOR items when n_opt = Some n or by an indefinite number of items followed by a Break element.

    *)
  9. | Break
  10. | Map of int option
    (*

    In a well-formed sequence of signals, an Map n_opt element is followed by exaclty n well-formed sequence of CBOR items when n_opt = Some n or by an indefinite number of items followed by a Break element.

    *)
  11. | Tag of Z.t
    (*

    In a well-formed sequence of signals, a Tag t element is followed by a single sequence of an encoded CBOR item.

    *)
  12. | Simple of int
  13. | Float of float
  14. | Double of float

Type of CBOR Signal

val pp : t Fmt.t
exception NotWellFormed of string

Exception that is thrown when sequence of signals or encoding is not well formed.

Conversion from and to CBOR Data Items

val of_item : item -> t Seq.t

of_item item returns a sequence of signals that represents the CBOR data item item.

Note that Cborl.Integer n values are encoded as Bignums if n is larger than what can be encoded in 8 bytes.

val to_items : t Seq.t -> item Seq.t

to_items signals reads multiple CBOR data items from the sequence signals.

val to_item : t Seq.t -> item * t Seq.t

to_item signals reads one item from the sequence signals and returns the sequence containing the continuation of signals after the read item.

Indefinite-Length Data Items

val indefinite_length_array : item Seq.t -> t Seq.t

indefinite_length_array items returns a sequence of signals encoding items as an indefinite-length array.

val indefinite_length_map : (item * item) Seq.t -> t Seq.t

indefinite_length_array key_values returns a sequence of signals encoding key_values as an indefinite-length map.

Writing

val write : t Seq.t -> char Seq.t

write stream

Reading

val read : char Seq.t -> t Seq.t

read input

OCaml

Innovation. Community. Security.