#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" namespace nix { template std::vector WorkerProto::Serialise>::read(const Store & store, WorkerProto::ReadConn conn) { std::vector resSet; auto size = readNum(conn.from); while (size--) { resSet.push_back(WorkerProto::Serialise::read(store, conn)); } return resSet; } template void WorkerProto::Serialise>::write(const Store & store, WorkerProto::WriteConn conn, const std::vector & resSet) { conn.to << resSet.size(); for (auto & key : resSet) { WorkerProto::Serialise::write(store, conn, key); } } template std::set WorkerProto::Serialise>::read(const Store & store, WorkerProto::ReadConn conn) { std::set resSet; auto size = readNum(conn.from); while (size--) { resSet.insert(WorkerProto::Serialise::read(store, conn)); } return resSet; } template void WorkerProto::Serialise>::write(const Store & store, WorkerProto::WriteConn conn, const std::set & resSet) { conn.to << resSet.size(); for (auto & key : resSet) { WorkerProto::Serialise::write(store, conn, key); } } template std::map WorkerProto::Serialise>::read(const Store & store, WorkerProto::ReadConn conn) { std::map resMap; auto size = readNum(conn.from); while (size--) { auto k = WorkerProto::Serialise::read(store, conn); auto v = WorkerProto::Serialise::read(store, conn); resMap.insert_or_assign(std::move(k), std::move(v)); } return resMap; } template void WorkerProto::Serialise>::write(const Store & store, WorkerProto::WriteConn conn, const std::map & resMap) { conn.to << resMap.size(); for (auto & i : resMap) { WorkerProto::Serialise::write(store, conn, i.first); WorkerProto::Serialise::write(store, conn, i.second); } } template std::tuple WorkerProto::Serialise>::read(const Store & store, WorkerProto::ReadConn conn) { return std::tuple { WorkerProto::Serialise::read(store, conn)..., }; } template void WorkerProto::Serialise>::write(const Store & store, WorkerProto::WriteConn conn, const std::tuple & res) { std::apply([&](const Us &... args) { (WorkerProto::Serialise::write(store, conn, args), ...); }, res); } }