2022-03-08 21:53:26 +00:00
|
|
|
#pragma once
|
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
*
|
|
|
|
* Template implementations (as opposed to mere declarations).
|
|
|
|
*
|
|
|
|
* This file is an exmample of the "impl.hh" pattern. See the
|
|
|
|
* contributing guide.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "worker-protocol.hh"
|
2024-03-04 03:24:23 +00:00
|
|
|
#include "length-prefixed-protocol-helper.hh"
|
2022-03-08 21:53:26 +00:00
|
|
|
|
|
|
|
namespace nix {
|
|
|
|
|
2024-03-04 03:24:23 +00:00
|
|
|
/* protocol-agnostic templates */
|
2022-03-08 21:53:26 +00:00
|
|
|
|
2024-03-04 03:24:23 +00:00
|
|
|
#define WORKER_USE_LENGTH_PREFIX_SERIALISER(TEMPLATE, T) \
|
|
|
|
TEMPLATE T WorkerProto::Serialise< T >::read(const Store & store, WorkerProto::ReadConn conn) \
|
|
|
|
{ \
|
|
|
|
return LengthPrefixedProtoHelper<WorkerProto, T >::read(store, conn); \
|
|
|
|
} \
|
|
|
|
TEMPLATE void WorkerProto::Serialise< T >::write(const Store & store, WorkerProto::WriteConn conn, const T & t) \
|
|
|
|
{ \
|
|
|
|
LengthPrefixedProtoHelper<WorkerProto, T >::write(store, conn, t); \
|
2022-03-08 21:53:26 +00:00
|
|
|
}
|
|
|
|
|
2024-03-04 03:24:23 +00:00
|
|
|
WORKER_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::vector<T>)
|
|
|
|
WORKER_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::set<T>)
|
|
|
|
WORKER_USE_LENGTH_PREFIX_SERIALISER(template<typename... Ts>, std::tuple<Ts...>)
|
2022-03-08 21:53:26 +00:00
|
|
|
|
2024-03-04 03:24:23 +00:00
|
|
|
#define COMMA_ ,
|
|
|
|
WORKER_USE_LENGTH_PREFIX_SERIALISER(
|
|
|
|
template<typename K COMMA_ typename V>,
|
|
|
|
std::map<K COMMA_ V>)
|
|
|
|
#undef COMMA_
|
2022-03-08 21:53:26 +00:00
|
|
|
|
2024-03-04 03:24:23 +00:00
|
|
|
/**
|
|
|
|
* Use `CommonProto` where possible.
|
|
|
|
*/
|
|
|
|
template<typename T>
|
|
|
|
struct WorkerProto::Serialise
|
2022-03-08 21:53:26 +00:00
|
|
|
{
|
2024-03-04 03:24:23 +00:00
|
|
|
static T read(const Store & store, WorkerProto::ReadConn conn)
|
|
|
|
{
|
|
|
|
return CommonProto::Serialise<T>::read(store,
|
|
|
|
CommonProto::ReadConn { .from = conn.from });
|
2022-03-08 21:53:26 +00:00
|
|
|
}
|
2024-03-04 03:24:23 +00:00
|
|
|
static void write(const Store & store, WorkerProto::WriteConn conn, const T & t)
|
|
|
|
{
|
|
|
|
CommonProto::Serialise<T>::write(store,
|
|
|
|
CommonProto::WriteConn { .to = conn.to },
|
|
|
|
t);
|
2022-03-08 21:53:26 +00:00
|
|
|
}
|
2024-03-04 03:24:23 +00:00
|
|
|
};
|
2024-03-04 02:46:48 +00:00
|
|
|
|
2024-03-04 03:24:23 +00:00
|
|
|
/* protocol-specific templates */
|
2024-03-04 02:46:48 +00:00
|
|
|
|
2022-03-08 21:53:26 +00:00
|
|
|
}
|