Skip to content

Commit

Permalink
Add conversion logic for subsystems and attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielKS committed Feb 16, 2024
1 parent 323deb9 commit e6d3892
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1549,6 +1549,10 @@ function IS.deserialize(
JSON3.read(io, Dict)
end

if raw["data_format_version"] != DATA_FORMAT_VERSION
pre_read_conversion!(raw)
end

# These file paths are relative to the system file.
directory = dirname(filename)
for file_key in ("time_series_storage_file", "validation_descriptor_file")
Expand Down
10 changes: 10 additions & 0 deletions src/data_format_conversions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ function _convert_data!(
return
end

# Conversions to occur immediately after the data is loaded from disk
function pre_read_conversion!(raw)
if VersionNumber(raw["data_format_version"]) < v"4.0.0"
haskey(raw["data"], "subsystems") || (raw["data"]["subsystems"] = Dict{String, Any}())
haskey(raw["data"], "attributes") || (raw["data"]["attributes"] = Any[])
end
end

# Conversions to occur before deserialize_components!
function pre_deserialize_conversion!(raw, sys::System)
old = raw["data_format_version"]
if old == DATA_FORMAT_VERSION
Expand All @@ -133,6 +142,7 @@ function pre_deserialize_conversion!(raw, sys::System)
end
end

# Conversions to occur at the end of deserialization
function post_deserialize_conversion!(sys::System, raw)
old = raw["data_format_version"]
if old == "1.0.0"
Expand Down

0 comments on commit e6d3892

Please sign in to comment.