summaryrefslogtreecommitdiff
path: root/src/main.cpp
diff options
context:
space:
mode:
authorRoman Smrž <roman.smrz@seznam.cz>2022-10-09 23:02:54 +0200
committerRoman Smrž <roman.smrz@seznam.cz>2022-11-01 22:36:45 +0100
commit4d82c7e2704c035e33b9b606c409e5fac0f4f708 (patch)
treed03922bdf7f9cac0be99605244306bd7ef0f4803 /src/main.cpp
parentc6d01458b4545500a964491c2602da3c3079bfc2 (diff)
Stored set
Diffstat (limited to 'src/main.cpp')
-rw-r--r--src/main.cpp36
1 files changed, 36 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp
index 4dc4582..95d3eeb 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -1,6 +1,7 @@
#include <erebos/attach.h>
#include <erebos/identity.h>
#include <erebos/network.h>
+#include <erebos/set.h>
#include <erebos/storage.h>
#include <erebos/sync.h>
@@ -162,6 +163,39 @@ void storedRoots(const vector<string> & args)
printLine(ss.str());
}
+void storedSetAdd(const vector<string> & args)
+{
+ auto iref = st.ref(Digest(args.at(0)));
+ if (!iref)
+ throw invalid_argument("ref " + args.at(0) + " not found");
+
+ auto set = args.size() > 1 ?
+ Set<vector<Stored<Object>>>::load({ *st.ref(Digest(args.at(1))) }) :
+ Set<vector<Stored<Object>>>();
+
+ ostringstream ss;
+ ss << "stored-set-add";
+ for (const auto & d : set.add(st, { Stored<Object>::load(*iref) }).digests())
+ ss << " " << string(d);
+ printLine(ss.str());
+}
+
+void storedSetList(const vector<string> & args)
+{
+ auto ref = st.ref(Digest(args.at(0)));
+ if (!ref)
+ throw invalid_argument("ref " + args.at(0) + " not found");
+
+ for (const auto & vec : Set<vector<Stored<Object>>>::load({ *ref }).view(std::less{})) {
+ ostringstream ss;
+ ss << "stored-set-item";
+ for (const auto & x : vec)
+ ss << " " << string(x.ref().digest());
+ printLine(ss.str());
+ }
+ printLine("stored-set-done");
+}
+
void createIdentity(const vector<string> & args)
{
optional<Identity> identity;
@@ -353,6 +387,8 @@ vector<Command> commands = {
{ "store", store },
{ "stored-generation", storedGeneration },
{ "stored-roots", storedRoots },
+ { "stored-set-add", storedSetAdd },
+ { "stored-set-list", storedSetList },
{ "create-identity", createIdentity },
{ "start-server", startServer },
{ "stop-server", stopServer },