package orsetto

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

Concise Binary Object Representation (CBOR) events.

Overview

As defined in RFC 7049, a CBOR object is an octet sequence encoding a series of core events that correspond to a simple grammar describing the composition of structured data.

This module provides a safe interface for constructing valid CBOR events used by the encoder in

bor_encode

and the decoder in

bor_decode

.

Types
type signal = [
  1. | `Break
  2. | `Octets
  3. | `Text
  4. | `Array
  5. | `Map
]

The type of indefinite-length sequencing signals.

type sign = [
  1. | `Positive
  2. | `Negative
]

The type of integer sign.

type ieee754_precision = [
  1. | `Half
  2. | `Single
  3. | `Double
]

The type of IEEE-754 floating point number precision.

type minor = private
  1. | Minor of int64

The private type of CBOR minor codepoints. This is conceptually an unsigned 64-bit integer, encapsulated here in a private data constructor because the OCaml int64 type is a signed integer.

type t = private
  1. | Null
  2. | Signal of signal
  3. | Boolean of bool
  4. | Integer of sign * minor
  5. | Float of ieee754_precision * float
  6. | Octets of string
  7. | Text of string
  8. | Array of minor
  9. | Map of minor
  10. | Tag of minor
  11. | Reserved of int
  12. | Undefined of string

The private type of CBOR events.

Constructors
val int_to_minor : int -> minor

Use int_to_minor n to make a CBOR minor codepoint of value n. Raises Invalid_argument if n is negative.

val int64_to_minor : ?unsigned:unit -> int64 -> minor

Use int64_to_minor n to make a CBOR minor codepoint of value n. Raises Invalid_argument if n is negative unless the ~unsigned:() optional flag is provided to explicitly signal that n is to be regarded as unsigned.

val minor_to_intopt : minor -> int option

Use minor_to_intopt minor to extract the positive integer corresponding to minor. Returns None if the codepoint cannot be represented by the positive range of values of the OCaml integer type.

val null : t

The distinguished "null" value.

val signal : [< signal ] -> t

Use signal s to make an event signaling s.

val boolean : bool -> t

Use boolean b to select either the distinguished "true" or "false" event according to b.

val integer : [< sign ] -> minor -> t

Use integer sign minor to make a positive or negative integer event, according to sign, with the value minor.

val float : ?precision:[< ieee754_precision ] -> float -> t

Use float n to make an IEEE 754 floating point number event with n. If ~precision is not used, then the most precise form required to represent n without loss is selected.

val octets : string -> t

Use octets s to make a definite length octet sequence event comprising the octets in s. To make an indefinite length octet sequence event, use the signal `Octets constructor.

val text : string -> t

Use text s to make a definite length Unicode text sequence event comprising the UTF-8 encoded octets in s. If the octets in s do not comprise a valid UTF-8 encoding, then Cf_decode.Invalid is raised with the position of the invalid octet in s. To make an indefinite length Unicode text event, use the signal `Text constructor.

val array : minor -> t

Use array minor to make an event signaling the start of a definite length array with the length indicated by minor. To make an indefinite length array event, use the signal `Array constructor.

val map : minor -> t

Use map minor to make an event signaling the start of a definite length map with the length indicated by minor. To make an indefinite length map event, use the signal `Map constructor.

val tag : minor -> t

Use tag minor to make a tagged value event.

Utilities

Equivalence relation

include Cf_relations.Equal with type t := t
val equal : t -> t -> bool

Use equal a b to compare a and b, returning true if the two values are equivalent, otherwise false.

val force_precision : [< ieee754_precision ] -> float -> float

Use force_precision p n to truncate n for the precision p.