diff options
| author | Marcos Magueta <maguetamarcos@gmail.com> | 2026-03-07 02:40:26 -0300 |
|---|---|---|
| committer | Marcos Magueta <maguetamarcos@gmail.com> | 2026-03-07 02:40:26 -0300 |
| commit | e9bc4aa3fa0e775acf1978722da1fde1ed8a469d (patch) | |
| tree | ff78d21ba9a03acae20b15bb2fad2f27bcde75e1 /lib/storable.ml | |
| parent | fcd8571577f2b98ffc8fa2b95781ed16982804a9 (diff) | |
| download | Sakura-e9bc4aa3fa0e775acf1978722da1fde1ed8a469d.tar.gz Sakura-e9bc4aa3fa0e775acf1978722da1fde1ed8a469d.zip | |
erlang port commands and generated tests
Diffstat (limited to '')
| -rw-r--r-- | lib/storable.ml | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/lib/storable.ml b/lib/storable.ml new file mode 100644 index 0000000..058773c --- /dev/null +++ b/lib/storable.ml @@ -0,0 +1,56 @@ +(** Serialization formats for content-addressed storage. + + These modules define the wire format for persisting relational engine + objects to storage. Each type has to_bytes/of_bytes for serialization. + + The stored formats capture only the essential data needed for reconstruction: + - Tuple: relation name and attribute hashes + - Relation: name, schema, tuple hashes, cardinality + - Database: name, relation hashes, merkle tree keys, history *) + +(** Stored tuple format for serialization *) +module Tuple = struct + type t = { + relation : string; + attributes : (string * Conventions.Hash.t) list; (* attr_name -> attr_value_hash *) + } + + let to_bytes (st : t) : bytes = + Marshal.to_bytes st [Marshal.Closures] + + let of_bytes (b : bytes) : t = + Marshal.from_bytes b 0 +end + +(** Stored relation format for serialization *) +module Relation = struct + type t = { + name : string; + schema : Schema.t; + tree_keys : Conventions.Hash.t list; (* Merkle tree contents - tuple hashes *) + cardinality : Conventions.Cardinality.t; + } + + let to_bytes (sr : t) : bytes = + Marshal.to_bytes sr [Marshal.Closures] + + let of_bytes (b : bytes) : t = + Marshal.from_bytes b 0 +end + +(** Stored database format for serialization *) +module Database = struct + type t = { + name : string; + relations : (string * Conventions.Hash.t) list; (* name -> relation_hash *) + tree_keys : Conventions.Hash.t list; (* Merkle tree contents - relation hashes *) + history : Conventions.Hash.t list; + timestamp : float; + } + + let to_bytes (sd : t) : bytes = + Marshal.to_bytes sd [Marshal.Closures] + + let of_bytes (b : bytes) : t = + Marshal.from_bytes b 0 +end |
