package data-encoding

  1. Overview
  2. Docs

Module Data_encoding.RegistrationSource

Sourcetype id = string
Sourcetype t

A encoding that has been registered. It can be retrieved using either list or find.

Note registration/retrieval erases the type information that is built by the combinator. In other words, t is a non-parametric type. As a result, you cannot recover an OCaml value of the type of the registered encoding. You can only perform operations where the type doesn't escape — e.g., converting between binary and json.

Sourceval binary_schema : t -> Binary_schema.t

Descriptions and schemas of registered encodings.

Sourceval json_schema : t -> Json.schema
Sourceval description : t -> string option
Sourceval json_pretty_printer : t -> Format.formatter -> Json.t -> unit

Printers for the encodings.

Sourceval binary_pretty_printer : t -> Format.formatter -> Bytes.t -> unit
Sourceval register : ?pp:(Format.formatter -> 'a -> unit) -> 'a Encoding.t -> unit

register (def id encoding) registers the encoding with the id. It can later be found using find and providing the matching id. It will also appear in the results of list.

  • raises [Invalid_argument]

    if encoding is not of one of the following form:

Sourceval slice : t -> string -> (Binary.Slicer.slice list, Binary.read_error) result

slice r b attempts to slice a binary representation b of some data assuming it is correctly described by the registered encoding r. If r does not correctly describe b, then it returns None.

See Binary.slice_string for details about slicing.

Sourceval slice_all : string -> (string * Binary.Slicer.slice list) list

slice_all b attempts to slice a binary representation b of some data for all of the registered encodings. It returns a list of the slicing for each of the registered encodings that correctly describe b.

See Binary.slice_string for details about slicing.

Sourceval find : id -> t option

find id is Some r if register (def id e) has been called, in which case r matches e. Otherwise, it is None.

Sourceval list : unit -> (id * t) list

list () is a list of pairs (id, r) where r is a registered encoding for the id.

Sourceval bytes_of_json : t -> Json.t -> Bytes.t option

Conversion functions from JSON to bytes.

Sourceval json_of_bytes : t -> Bytes.t -> Json.t option

Conversion functions from bytes to JSON.