WIP: Put the worker protocol read and write in a namespace to disambig

This commit is contained in:
John Ericson 2020-08-05 20:37:48 +00:00
parent ed96e603e1
commit 6c66331d5c
2 changed files with 16 additions and 5 deletions

View file

@ -58,6 +58,8 @@ void writeStorePathCAMap(const Store & store, Sink & out, const StorePathCAMap &
} }
namespace worker_proto {
StorePath read(const Store & store, Source & from, Phantom<StorePath> _) StorePath read(const Store & store, Source & from, Phantom<StorePath> _)
{ {
return store.parseStorePath(readString(from)); return store.parseStorePath(readString(from));
@ -68,6 +70,8 @@ void write(const Store & store, Sink & out, const StorePath & storePath)
out << store.printStorePath(storePath); out << store.printStorePath(storePath);
} }
}
/* TODO: Separate these store impls into different files, give them better names */ /* TODO: Separate these store impls into different files, give them better names */
RemoteStore::RemoteStore(const Params & params) RemoteStore::RemoteStore(const Params & params)
@ -461,7 +465,7 @@ std::map<std::string, std::optional<StorePath>> RemoteStore::queryDerivationOutp
auto conn(getConnection()); auto conn(getConnection());
conn->to << wopQueryDerivationOutputMap << printStorePath(path); conn->to << wopQueryDerivationOutputMap << printStorePath(path);
conn.processStderr(); conn.processStderr();
return read(*this, conn->from, Phantom<std::map<std::string, std::optional<StorePath>>> {}); return worker_proto::read(*this, conn->from, Phantom<std::map<std::string, std::optional<StorePath>>> {});
} }

View file

@ -74,6 +74,10 @@ void writeStorePaths(const Store & store, Sink & out, const StorePathSet & paths
template<typename T> template<typename T>
struct Phantom {}; struct Phantom {};
namespace worker_proto {
/* FIXME maybe move more stuff inside here */
template<typename T> template<typename T>
std::map<std::string, T> read(const Store & store, Source & from, Phantom<std::map<std::string, T>> _) std::map<std::string, T> read(const Store & store, Source & from, Phantom<std::map<std::string, T>> _)
{ {
@ -81,7 +85,7 @@ std::map<std::string, T> read(const Store & store, Source & from, Phantom<std::m
auto size = (size_t)readInt(from); auto size = (size_t)readInt(from);
while (size--) { while (size--) {
auto thisKey = readString(from); auto thisKey = readString(from);
resMap.insert_or_assign(std::move(thisKey), read(store, from, Phantom<T> {})); resMap.insert_or_assign(std::move(thisKey), nix::worker_proto::read(store, from, Phantom<T> {}));
} }
return resMap; return resMap;
} }
@ -92,7 +96,7 @@ void write(const Store & store, Sink & out, const std::map<string, T> & resMap)
out << resMap.size(); out << resMap.size();
for (auto & i : resMap) { for (auto & i : resMap) {
out << i.first; out << i.first;
write(store, out, i.second); nix::worker_proto::write(store, out, i.second);
} }
} }
@ -104,7 +108,7 @@ std::optional<T> read(const Store & store, Source & from, Phantom<std::optional<
case 0: case 0:
return std::nullopt; return std::nullopt;
case 1: case 1:
return read(store, from, Phantom<T> {}); return nix::worker_proto::read(store, from, Phantom<T> {});
default: default:
throw Error("got an invalid tag bit for std::optional: %#04x", tag); throw Error("got an invalid tag bit for std::optional: %#04x", tag);
} }
@ -115,13 +119,16 @@ void write(const Store & store, Sink & out, const std::optional<T> & optVal)
{ {
out << (optVal ? 1 : 0); out << (optVal ? 1 : 0);
if (optVal) if (optVal)
write(store, out, *optVal); nix::worker_proto::write(store, out, *optVal);
} }
StorePath read(const Store & store, Source & from, Phantom<StorePath> _); StorePath read(const Store & store, Source & from, Phantom<StorePath> _);
void write(const Store & store, Sink & out, const StorePath & storePath); void write(const Store & store, Sink & out, const StorePath & storePath);
}
StorePathCAMap readStorePathCAMap(const Store & store, Source & from); StorePathCAMap readStorePathCAMap(const Store & store, Source & from);
void writeStorePathCAMap(const Store & store, Sink & out, const StorePathCAMap & paths); void writeStorePathCAMap(const Store & store, Sink & out, const StorePathCAMap & paths);