aboutsummaryrefslogtreecommitdiff
path: root/src/libstore/worker-protocol.hh
diff options
context:
space:
mode:
authoreldritch horrors <pennae@lix.systems>2024-03-04 04:24:23 +0100
committereldritch horrors <pennae@lix.systems>2024-03-04 04:36:58 +0100
commit6897e238bd0c730af224b928ec8746781df67ad2 (patch)
tree50ce7ddeda203a12c7d67080ef611f56d59678c2 /src/libstore/worker-protocol.hh
parentda0aa66d98b8b46253dd968cfaae61d872569c9b (diff)
Merge pull request #9099 from obsidiansystems/common-proto
Factor out bits of the worker protocol to use elsewhere (cherry picked from commit 4b1a97338f517f45e6169d3d8845c5caa5724e97) Change-Id: If93afa0f8b1cf9b0e705b34fa71e6fd708752758
Diffstat (limited to 'src/libstore/worker-protocol.hh')
-rw-r--r--src/libstore/worker-protocol.hh60
1 files changed, 14 insertions, 46 deletions
diff --git a/src/libstore/worker-protocol.hh b/src/libstore/worker-protocol.hh
index b7f42f24d..c84060103 100644
--- a/src/libstore/worker-protocol.hh
+++ b/src/libstore/worker-protocol.hh
@@ -1,7 +1,7 @@
#pragma once
///@file
-#include "serialise.hh"
+#include "common-protocol.hh"
namespace nix {
@@ -28,11 +28,7 @@ class Store;
struct Source;
// items being serialised
-class StorePath;
-struct ContentAddress;
struct DerivedPath;
-struct DrvOutput;
-struct Realisation;
struct BuildResult;
struct KeyedBuildResult;
enum TrustedFlag : bool;
@@ -193,60 +189,32 @@ inline std::ostream & operator << (std::ostream & s, WorkerProto::Op op)
* be legal specialization syntax. See below for what that looks like in
* practice.
*/
-#define MAKE_WORKER_PROTO(T) \
- struct WorkerProto::Serialise< T > { \
+#define DECLARE_WORKER_SERIALISER(T) \
+ struct WorkerProto::Serialise< T > \
+ { \
static T read(const Store & store, WorkerProto::ReadConn conn); \
static void write(const Store & store, WorkerProto::WriteConn conn, const T & t); \
};
template<>
-MAKE_WORKER_PROTO(std::string);
+DECLARE_WORKER_SERIALISER(DerivedPath);
template<>
-MAKE_WORKER_PROTO(StorePath);
+DECLARE_WORKER_SERIALISER(BuildResult);
template<>
-MAKE_WORKER_PROTO(ContentAddress);
+DECLARE_WORKER_SERIALISER(KeyedBuildResult);
template<>
-MAKE_WORKER_PROTO(DerivedPath);
-template<>
-MAKE_WORKER_PROTO(DrvOutput);
-template<>
-MAKE_WORKER_PROTO(Realisation);
-template<>
-MAKE_WORKER_PROTO(BuildResult);
-template<>
-MAKE_WORKER_PROTO(KeyedBuildResult);
-template<>
-MAKE_WORKER_PROTO(std::optional<TrustedFlag>);
+DECLARE_WORKER_SERIALISER(std::optional<TrustedFlag>);
template<typename T>
-MAKE_WORKER_PROTO(std::vector<T>);
+DECLARE_WORKER_SERIALISER(std::vector<T>);
template<typename T>
-MAKE_WORKER_PROTO(std::set<T>);
+DECLARE_WORKER_SERIALISER(std::set<T>);
template<typename... Ts>
-MAKE_WORKER_PROTO(std::tuple<Ts...>);
+DECLARE_WORKER_SERIALISER(std::tuple<Ts...>);
+#define COMMA_ ,
template<typename K, typename V>
-#define X_ std::map<K, V>
-MAKE_WORKER_PROTO(X_);
-#undef X_
-
-/**
- * These use the empty string for the null case, relying on the fact
- * that the underlying types never serialise to the empty string.
- *
- * We do this instead of a generic std::optional<T> instance because
- * ordinal tags (0 or 1, here) are a bit of a compatability hazard. For
- * the same reason, we don't have a std::variant<T..> instances (ordinal
- * tags 0...n).
- *
- * We could the generic instances and then these as specializations for
- * compatability, but that's proven a bit finnicky, and also makes the
- * worker protocol harder to implement in other languages where such
- * specializations may not be allowed.
- */
-template<>
-MAKE_WORKER_PROTO(std::optional<StorePath>);
-template<>
-MAKE_WORKER_PROTO(std::optional<ContentAddress>);
+DECLARE_WORKER_SERIALISER(std::map<K COMMA_ V>);
+#undef COMMA_
}