@@ -28,18 +28,23 @@ function _versionCheck(node::Union{<:VariableDFG, <:FactorDFG})
28
28
end
29
29
end
30
30
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
39
46
end
40
47
41
- typeModuleName (varT:: Type{<:InferenceVariable} ) = typeModuleName (varT ())
42
-
43
48
function parseVariableType (_typeString:: AbstractString )
44
49
m = match (r" {(\d +)}" , _typeString)
45
50
if ! isnothing (m) # parameters in type
@@ -55,7 +60,7 @@ function parseVariableType(_typeString::AbstractString)
55
60
subtype = get (all_subtypes, Symbol (split (typeString, " ." )[end ]), nothing )
56
61
57
62
if isnothing (subtype)
58
- error ( " Unable to deserialize type $(_typeString) , not found" )
63
+ throw ( SerializationError ( " Unable to deserialize type $(_typeString) , not found" ) )
59
64
return nothing
60
65
end
61
66
@@ -133,7 +138,7 @@ function packVariableState(d::VariableState{T}) where {T <: InferenceVariable}
133
138
d. eliminated,
134
139
d. BayesNetVertID,
135
140
d. separator,
136
- typeModuleName (getVariableType (d)),
141
+ stringVariableType (getVariableType (d)),
137
142
d. initialized,
138
143
d. infoPerCoord,
139
144
d. ismargin,
@@ -215,7 +220,7 @@ function packVariable(
215
220
solverData = packVariableState .(collect (values (v. solverDataDict))),
216
221
metadata = base64encode (JSON3. write (v. smallData)),
217
222
solvable = v. solvable,
218
- variableType = DFG . typeModuleName (DFG. getVariableType (v)),
223
+ variableType = stringVariableType (DFG. getVariableType (v)),
219
224
blobEntries = collect (values (v. dataDict)),
220
225
_version = string (DFG. _getDFGVersion ()),
221
226
)
0 commit comments