Legend:
Library
Module
Module type
Parameter
Class
Class type
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