#include "serialise.hh" #include "path-with-outputs.hh" #include "store-api.hh" #include "common-protocol.hh" #include "common-protocol-impl.hh" #include "derivations.hh" #include namespace nix { /* protocol-agnostic definitions */ std::string CommonProto::Serialise::read(const Store & store, CommonProto::ReadConn conn) { return readString(conn.from); } WireFormatGenerator CommonProto::Serialise::write(const Store & store, CommonProto::WriteConn conn, const std::string & str) { co_yield str; } StorePath CommonProto::Serialise::read(const Store & store, CommonProto::ReadConn conn) { return store.parseStorePath(readString(conn.from)); } WireFormatGenerator CommonProto::Serialise::write(const Store & store, CommonProto::WriteConn conn, const StorePath & storePath) { co_yield store.printStorePath(storePath); } ContentAddress CommonProto::Serialise::read(const Store & store, CommonProto::ReadConn conn) { return ContentAddress::parse(readString(conn.from)); } WireFormatGenerator CommonProto::Serialise::write(const Store & store, CommonProto::WriteConn conn, const ContentAddress & ca) { co_yield renderContentAddress(ca); } Realisation CommonProto::Serialise::read(const Store & store, CommonProto::ReadConn conn) { std::string rawInput = readString(conn.from); return Realisation::fromJSON( nlohmann::json::parse(rawInput), "remote-protocol" ); } WireFormatGenerator CommonProto::Serialise::write(const Store & store, CommonProto::WriteConn conn, const Realisation & realisation) { co_yield realisation.toJSON().dump(); } DrvOutput CommonProto::Serialise::read(const Store & store, CommonProto::ReadConn conn) { return DrvOutput::parse(readString(conn.from)); } WireFormatGenerator CommonProto::Serialise::write(const Store & store, CommonProto::WriteConn conn, const DrvOutput & drvOutput) { co_yield drvOutput.to_string(); } std::optional CommonProto::Serialise>::read(const Store & store, CommonProto::ReadConn conn) { auto s = readString(conn.from); return s == "" ? std::optional {} : store.parseStorePath(s); } WireFormatGenerator CommonProto::Serialise>::write(const Store & store, CommonProto::WriteConn conn, const std::optional & storePathOpt) { return [](std::string s) -> WireFormatGenerator { co_yield s; }(storePathOpt ? store.printStorePath(*storePathOpt) : ""); } std::optional CommonProto::Serialise>::read(const Store & store, CommonProto::ReadConn conn) { return ContentAddress::parseOpt(readString(conn.from)); } WireFormatGenerator CommonProto::Serialise>::write(const Store & store, CommonProto::WriteConn conn, const std::optional & caOpt) { return [](std::string s) -> WireFormatGenerator { co_yield s; }(caOpt ? renderContentAddress(*caOpt) : ""); } }