aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/Branch.ml
diff options
context:
space:
mode:
authorEstevan Castilho <tevo@riajuu.net>2026-08-27 01:35:53 +0000
committerEstevan Castilho <tevo@riajuu.net>2026-08-27 01:41:12 +0000
commite61404f0219cd8f07c6c278f7ee952c70ce5bdf4 (patch)
tree412aa6ca71df835fb154427a32bb2573944faa8a /lib/kernel/Branch.ml
parent9efb32195a905de2d66ce29164cc22970833c2d7 (diff)
downloadRNT-e61404f0219cd8f07c6c278f7ee952c70ce5bdf4.tar.gz
RNT-e61404f0219cd8f07c6c278f7ee952c70ce5bdf4.zip
Branch serialization
Diffstat (limited to '')
-rw-r--r--lib/kernel/Branch.ml60
-rw-r--r--lib/kernel/Branch.mli5
2 files changed, 65 insertions, 0 deletions
diff --git a/lib/kernel/Branch.ml b/lib/kernel/Branch.ml
new file mode 100644
index 0000000..2aaa9ca
--- /dev/null
+++ b/lib/kernel/Branch.ml
@@ -0,0 +1,60 @@
+module Multigroup = Merkle.StringKey (* FIXME *)
+
+module Make (S : Abstract.Storage.STORAGE) = struct
+ (* Branch has a name, a set of multigroups, and a backlink to the previous state
+ multigroup has a name and a set of schemas
+ schema has a name and a set of relations
+
+ /branch/master/multigroup/universe/schema/sky/relation/planet
+ *)
+
+ module SI = Storage.Make (S)
+
+ module MultigroupM = Merkle.Interface (S) (Merkle.StringKey) (Multigroup)
+
+ type t = {
+ multigroups : MultigroupM.address;
+ previous : t SI.Pointer.t option
+ }
+
+ module rec Representation : Concepts.Encoding.Record.S with type t = t = Concepts.Encoding.Record.Make (Body)
+ and Body : Concepts.Encoding.Record.BODY = struct
+ type nonrec t = t
+
+ let load tx addr =
+ SI.get_req tx addr
+ |> Utilities.Result.fmap Representation.of_blob
+
+ let tag = 'Y'
+ let malformed () =
+ Concepts.Condition.
+ (condition "malformed-branch" "The on-disk representation of a branch did not conform to what was expected. Is your database corrupted?"
+ empty)
+
+ let fields { multigroups; previous } =
+ let open Concepts.Encoding in
+ ["multigroups", Value.bencode_of_hash multigroups;
+ "previous", Value.bencode_of_option
+ (fun v -> SI.Pointer.address_of v
+ |> SI.as_hash
+ |> Value.bencode_of_hash)
+ previous]
+
+ let of_fields fields =
+ let open Utilities.Result in
+ let open Concepts.Encoding in
+ let* multigroups = Bencode.field "multigroups" fields |> fmap Value.hash_of_bencode in
+ let* previous = Bencode.field "previous" fields
+ |> fmap (Value.option_of_bencode
+ (fun v -> Value.hash_of_bencode v
+ |> Result.map (fun hash -> S.Hash hash)
+ |> Result.map (Fun.flip (SI.Pointer.make) load))) in
+ Ok { multigroups; previous }
+ end
+
+ class branch = object
+ (* TODO *)
+ end
+
+ let load _tx _conn _name _addr = failwith "TODO"
+end
diff --git a/lib/kernel/Branch.mli b/lib/kernel/Branch.mli
new file mode 100644
index 0000000..02be2ed
--- /dev/null
+++ b/lib/kernel/Branch.mli
@@ -0,0 +1,5 @@
+module Make (S : Abstract.Storage.STORAGE) : sig
+ type t
+
+ val load : S.transaction -> S.connection -> string -> Concepts.Hash.hash -> (Protocols.Handle.t, Concepts.Condition.condition) result
+end