this is cursed. deeply and profoundly cursed. under NO CIRCUMSTANCES must protocol serializer helpers be applied to temporaries! doing so will inevitably cause dangling references and cause the entire thing to crash. we need to do this even so to get rid of boost coroutines, and likewise to encapsulate the serializers we suffer today at least a little bit to allow a gradual migration to an actual IPC protocol. Change-Id: I2921ba451e04d86798752d140885d3c5cc08e146
61 lines
1.7 KiB
C++
61 lines
1.7 KiB
C++
#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 "serve-protocol.hh"
|
|
#include "length-prefixed-protocol-helper.hh"
|
|
|
|
namespace nix {
|
|
|
|
/* protocol-agnostic templates */
|
|
|
|
#define SERVE_USE_LENGTH_PREFIX_SERIALISER(TEMPLATE, T) \
|
|
TEMPLATE T ServeProto::Serialise< T >::read(const Store & store, ServeProto::ReadConn conn) \
|
|
{ \
|
|
return LengthPrefixedProtoHelper<ServeProto, T >::read(store, conn); \
|
|
} \
|
|
TEMPLATE [[nodiscard]] WireFormatGenerator ServeProto::Serialise< T >::write(const Store & store, ServeProto::WriteConn conn, const T & t) \
|
|
{ \
|
|
return LengthPrefixedProtoHelper<ServeProto, T >::write(store, conn, t); \
|
|
}
|
|
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::vector<T>)
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename T>, std::set<T>)
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(template<typename... Ts>, std::tuple<Ts...>)
|
|
|
|
#define COMMA_ ,
|
|
SERVE_USE_LENGTH_PREFIX_SERIALISER(
|
|
template<typename K COMMA_ typename V>,
|
|
std::map<K COMMA_ V>)
|
|
#undef COMMA_
|
|
|
|
/**
|
|
* Use `CommonProto` where possible.
|
|
*/
|
|
template<typename T>
|
|
struct ServeProto::Serialise
|
|
{
|
|
static T read(const Store & store, ServeProto::ReadConn conn)
|
|
{
|
|
return CommonProto::Serialise<T>::read(store,
|
|
CommonProto::ReadConn { .from = conn.from });
|
|
}
|
|
[[nodiscard]]
|
|
static WireFormatGenerator write(const Store & store, ServeProto::WriteConn conn, const T & t)
|
|
{
|
|
return CommonProto::Serialise<T>::write(store,
|
|
CommonProto::WriteConn { .to = conn.to },
|
|
t);
|
|
}
|
|
};
|
|
|
|
/* protocol-specific templates */
|
|
|
|
}
|