helics 3.7.0
Loading...
Searching...
No Matches
JsonGeneration.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-License-Identifier: BSD-3-Clause
6*/
7#pragma once
8
9#include "nlohmann/json.hpp"
10
11#include <fmt/format.h>
12#include <string>
13
14namespace helics {
15
16inline std::string generateJsonQuotedString(const std::string& string)
17{
18 nlohmann::json V = string;
19 return V.dump(-1, ' ', true, nlohmann::json::error_handler_t::hex);
20}
21
22enum class JsonErrorCodes : std::int32_t {
23 BAD_REQUEST = 400,
24 FORBIDDEN = 403,
25 NOT_FOUND = 404,
26 METHOD_NOT_ALLOWED = 405,
27 TIMEOUT = 408,
28 DISCONNECTED = 410,
29 INTERNAL_ERROR = 500,
30 NOT_IMPLEMENTED = 501,
31 BAD_GATEWAY = 502,
32 SERVICE_UNAVAILABLE = 503,
33 GATEWAY_TIMEOUT = 504
34};
36inline std::string generateJsonErrorResponse(JsonErrorCodes code, const std::string& message)
37{
38 return fmt::format("{{\n \"error\":{{\n \"code\":{},\n \"message\":{}\n }}\n}}",
39 static_cast<std::int32_t>(code),
40 generateJsonQuotedString(message));
41}
42
43} // namespace helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
std::string generateJsonErrorResponse(JsonErrorCodes code, const std::string &message)
Definition JsonGeneration.hpp:36