aboutsummaryrefslogtreecommitdiff
path: root/src/zencore
diff options
context:
space:
mode:
authorStefan Boberg <[email protected]>2023-05-25 15:42:36 +0200
committerGitHub <[email protected]>2023-05-25 15:42:36 +0200
commit3994bac926bcceb03a89ba74d164dcd687d70db6 (patch)
treed967928c38dea7449381c85b1a6a60887964e491 /src/zencore
parentminor: refcount bump elimination (diff)
downloadzen-3994bac926bcceb03a89ba74d164dcd687d70db6.tar.xz
zen-3994bac926bcceb03a89ba74d164dcd687d70db6.zip
oplog snapshot (#317)
Added "snapshot" oplog RPC this may be used to bring referenced files into the local store instead of referencing them by filename, thus making the project/oplog transportable
Diffstat (limited to 'src/zencore')
-rw-r--r--src/zencore/include/zencore/compactbinaryutil.h42
1 files changed, 42 insertions, 0 deletions
diff --git a/src/zencore/include/zencore/compactbinaryutil.h b/src/zencore/include/zencore/compactbinaryutil.h
new file mode 100644
index 000000000..9d69266bf
--- /dev/null
+++ b/src/zencore/include/zencore/compactbinaryutil.h
@@ -0,0 +1,42 @@
+// Copyright Epic Games, Inc. All Rights Reserved.
+
+#pragma once
+
+#include <zencore/zencore.h>
+
+#include <zencore/compactbinary.h>
+#include <zencore/compactbinarybuilder.h>
+
+namespace zen {
+
+/** Object rewrite helper
+
+ This is meant to be used when you have a fully formed CbObject which you wish
+ to rewrite. Since the compact binary format is not meant for in-place updates
+ this involves scanning the object, copying the fields we want to keep and
+ writing new versions of the fields we wish to keep.
+
+ The Rewriter function accepts a reference to the CbObjectWriter which is being
+ used to build the new version of the object and a reference to a field which is
+ considered for copy or rewriting. If the function wants to rewrite a field then
+ it'll use the writer to write a new field and then return `true`, otherwise just
+ return `false` to have RewriteCbObject copy the field into the new object.
+*/
+
+CbObject
+RewriteCbObject(CbObjectView InObj, Invocable<CbObjectWriter&, CbFieldView&> auto Rewriter)
+{
+ CbObjectWriter CboWriter;
+
+ for (CbFieldView InnerField : InObj)
+ {
+ if (!Rewriter(CboWriter, InnerField))
+ {
+ CboWriter.AddField(InnerField.GetName(), InnerField);
+ }
+ }
+
+ return CboWriter.Save();
+}
+
+} // namespace zen