diff --git a/plugins/builtin/source/content/pl_builtin_types.cpp b/plugins/builtin/source/content/pl_builtin_types.cpp index e0e011cc8..13176d0e1 100644 --- a/plugins/builtin/source/content/pl_builtin_types.cpp +++ b/plugins/builtin/source/content/pl_builtin_types.cpp @@ -197,12 +197,12 @@ namespace hex::plugin::builtin { } - std::unique_ptr jsonToPattern(pl::core::Evaluator *evaluator, const nlohmann::json &json) { + std::unique_ptr jsonToPattern(pl::core::Evaluator *evaluator, auto function) { auto object = std::make_unique(evaluator, 0, 0, 0); std::vector> patterns; try { - jsonToPattern(evaluator, json, patterns); + jsonToPattern(evaluator, function(), patterns); object->setEntries(patterns); return object; @@ -224,7 +224,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addType(nsHexDec, "Json", FunctionParameterCount::exactly(1), [](Evaluator *evaluator, auto params) -> std::unique_ptr { auto data = params[0].toBytes(); - auto result = jsonToPattern(evaluator, nlohmann::json::parse(data)); + auto result = jsonToPattern(evaluator, [&] { return nlohmann::json::parse(data); }); result->setSize(data.size()); return result; }); @@ -233,7 +233,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addType(nsHexDec, "Bson", FunctionParameterCount::exactly(1), [](Evaluator *evaluator, auto params) -> std::unique_ptr { auto data = params[0].toBytes(); - auto result = jsonToPattern(evaluator, nlohmann::json::from_bson(data)); + auto result = jsonToPattern(evaluator, [&] { return nlohmann::json::from_bson(data); }); result->setSize(data.size()); return result; }); @@ -242,7 +242,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addType(nsHexDec, "Cbor", FunctionParameterCount::exactly(1), [](Evaluator *evaluator, auto params) -> std::unique_ptr { auto data = params[0].toBytes(); - auto result = jsonToPattern(evaluator, nlohmann::json::from_cbor(data)); + auto result = jsonToPattern(evaluator, [&] { return nlohmann::json::from_cbor(data); }); result->setSize(data.size()); return result; }); @@ -251,7 +251,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addType(nsHexDec, "Bjdata", FunctionParameterCount::exactly(1), [](Evaluator *evaluator, auto params) -> std::unique_ptr { auto data = params[0].toBytes(); - auto result = jsonToPattern(evaluator, nlohmann::json::from_bjdata(data)); + auto result = jsonToPattern(evaluator, [&] { return nlohmann::json::from_bjdata(data); }); result->setSize(data.size()); return result; }); @@ -260,7 +260,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addType(nsHexDec, "Msgpack", FunctionParameterCount::exactly(1), [](Evaluator *evaluator, auto params) -> std::unique_ptr { auto data = params[0].toBytes(); - auto result = jsonToPattern(evaluator, nlohmann::json::from_msgpack(data)); + auto result = jsonToPattern(evaluator, [&] { return nlohmann::json::from_msgpack(data); }); result->setSize(data.size()); return result; }); @@ -269,7 +269,7 @@ namespace hex::plugin::builtin { ContentRegistry::PatternLanguage::addType(nsHexDec, "Ubjson", FunctionParameterCount::exactly(1), [](Evaluator *evaluator, auto params) -> std::unique_ptr { auto data = params[0].toBytes(); - auto result = jsonToPattern(evaluator, nlohmann::json::from_ubjson(data)); + auto result = jsonToPattern(evaluator, [&] { return nlohmann::json::from_ubjson(data); }); result->setSize(data.size()); return result; });