matjson 2/?
Some checks are pending
Build Binaries / Build Windows (push) Waiting to run
Build Binaries / Build macOS (push) Waiting to run
Build Binaries / Build Android (64-bit) (push) Waiting to run
Build Binaries / Build Android (32-bit) (push) Waiting to run
Build Binaries / Publish (push) Blocked by required conditions

This commit is contained in:
altalk23 2024-11-09 09:14:00 +03:00
parent f2ec5fa3f8
commit 108721dd3f
3 changed files with 13 additions and 16 deletions

View file

@ -121,18 +121,16 @@ namespace geode {
* @param name The argument name * @param name The argument name
*/ */
template <class T> template <class T>
Result<T> parseLaunchArgument(std::string_view const name) const { Result<T, std::string_view> parseLaunchArgument(std::string_view const name) const {
auto str = this->getLaunchArgument(name); auto str = this->getLaunchArgument(name);
if (!str.has_value()) { if (!str.has_value()) {
return std::nullopt; return Err("Launch argument '{}' not found", name);
} }
std::string parseError; auto jsonOpt = matjson::Value::parse(str.value());
auto jsonOpt = matjson::parse(str.value(), parseError); if (jsonOpt.isErr()) {
if (!jsonOpt.has_value()) { return Err("Parsing launch argument '{}' failed: {}", name, jsonOpt.unwrapErr());
log::debug("Parsing launch argument '{}' failed: {}", name, parseError);
return std::nullopt;
} }
auto value = jsonOpt.value(); auto value = jsonOpt.unwrap();
return value.template as<T>(); return value.template as<T>();
} }

View file

@ -265,7 +265,7 @@ namespace geode {
}); res.isOk()) { }); res.isOk()) {
return res.unwrap(); return res.unwrap();
} }
saved[key] = defaultValue; saved[key] = matjson::Value(defaultValue);
return defaultValue; return defaultValue;
} }

View file

@ -33,19 +33,18 @@ ipc::IPCFilter::IPCFilter(std::string const& modID, std::string const& messageID
matjson::Value ipc::processRaw(void* rawHandle, std::string const& buffer) { matjson::Value ipc::processRaw(void* rawHandle, std::string const& buffer) {
matjson::Value reply; matjson::Value reply;
std::string error; auto res = matjson::Value::parse(buffer);
auto res = matjson::parse(buffer, error);
if (error.size() > 0) { if (error.size() > 0) {
log::warn("Received IPC message that isn't valid JSON: {}", error); log::warn("Received IPC message that isn't valid JSON: {}", res.unwrapErr());
return reply; return reply;
} }
matjson::Value json = res.value(); matjson::Value json = res.unwrap();
if (!json.contains("mod") || !json["mod"].is_string()) { if (!json.contains("mod") || !json["mod"].isString()) {
log::warn("Received IPC message without 'mod' field"); log::warn("Received IPC message without 'mod' field");
return reply; return reply;
} }
if (!json.contains("message") || !json["message"].is_string()) { if (!json.contains("message") || !json["message"].isString()) {
log::warn("Received IPC message without 'message' field"); log::warn("Received IPC message without 'message' field");
return reply; return reply;
} }
@ -55,6 +54,6 @@ matjson::Value ipc::processRaw(void* rawHandle, std::string const& buffer) {
} }
// log::debug("Posting IPC event"); // log::debug("Posting IPC event");
// ! warning: if the event system is ever made asynchronous this will break! // ! warning: if the event system is ever made asynchronous this will break!
IPCEvent(rawHandle, json["mod"].as_string(), json["message"].as_string(), data, reply).post(); IPCEvent(rawHandle, json["mod"].asString().unwrap(), json["message"].asString().unwrap(), data, reply).post();
return reply; return reply;
} }