#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" #include "length-prefixed-protocol-helper.hh" namespace nix { /* protocol-agnostic templates */ #define WORKER_USE_LENGTH_PREFIX_SERIALISER(TEMPLATE, T) \ TEMPLATE T WorkerProto::Serialise< T >::read(const Store & store, WorkerProto::ReadConn conn) \ { \ return LengthPrefixedProtoHelper::read(store, conn); \ } \ /* NOLINTNEXTLINE(bugprone-macro-parentheses) */ \ TEMPLATE [[nodiscard]] WireFormatGenerator WorkerProto::Serialise< T >::write(const Store & store, WorkerProto::WriteConn conn, const T & t) \ { \ return LengthPrefixedProtoHelper::write(store, conn, t); \ } WORKER_USE_LENGTH_PREFIX_SERIALISER(template, std::vector) WORKER_USE_LENGTH_PREFIX_SERIALISER(template, std::set) WORKER_USE_LENGTH_PREFIX_SERIALISER(template, std::tuple) #define COMMA_ , WORKER_USE_LENGTH_PREFIX_SERIALISER( template, std::map) #undef COMMA_ /** * Use `CommonProto` where possible. */ template struct WorkerProto::Serialise { static T read(const Store & store, WorkerProto::ReadConn conn) { return CommonProto::Serialise::read(store, CommonProto::ReadConn { .from = conn.from }); } [[nodiscard]] static WireFormatGenerator write(const Store & store, WorkerProto::WriteConn conn, const T & t) { return CommonProto::Serialise::write(store, CommonProto::WriteConn {}, t); } }; /* protocol-specific templates */ }