Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
common-protocol.hh
Go to the documentation of this file.
1#pragma once
3
5
6namespace nix {
7
8class Store;
9struct Source;
10
11// items being serialized
12class StorePath;
13struct ContentAddress;
14struct DrvOutput;
15struct Realisation;
16
17
26{
31 struct ReadConn {
32 Source & from;
33 };
34
39 struct WriteConn {
40 };
41
42 template<typename T>
43 struct Serialise;
44
49 template<typename T>
50 [[nodiscard]]
51 static WireFormatGenerator write(const Store & store, WriteConn conn, const T & t)
52 {
53 return CommonProto::Serialise<T>::write(store, conn, t);
54 }
55};
56
57#define DECLARE_COMMON_SERIALISER(T) \
58 struct CommonProto::Serialise< T > \
59 { \
60 static T read(const Store & store, CommonProto::ReadConn conn); \
61 [[nodiscard]] static WireFormatGenerator write(const Store & store, CommonProto::WriteConn conn, const T & str); \
62 }
63
64template<>
65DECLARE_COMMON_SERIALISER(std::string);
66template<>
67DECLARE_COMMON_SERIALISER(StorePath);
68template<>
69DECLARE_COMMON_SERIALISER(ContentAddress);
70template<>
71DECLARE_COMMON_SERIALISER(DrvOutput);
72template<>
73DECLARE_COMMON_SERIALISER(Realisation);
74
75template<typename T>
76DECLARE_COMMON_SERIALISER(std::vector<T>);
77template<typename T>
78DECLARE_COMMON_SERIALISER(std::set<T>);
79template<typename... Ts>
80DECLARE_COMMON_SERIALISER(std::tuple<Ts...>);
81
82#define COMMA_ ,
83template<typename K, typename V>
84DECLARE_COMMON_SERIALISER(std::map<K COMMA_ V>);
85#undef COMMA_
86
101template<>
102DECLARE_COMMON_SERIALISER(std::optional<StorePath>);
103template<>
104DECLARE_COMMON_SERIALISER(std::optional<ContentAddress>);
105
106}
Definition path.hh:21
Definition store-api.hh:195
Definition common-protocol.hh:31
Definition common-protocol.hh:43
Definition common-protocol.hh:39
Definition common-protocol.hh:26
static WireFormatGenerator write(const Store &store, WriteConn conn, const T &t)
Definition common-protocol.hh:51
Definition content-address.hh:126
Definition realisation.hh:24
Definition realisation.hh:49
Definition serialise.hh:66