package orsetto

  1. Overview
  2. Docs
Legend:
Library
Module
Module type
Parameter
Class
Class type

Concise Binary Object Representation (CBOR) flyweight implementation.

Overview

This module provides flyweight encoding and decoding of Concise Binary Object Representation (CBOR) structured data.

Use the flyweight implementation when values are not very large, streaming is not required, integer and floating point values do not exceed the limits of representation for OCaml primitive int and float types, lengths of octet arrays and Unicode texts do not exceed the limits of the OCaml string type, no special handling is required for standard CBOR tags, no Unicode normalization is required, and the order/uniqueness properties of key-value pairs in maps is not required to be canonical.

The encoder never emits indefinite-length sequence events. The decoder can scan them and reconstruct fixed-length sequences from them accordingly.

Types
type t = private
  1. | Null
  2. | Undefined of string
  3. | Boolean of bool
  4. | Integer of int
  5. | Float of float
  6. | Octets of string
  7. | Text of string
  8. | Array of t list
  9. | Map of (t * t) list
  10. | Tag of int * t

The private type of flyweight CBOR values.

val equal : t -> t -> bool

Equality

val compare : t -> t -> int

Comparison

Constructors

The functions below guard construction of flyweight values to respect the invariants of the CBOR encoding, e.g. tag values must be non-negative integers, text strings should comprise valid UTF-8 encodings, an "undefined" value can only be constructed by decoders, et cetera.

val null : t

The distinguished "null" value.

val boolean : bool -> t

Use boolean b to make a boolean value with b.

val integer : int -> t

Use integer i to make an integer value with i.

val float : float -> t

Use float n to make a floating-point value with n.

val octets : string -> t

Use octets s to make an octet sequence value with s.

val text : ?unsafe:unit -> string -> t

Use text s to make a Unicode text value with b. If s is not valid UTF-8 and ~unsafe:() is not used, then Cf_decode.Invalid is raised.

val array : t list -> t

Use array s to make an array value with s.

val map : (t * t) list -> t

Use map s to make a map value with s.

val tag : int -> t -> t

Use tag n v to tag the value v with tag number n.

Decoding and Encoding
val decoder : t Cf_decode.scheme

The decoder for flyweight CBOR values.

val encoder : t Cf_encode.scheme

The encoder for flyweight CBOR values.

OCaml

Innovation. Community. Security.