7#include <nlohmann/json.hpp>
22 if (serialized ==
nullptr) {
25 const auto json = nlohmann::json::parse(*serialized);
26 if (!
json.is_object() || (
json.contains(
"expected_performance") && !
json[
"expected_performance"].is_object()) ||
27 (!
json.contains(
"expected_performance") && !
json.contains(
"vector_distance"))) {
28 throw std::runtime_error(
"Invalid RPC optimization element metadata");
31 json.contains(
"expected_performance") ? std::optional<nlohmann::json>(
json[
"expected_performance"])
35 if (
json.contains(
"vector_distance")) {
36 if (!
json[
"vector_distance"].is_number() || !std::isfinite(
json[
"vector_distance"].get<double>())) {
37 throw std::runtime_error(
"Invalid RPC vector distance element metadata");
46 std::optional<nlohmann::json> expected_performance,
47 std::optional<double> vector_distance = std::nullopt
49 if (!expected_performance.has_value() && !vector_distance.has_value()) {
53 if ((expected_performance.has_value() && !expected_performance->is_object()) ||
54 (vector_distance.has_value() && !std::isfinite(vector_distance.value()))) {
55 throw std::invalid_argument(
"RPC expected performance must be an object and vector distance finite");
57 nlohmann::json
json = nlohmann::json::object();
58 if (expected_performance.has_value()) {
59 json[
"expected_performance"] = expected_performance.value();
61 if (vector_distance.has_value()) {
62 json[
"vector_distance"] = vector_distance.value();
void remove_metadata(const std::string &key)
const std::string * metadata_if_exists(const std::string &key) const
void add_metadata(const std::string &key, const std::string &value)
nlohmann::json json
Definition interstate_edge.h:14