1
1
Fork 0
mirror of https://github.com/NixOS/nix.git synced 2025-11-20 01:09:37 +01:00

JSON alongside binary proto serialization test data

This makes the proto serializer characterisation test data be
accompanied by JSON data.

This is arguably useful for a reasons:

- The JSON data is human-readable while the binary data is not, so it
  provides some indication of what the test data means beyond the C++
  literals.

- The JSON data is language-agnostic, and so can be used to quickly rig
  up tests for implementation in other languages, without having source
  code literals at all (just go back and forth between the JSON and the
  binary).

- Even though we have no concrete plans to place the binary protocol 1-1
  or with JSON, it is still nice to ensure that the JSON serializers and
  binary protocols have (near) equal coverage over data types, to help
  ensure we didn't forget a JSON (de)serializer.
This commit is contained in:
John Ericson 2025-10-30 14:47:05 -04:00
parent f5390e76e4
commit 204749270b
60 changed files with 1097 additions and 42 deletions

View file

@ -10,6 +10,7 @@
#include "nix/util/closure.hh"
#include "nix/store/filetransfer.hh"
#include "nix/util/strings.hh"
#include "nix/util/json-utils.hh"
#include <boost/unordered/unordered_flat_set.hpp>
@ -482,3 +483,19 @@ OutputPathMap resolveDerivedPath(Store & store, const DerivedPath::Built & bfd)
}
} // namespace nix
namespace nlohmann {
using namespace nix;
TrustedFlag adl_serializer<TrustedFlag>::from_json(const json & json)
{
return getBoolean(json) ? TrustedFlag::Trusted : TrustedFlag::NotTrusted;
}
void adl_serializer<TrustedFlag>::to_json(json & json, const TrustedFlag & trustedFlag)
{
json = static_cast<bool>(trustedFlag);
}
} // namespace nlohmann