Module Irmin_traces.Trace_common

Trace_common contains utility to simplify the management of files using the following layout:

    - Magic (Magic.t, 8 bytes)
    - Version (int32, 4 bytes)
    - Length of header (varint, >=1 byte)
    - Header (header_t, _ bytes)
    - Arbitrary long series of rows, of unspecified length, each prefixed by their length:
      - Length of row (varint, >=1 byte)
      - Row (row_t, _ bytes)

This file is meant to be used from Tezos. OCaml version 4.09 and the 32bit architecture should be supported.

Example

module Example = struct
  module V2 = struct
    let version = 2

    type header = unit [@@deriving repr]
    type row = [ `A | `B | `C ] [@@deriving repr]
  end

  module V1 = struct
    let version = 1

    type header = unit [@@deriving repr]
    type row = [ `A | `B ] [@@deriving repr]

    let to_v2 x = (x :> V2.row)
  end

  module V0 = struct
    let version = 0

    type header = unit [@@deriving repr]
    type row = [ `A of int | `B of int ] [@@deriving repr]

    let to_v1 = function `A _ -> `A | `B _ -> `B
  end

  module Latest = V2
  include Latest

  include Trace_common.Io (struct
    module Latest = Latest

    let magic = Trace_common.Magic.of_string "Magique_"

    let get_version_converter = function
      | 2 ->
          Trace_common.Version_converter
            {
              header_t = V2.header_t;
              row_t = V2.row_t;
              upgrade_header = Fun.id;
              upgrade_row = Fun.id;
            }
      | 1 ->
          Version_converter
            {
              header_t = V1.header_t;
              row_t = V1.row_t;
              upgrade_header = Fun.id;
              upgrade_row = V1.to_v2;
            }
      | 0 ->
          Version_converter
            {
              header_t = V0.header_t;
              row_t = V0.row_t;
              upgrade_header = Fun.id;
              upgrade_row = (fun x -> V0.to_v1 x |> V1.to_v2);
            }
      | i -> Fmt.invalid_arg "Unknown Example version %d" i
  end)
end
module Seq : sig ... end
module Magic : sig ... end
type ('latest_header, 'latest_row, 'header, 'row) version_converter' = {
  1. header_t : 'header Repr.ty;
  2. row_t : 'row Repr.ty;
  3. upgrade_header : 'header -> 'latest_header;
  4. upgrade_row : 'row -> 'latest_row;
}

Contains everything needed to read a file as if it is written with the lastest version.

type ('latest_header, 'latest_row) version_converter =
  1. | Version_converter : ('latest_header, 'latest_row, 'header, 'row) version_converter' -> ('latest_header, 'latest_row) version_converter

A box containing the above record

module type File_format = sig ... end
module Var_int : sig ... end

Very similar to what can be found in "repr/type_binary.ml", but working straight off channels.

module Io (Ff : File_format) : sig ... end

Derive the IO operations from a file format. Only the write operations are performance sensitive, the read operations are not.