3 #include "JsonHandler.h"
7 #include <rapidjson/document.h>
60 readJson(
const gsl::span<const std::byte>& data, T& handler) {
63 result.
value.emplace();
65 FinalJsonHandler finalHandler(result.
warnings);
66 handler.reset(&finalHandler, &result.
value.value());
68 JsonReader::internalRead(
75 if (!result.
errors.empty()) {
97 readJson(
const rapidjson::Value& jsonValue, T& handler) {
100 result.
value.emplace();
102 FinalJsonHandler finalHandler(result.
warnings);
103 handler.reset(&finalHandler, &result.
value.value());
105 JsonReader::internalRead(
112 if (!result.
errors.empty()) {
113 result.
value.reset();
122 FinalJsonHandler(std::vector<std::string>& warnings);
123 virtual void reportWarning(
124 const std::string& warning,
125 std::vector<std::string>&& context)
override;
126 void setInputStream(rapidjson::MemoryStream* pInputStream) noexcept;
129 std::vector<std::string>& _warnings;
130 rapidjson::MemoryStream* _pInputStream;
133 static void internalRead(
134 const gsl::span<const std::byte>& data,
135 IJsonHandler& handler,
136 FinalJsonHandler& finalHandler,
137 std::vector<std::string>& errors,
138 std::vector<std::string>& warnings);
140 static void internalRead(
141 const rapidjson::Value& jsonValue,
142 IJsonHandler& handler,
143 FinalJsonHandler& finalHandler,
144 std::vector<std::string>& errors,
145 std::vector<std::string>& warnings);
static ReadJsonResult< typename T::ValueType > readJson(const rapidjson::Value &jsonValue, T &handler)
Reads JSON from a rapidjson::Value into a statically-typed class.
static ReadJsonResult< typename T::ValueType > readJson(const gsl::span< const std::byte > &data, T &handler)
Reads JSON from a byte buffer into a statically-typed class.
Classes for reading JSON.
The result of Reader::readJson.
std::optional< T > value
The value read from the JSON, or std::nullopt on error.
std::vector< std::string > warnings
Warnings that occurred while reading.
std::vector< std::string > errors
Errors that occurred while reading.