Nix 2.93.3
Lix: A modern, delicious implementation of the Nix package manager; unstable internal interfaces
Loading...
Searching...
No Matches
serve-protocol.hh
Go to the documentation of this file.
1#pragma once
3
5
6namespace nix {
7
8#define SERVE_MAGIC_1 0x390c9deb
9#define SERVE_MAGIC_2 0x5452eecb
10
11// This must remain at 2.7 (Nix 2.18) forever in Lix, since the protocol
12// versioning is monotonic, so if we ever change it in the future, it will
13// break compatibility with any potential CppNix-originated protocol changes.
14//
15// Lix intends to replace this protocol entirely.
16#define SERVE_PROTOCOL_VERSION (2 << 8 | 7)
17#define GET_PROTOCOL_MAJOR(x) ((x) & 0xff00)
18#define GET_PROTOCOL_MINOR(x) ((x) & 0x00ff)
19
20
21class Store;
22struct Source;
23
24// items being serialised
25struct BuildResult;
27
28
36{
40 enum struct Command : uint64_t;
41
47 using Version = unsigned int;
48
53 struct ReadConn {
54 Source & from;
55 Version version;
56 };
57
62 struct WriteConn {
63 Version version;
64 };
65
72 template<typename T>
73 struct Serialise;
74 // This is the definition of `Serialise` we *want* to put here, but
75 // do not do so.
76 //
77 // See `worker-protocol.hh` for a longer explanation.
78#if 0
79 {
80 static T read(const Store & store, ReadConn conn);
81 static WireFormatGenerator write(const Store & store, WriteConn conn, const T & t);
82 };
83#endif
84
89 template<typename T>
90 [[nodiscard]]
91 static WireFormatGenerator write(const Store & store, WriteConn conn, const T & t)
92 {
93 return ServeProto::Serialise<T>::write(store, conn, t);
94 }
95};
96
97enum struct ServeProto::Command : uint64_t
98{
99 QueryValidPaths = 1,
100 QueryPathInfos = 2,
101 DumpStorePath = 3,
102 ImportPaths = 4,
103 ExportPaths = 5,
104 BuildPaths = 6,
105 QueryClosure = 7,
106 BuildDerivation = 8,
107 AddToStoreNar = 9,
108};
109
116inline Sink & operator << (Sink & sink, ServeProto::Command op)
117{
118 return sink << (uint64_t) op;
119}
120
126inline std::ostream & operator << (std::ostream & s, ServeProto::Command op)
127{
128 return s << (uint64_t) op;
129}
130
141#define DECLARE_SERVE_SERIALISER(T) \
142 struct ServeProto::Serialise< T > \
143 { \
144 static T read(const Store & store, ServeProto::ReadConn conn); \
145 [[nodiscard]] static WireFormatGenerator write(const Store & store, ServeProto::WriteConn conn, const T & t); \
146 };
147
148template<>
150template<>
152
153template<typename T>
155template<typename T>
157template<typename... Ts>
158DECLARE_SERVE_SERIALISER(std::tuple<Ts...>);
159
160#define COMMA_ ,
161template<typename K, typename V>
162DECLARE_SERVE_SERIALISER(std::map<K COMMA_ V>);
163#undef COMMA_
164
165}
Definition store-api.hh:195
#define DECLARE_SERVE_SERIALISER(T)
Definition serve-protocol.hh:141
Definition build-result.hh:17
Definition serve-protocol.hh:53
Definition serve-protocol.hh:73
Definition serve-protocol.hh:62
Definition serve-protocol.hh:36
static WireFormatGenerator write(const Store &store, WriteConn conn, const T &t)
Definition serve-protocol.hh:91
unsigned int Version
Definition serve-protocol.hh:47
Definition serialise.hh:18
Definition serialise.hh:66
Definition path-info.hh:36