Skip to content

Commit 7708ecd

Browse files
authored
new function stringVariableType (#1149)
1 parent 89b1892 commit 7708ecd

File tree

2 files changed

+28
-13
lines changed

2 files changed

+28
-13
lines changed

src/Deprecated.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -430,6 +430,16 @@ function getFactorOperationalMemoryType(dfg::AbstractDFG)
430430
return getFactorOperationalMemoryType(getSolverParams(dfg))
431431
end
432432

433+
function typeModuleName(variableType::InferenceVariable)
434+
Base.depwarn("typeModuleName is obsolete", :typeModuleName)
435+
io = IOBuffer()
436+
ioc = IOContext(io, :module => DistributedFactorGraphs)
437+
show(ioc, typeof(variableType))
438+
return String(take!(io))
439+
end
440+
441+
typeModuleName(varT::Type{<:InferenceVariable}) = typeModuleName(varT())
442+
433443
## ================================================================================
434444
## Deprecated in v0.25
435445
##=================================================================================

src/services/Serialization.jl

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,18 +28,23 @@ function _versionCheck(node::Union{<:VariableDFG, <:FactorDFG})
2828
end
2929
end
3030

31-
## Utility functions for ZonedDateTime
32-
33-
# variableType module.type string functions
34-
function typeModuleName(variableType::InferenceVariable)
35-
io = IOBuffer()
36-
ioc = IOContext(io, :module => DistributedFactorGraphs)
37-
show(ioc, typeof(variableType))
38-
return String(take!(io))
31+
function stringVariableType(varT::InferenceVariable)
32+
T = typeof(varT)
33+
#FIXME maybe don't use .parameters
34+
Tparams = T.parameters
35+
if length(Tparams) == 0
36+
return string(parentmodule(T), ".", nameof(T))
37+
elseif length(Tparams) == 1 && Tparams[1] isa Integer
38+
return string(parentmodule(T), ".", nameof(T), "{", join(Tparams, ","), "}")
39+
else
40+
throw(
41+
SerializationError(
42+
"Serializing Variable State type only supports 1 integer parameter, got '$(T)'.",
43+
),
44+
)
45+
end
3946
end
4047

41-
typeModuleName(varT::Type{<:InferenceVariable}) = typeModuleName(varT())
42-
4348
function parseVariableType(_typeString::AbstractString)
4449
m = match(r"{(\d+)}", _typeString)
4550
if !isnothing(m) #parameters in type
@@ -55,7 +60,7 @@ function parseVariableType(_typeString::AbstractString)
5560
subtype = get(all_subtypes, Symbol(split(typeString, ".")[end]), nothing)
5661

5762
if isnothing(subtype)
58-
error("Unable to deserialize type $(_typeString), not found")
63+
throw(SerializationError("Unable to deserialize type $(_typeString), not found"))
5964
return nothing
6065
end
6166

@@ -133,7 +138,7 @@ function packVariableState(d::VariableState{T}) where {T <: InferenceVariable}
133138
d.eliminated,
134139
d.BayesNetVertID,
135140
d.separator,
136-
typeModuleName(getVariableType(d)),
141+
stringVariableType(getVariableType(d)),
137142
d.initialized,
138143
d.infoPerCoord,
139144
d.ismargin,
@@ -215,7 +220,7 @@ function packVariable(
215220
solverData = packVariableState.(collect(values(v.solverDataDict))),
216221
metadata = base64encode(JSON3.write(v.smallData)),
217222
solvable = v.solvable,
218-
variableType = DFG.typeModuleName(DFG.getVariableType(v)),
223+
variableType = stringVariableType(DFG.getVariableType(v)),
219224
blobEntries = collect(values(v.dataDict)),
220225
_version = string(DFG._getDFGVersion()),
221226
)

0 commit comments

Comments
 (0)