diff --git a/src/trace/sidekick_trace.ml b/src/trace/sidekick_trace.ml index 109079c6..7b8965b4 100644 --- a/src/trace/sidekick_trace.ml +++ b/src/trace/sidekick_trace.ml @@ -23,6 +23,7 @@ open Sidekick_sigs module Entry_view = Entry_view module Entry_read = Entry_read module Sink = Sink +module Source = Source module Entry_id = Entry_id type entry_id = Entry_id.t diff --git a/src/trace/source.ml b/src/trace/source.ml new file mode 100644 index 00000000..b4cfa0cf --- /dev/null +++ b/src/trace/source.ml @@ -0,0 +1,15 @@ +type tag = string + +module type S = sig + val get_entry : Entry_id.t -> tag * Ser_value.t + val iter_all : (Entry_id.t -> tag:tag -> Ser_value.t -> unit) -> unit +end + +type t = (module S) + +let get_entry_exn (module S : S) id = S.get_entry id + +let get_entry (module S : S) id : _ option = + try Some (S.get_entry id) with Not_found -> None + +let iter_all (module S : S) f : unit = S.iter_all f diff --git a/src/trace/source.mli b/src/trace/source.mli new file mode 100644 index 00000000..6bbbd5d4 --- /dev/null +++ b/src/trace/source.mli @@ -0,0 +1,22 @@ +(** Source to read a trace. + + A source is an IO input source that allows the read of individual + entries of the trace, by providing their entry ID. It also allows to + iterate on entries in chronological order. +*) + +type tag = string + +module type S = sig + val get_entry : Entry_id.t -> tag * Ser_value.t + (** @raise Not_found if there is no such entry *) + + val iter_all : (Entry_id.t -> tag:tag -> Ser_value.t -> unit) -> unit + (** Iterate on all entries *) +end + +type t = (module S) + +val get_entry : t -> Entry_id.t -> (tag * Ser_value.t) option +val get_entry_exn : t -> Entry_id.t -> tag * Ser_value.t +val iter_all : t -> (Entry_id.t -> tag:tag -> Ser_value.t -> unit) -> unit