[Serialization] Make JsonSerializationContext FilesystemAppComponent-compatible
This commit is contained in:
@@ -36,11 +36,20 @@ namespace Nz
|
||||
|
||||
bool JsonSerializationContext::Load(const std::filesystem::path& path)
|
||||
{
|
||||
std::ifstream file(path);
|
||||
if (!file || !file.is_open())
|
||||
Nz::File file(path, Nz::OpenMode::Read);
|
||||
return Load(file);
|
||||
}
|
||||
|
||||
bool JsonSerializationContext::Load(Stream& stream)
|
||||
{
|
||||
if (!stream.IsReadable())
|
||||
return false;
|
||||
|
||||
m_impl->json = nlohmann::json::parse(file);
|
||||
auto size = stream.GetSize();
|
||||
std::vector<char> content(size);
|
||||
stream.Read(content.data(), content.size());
|
||||
|
||||
m_impl->json = nlohmann::json::parse(content.begin(), content.end());
|
||||
m_impl->stack.push(&m_impl->json);
|
||||
return true;
|
||||
}
|
||||
@@ -129,4 +138,12 @@ namespace Nz
|
||||
*value = m_impl->Top()[name].get<std::string>();
|
||||
return true;
|
||||
}
|
||||
|
||||
std::shared_ptr<JsonSerializationContext> JsonSerializationContext::LoadFromStream(Stream& stream, const JsonSerializationContext::Params&)
|
||||
{
|
||||
std::shared_ptr<JsonSerializationContext> context = std::make_shared<JsonSerializationContext>();
|
||||
if (context->Load(stream))
|
||||
return context;
|
||||
return {};
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user