aboutsummaryrefslogtreecommitdiffstats
path: root/include/TupleCodec.h
diff options
context:
space:
mode:
authorMarcos Magueta <maguetamarcos@gmail.com>2026-05-10 03:36:59 -0300
committerMarcos Magueta <maguetamarcos@gmail.com>2026-05-10 03:36:59 -0300
commit2864398c7b723c1d43166d422ea7028ef33cf9e3 (patch)
treeec63cd647239612167c36e521610f69023ed9303 /include/TupleCodec.h
parent7ffd4d99bbb8e358c6694c27c7ff859967872ece (diff)
downloadRNT-2864398c7b723c1d43166d422ea7028ef33cf9e3.tar.gz
RNT-2864398c7b723c1d43166d422ea7028ef33cf9e3.zip
sqlite backend with actual pagination
Diffstat (limited to 'include/TupleCodec.h')
-rw-r--r--include/TupleCodec.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/include/TupleCodec.h b/include/TupleCodec.h
new file mode 100644
index 0000000..18294d4
--- /dev/null
+++ b/include/TupleCodec.h
@@ -0,0 +1,52 @@
+#pragma once
+
+#include "Types.h"
+
+#include <cstdint>
+#include <string>
+#include <vector>
+
+/**
+ * @file TupleCodec.h
+ * @brief Content-addressing utilities for tuples.
+ *
+ * Mirrors Sakura's hashing.ml and physical.ml:
+ * - Hash() ≈ hash_tuple: deterministic SHA256 over sorted attribute content
+ * - Serialize() ≈ Marshal.to_bytes: raw bytes stored as the KV value
+ * - Deserialize() ≈ Marshal.from_bytes: reconstruct attributes from raw bytes
+ *
+ * The hash input format is:
+ * "path_seg1/path_seg2/..|name1:value1;name2:value2;"
+ * where attributes are sorted by name for determinism.
+ *
+ * The serialization format is a sequence of length-prefixed UTF-8 pairs:
+ * [uint32_le name_len][name bytes][uint32_le value_len][value bytes] ...
+ */
+
+namespace nt::TupleCodec
+{
+ /**
+ * @brief Computes the SHA256 hex digest of the serialized tuple.
+ *
+ * Equivalent to SHA256(Serialize(attrs)), so the value returned here
+ * matches the key returned by IStorageBackend::Put(Serialize(attrs)).
+ *
+ * @param attrs Attribute set. Need not be pre-sorted.
+ * @return 64-character lowercase hex string.
+ */
+ std::string Hash(const std::vector<Attribute>& attrs);
+
+ /**
+ * @brief Serializes a tuple's attributes to raw bytes for KV storage.
+ * @param attrs Attribute set. Need not be pre-sorted.
+ * @return Serialized bytes.
+ */
+ std::vector<uint8_t> Serialize(const std::vector<Attribute>& attrs);
+
+ /**
+ * @brief Reconstructs attributes from the bytes returned by Serialize().
+ * @param bytes Bytes produced by Serialize().
+ * @return Reconstructed attribute list in serialization order.
+ */
+ std::vector<Attribute> Deserialize(const std::vector<uint8_t>& bytes);
+}