mirror of
https://github.com/NixOS/nix.git
synced 2025-11-12 21:46:01 +01:00
For example, instead of doing
#include "nix/store-config.hh"
#include "nix/derived-path.hh"
Now do
#include "nix/store/config.hh"
#include "nix/store/derived-path.hh"
This was originally planned in the issue, and also recent requested by
Eelco.
Most of the change is purely mechanical. There is just one small
additional issue. See how, in the example above, we took this
opportunity to also turn `<comp>-config.hh` into `<comp>/config.hh`.
Well, there was already a `nix/util/config.{cc,hh}`. Even though there
is not a public configuration header for libutil (which also would be
called `nix/util/config.{cc,hh}`) that's still confusing, To avoid any
such confusion, we renamed that to `nix/util/configuration.{cc,hh}`.
Finally, note that the libflake headers already did this, so we didn't
need to do anything to them. We wouldn't want to mistakenly get
`nix/flake/flake/flake.hh`!
Progress on #7876
(cherry picked from commit cc24766fa6)
97 lines
3.1 KiB
C++
97 lines
3.1 KiB
C++
#include "nix/util/serialise.hh"
|
|
#include "nix/store/path-with-outputs.hh"
|
|
#include "nix/store/store-api.hh"
|
|
#include "nix/store/build-result.hh"
|
|
#include "nix/store/common-protocol.hh"
|
|
#include "nix/store/common-protocol-impl.hh"
|
|
#include "nix/util/archive.hh"
|
|
#include "nix/store/derivations.hh"
|
|
|
|
#include <nlohmann/json.hpp>
|
|
|
|
namespace nix {
|
|
|
|
/* protocol-agnostic definitions */
|
|
|
|
std::string CommonProto::Serialise<std::string>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
|
|
{
|
|
return readString(conn.from);
|
|
}
|
|
|
|
void CommonProto::Serialise<std::string>::write(const StoreDirConfig & store, CommonProto::WriteConn conn, const std::string & str)
|
|
{
|
|
conn.to << str;
|
|
}
|
|
|
|
|
|
StorePath CommonProto::Serialise<StorePath>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
|
|
{
|
|
return store.parseStorePath(readString(conn.from));
|
|
}
|
|
|
|
void CommonProto::Serialise<StorePath>::write(const StoreDirConfig & store, CommonProto::WriteConn conn, const StorePath & storePath)
|
|
{
|
|
conn.to << store.printStorePath(storePath);
|
|
}
|
|
|
|
|
|
ContentAddress CommonProto::Serialise<ContentAddress>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
|
|
{
|
|
return ContentAddress::parse(readString(conn.from));
|
|
}
|
|
|
|
void CommonProto::Serialise<ContentAddress>::write(const StoreDirConfig & store, CommonProto::WriteConn conn, const ContentAddress & ca)
|
|
{
|
|
conn.to << renderContentAddress(ca);
|
|
}
|
|
|
|
|
|
Realisation CommonProto::Serialise<Realisation>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
|
|
{
|
|
std::string rawInput = readString(conn.from);
|
|
return Realisation::fromJSON(
|
|
nlohmann::json::parse(rawInput),
|
|
"remote-protocol"
|
|
);
|
|
}
|
|
|
|
void CommonProto::Serialise<Realisation>::write(const StoreDirConfig & store, CommonProto::WriteConn conn, const Realisation & realisation)
|
|
{
|
|
conn.to << realisation.toJSON().dump();
|
|
}
|
|
|
|
|
|
DrvOutput CommonProto::Serialise<DrvOutput>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
|
|
{
|
|
return DrvOutput::parse(readString(conn.from));
|
|
}
|
|
|
|
void CommonProto::Serialise<DrvOutput>::write(const StoreDirConfig & store, CommonProto::WriteConn conn, const DrvOutput & drvOutput)
|
|
{
|
|
conn.to << drvOutput.to_string();
|
|
}
|
|
|
|
|
|
std::optional<StorePath> CommonProto::Serialise<std::optional<StorePath>>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
|
|
{
|
|
auto s = readString(conn.from);
|
|
return s == "" ? std::optional<StorePath> {} : store.parseStorePath(s);
|
|
}
|
|
|
|
void CommonProto::Serialise<std::optional<StorePath>>::write(const StoreDirConfig & store, CommonProto::WriteConn conn, const std::optional<StorePath> & storePathOpt)
|
|
{
|
|
conn.to << (storePathOpt ? store.printStorePath(*storePathOpt) : "");
|
|
}
|
|
|
|
|
|
std::optional<ContentAddress> CommonProto::Serialise<std::optional<ContentAddress>>::read(const StoreDirConfig & store, CommonProto::ReadConn conn)
|
|
{
|
|
return ContentAddress::parseOpt(readString(conn.from));
|
|
}
|
|
|
|
void CommonProto::Serialise<std::optional<ContentAddress>>::write(const StoreDirConfig & store, CommonProto::WriteConn conn, const std::optional<ContentAddress> & caOpt)
|
|
{
|
|
conn.to << (caOpt ? renderContentAddress(*caOpt) : "");
|
|
}
|
|
|
|
}
|