package biniou

  1. Overview
  2. Docs

Module Bi_ioSource

Input and output functions for the Biniou serialization format

Node tags

Sourcetype node_tag = int
Sourceval bool_tag : node_tag

Tag indicating a bool node.

Sourceval int8_tag : node_tag

Tag indicating a bool node.

Tag indicating an int8 node.

Sourceval int16_tag : node_tag

Tag indicating an int8 node.

Tag indicating an int16 node.

Sourceval int32_tag : node_tag

Tag indicating an int16 node.

Tag indicating an int32 node.

Sourceval int64_tag : node_tag

Tag indicating an int32 node.

Tag indicating an int64 node.

Sourceval float32_tag : node_tag

Tag indicating an int64 node.

Tag indicating a float32 node.

Sourceval float64_tag : node_tag

Tag indicating a float32 node.

Tag indicating a float64 node.

Sourceval uvint_tag : node_tag

Tag indicating a float64 node.

Tag indicating a uvint node.

Sourceval svint_tag : node_tag

Tag indicating a uvint node.

Tag indicating an svint node.

Sourceval string_tag : node_tag

Tag indicating an svint node.

Tag indicating a string node.

Sourceval array_tag : node_tag

Tag indicating a string node.

Tag indicating an array node.

Sourceval tuple_tag : node_tag

Tag indicating an array node.

Tag indicating a tuple node.

Sourceval record_tag : node_tag

Tag indicating a tuple node.

Tag indicating a record node.

Sourceval num_variant_tag : node_tag

Tag indicating a record node.

Tag indicating a num_variant node.

Sourceval variant_tag : node_tag

Tag indicating a num_variant node.

Tag indicating a variant node.

Sourceval unit_tag : node_tag

Tag indicating a variant node.

Tag indicating a unit node.

Sourceval table_tag : node_tag

Tag indicating a unit node.

Tag indicating a table node.

Sourceval shared_tag : node_tag

Tag indicating a table node.

Tag indicating a shared node.

Sourceval write_tag : Bi_outbuf.t -> node_tag -> unit

Write one-byte tag to a buffer.

Sourceval read_tag : Bi_inbuf.t -> node_tag

Read one-byte tag from a buffer.

Tags of variants and record fields

Sourcetype hash = int

31-bit hash

Sourceval hash_name : string -> hash

Hash function used to compute field name tags and variant tags from their full name.

Sourceval write_hashtag : Bi_outbuf.t -> hash -> bool -> unit

write_hashtag ob h has_arg writes variant tag h to buffer ob. has_arg indicates whether the variant has an argument. This function can be used for record field names as well, in which case has_arg may only be true.

Sourceval string_of_hashtag : hash -> bool -> string

Same as write_hashtag but writes to a string.

Sourceval read_hashtag : Bi_inbuf.t -> (Bi_inbuf.t -> hash -> bool -> 'a) -> 'a

read_hashtag ib f reads a variant tag as hash h and flag has_arg and returns f h has_arg.

Sourceval read_field_hashtag : Bi_inbuf.t -> hash

read_field_hashtag ib reads a field tag and returns the 31-bit hash.

Sourceval make_unhash : string list -> hash -> string option

Compute the hash of each string of the input list and return a function that converts a hash back to the original string. Lookups do not allocate memory blocks.

  • raises Failure

    if the input list contains two different strings with the same hash.

Sourcetype int7 = int

7-bit int used to represent a num_variant tag.

Sourceval write_numtag : Bi_outbuf.t -> int7 -> bool -> unit

write_numtag ob i has_arg writes the tag of a num_variant. The tag name is represented by i which must be within [0, 127] and the flag has_arg which indicates the presence of an argument.

Sourceval read_numtag : Bi_inbuf.t -> (Bi_inbuf.t -> int7 -> bool -> 'a) -> 'a

read_numtag ib f reads a num_variant tag and processes the tag name i and flag has_arg using f.

Atom writers

The write_untagged_ functions write an untagged value (VAL) to an output buffer while the other write_ functions write a tagged value (TAGVAL).

Sourceval write_untagged_unit : Bi_outbuf.t -> unit -> unit
Sourceval write_untagged_bool : Bi_outbuf.t -> bool -> unit
Sourceval write_untagged_char : Bi_outbuf.t -> char -> unit
Sourceval write_untagged_int8 : Bi_outbuf.t -> int -> unit
Sourceval write_untagged_int16 : Bi_outbuf.t -> int -> unit
Sourceval write_untagged_int32 : Bi_outbuf.t -> int32 -> unit
Sourceval write_untagged_int64 : Bi_outbuf.t -> int64 -> unit
Sourceval write_untagged_float32 : Bi_outbuf.t -> float -> unit
Sourceval write_untagged_float64 : Bi_outbuf.t -> float -> unit
Sourceval write_untagged_string : Bi_outbuf.t -> string -> unit
Sourceval write_untagged_uvint : Bi_outbuf.t -> int -> unit
Sourceval write_untagged_svint : Bi_outbuf.t -> int -> unit
Sourceval write_unit : Bi_outbuf.t -> unit -> unit
Sourceval write_bool : Bi_outbuf.t -> bool -> unit
Sourceval write_char : Bi_outbuf.t -> char -> unit
Sourceval write_int8 : Bi_outbuf.t -> int -> unit
Sourceval write_int16 : Bi_outbuf.t -> int -> unit
Sourceval write_int32 : Bi_outbuf.t -> int32 -> unit
Sourceval write_int64 : Bi_outbuf.t -> int64 -> unit
Sourceval write_float32 : Bi_outbuf.t -> float -> unit
Sourceval write_float64 : Bi_outbuf.t -> float -> unit
Sourceval write_string : Bi_outbuf.t -> string -> unit
Sourceval write_uvint : Bi_outbuf.t -> int -> unit
Sourceval write_svint : Bi_outbuf.t -> int -> unit

Atom readers

The read_untagged_ functions read an untagged value (VAL) from an input buffer.

Sourceval read_untagged_unit : Bi_inbuf.t -> unit
Sourceval read_untagged_bool : Bi_inbuf.t -> bool
Sourceval read_untagged_char : Bi_inbuf.t -> char
Sourceval read_untagged_int8 : Bi_inbuf.t -> int
Sourceval read_untagged_int16 : Bi_inbuf.t -> int
Sourceval read_untagged_int32 : Bi_inbuf.t -> int32
Sourceval read_untagged_int64 : Bi_inbuf.t -> int64
Sourceval read_untagged_float32 : Bi_inbuf.t -> float
Sourceval read_untagged_float64 : Bi_inbuf.t -> float
Sourceval read_untagged_string : Bi_inbuf.t -> string
Sourceval read_untagged_uvint : Bi_inbuf.t -> int
Sourceval read_untagged_svint : Bi_inbuf.t -> int
Sourceval skip : Bi_inbuf.t -> unit

Read and discard a value. Useful for skipping unknown record fields.

Generic tree

Sourcetype tree = [
  1. | `Unit
  2. | `Bool of bool
  3. | `Int8 of char
  4. | `Int16 of int
  5. | `Int32 of Int32.t
  6. | `Int64 of Int64.t
  7. | `Float32 of float
  8. | `Float64 of float
  9. | `Uvint of int
  10. | `Svint of int
  11. | `String of string
  12. | `Array of (node_tag * tree array) option
  13. | `Tuple of tree array
  14. | `Record of (string option * hash * tree) array
  15. | `Num_variant of int * tree option
  16. | `Variant of string option * hash * tree option
  17. | `Table of ((string option * hash * node_tag) array * tree array array) option
  18. | `Shared of tree
]

Tree representing serialized data, useful for testing and for untyped transformations.

Sourceval write_tree : Bi_outbuf.t -> tree -> unit

Serialization of a tree to a buffer.

Sourceval string_of_tree : tree -> string

Serialization of a tree into a string.

Sourceval read_tree : ?unhash:(hash -> string option) -> Bi_inbuf.t -> tree

Deserialization of a tree from a buffer.

Sourceval tree_of_string : ?unhash:(hash -> string option) -> string -> tree

Deserialization of a tree from a string.

Sourceval tag_of_tree : tree -> node_tag

Returns the node tag of the given tree.

Sourceval view_of_tree : tree -> string
Sourceval view : ?unhash:(hash -> string option) -> string -> string

Prints a human-readable representation of the data into a string.

Sourceval print_view_of_tree : tree -> unit
Sourceval print_view : ?unhash:(hash -> string option) -> string -> unit

Prints a human-readable representation of the data to stdout.

Sourceval output_view_of_tree : out_channel -> tree -> unit
Sourceval output_view : ?unhash:(hash -> string option) -> out_channel -> string -> unit

Prints a human-readable representation of the data to an out_channel.

Sourceval safety_test : unit -> unit

Check that certain low-level hacks work as expected

OCaml

Innovation. Community. Security.