2
2
# For all types that pack their type into their own structure (e.g. PPE)
3
3
const TYPEKEY = " _type"
4
4
5
- # Custom serialization
5
+ # # Custom serialization
6
6
using JSON
7
7
import JSON. show_json
8
8
import JSON. Writer: StructuralContext, JSONContext, show_json
9
9
import JSON. Serializations: CommonSerialization, StandardSerialization
10
10
JSON. show_json (io:: JSONContext , serialization:: CommonSerialization , uuid:: UUID ) = print (io. io, " \" $uuid \" " )
11
11
12
+ # # Version checking
13
+ function _getDFGVersion ()
14
+ # Looks like this is deprecated but there's no replacement function yet.
15
+ return string (Pkg. installed ()[" DistributedFactorGraphs" ])
16
+ end
17
+
18
+ function _versionCheck (props:: Dict{String, Any} )
19
+ if haskey (props, " _version" )
20
+ if props[" _version" ] != _getDFGVersion ()
21
+ @warn " This data was serialized using DFG $(props[" _version" ]) but you have $(_getDFGVersion ()) installed, there may be deserialization issues."
22
+ end
23
+ else
24
+ @warn " There isn't a version tag in this data so it older than v0.10, there may be deserialization issues."
25
+ end
26
+ end
12
27
13
28
# #==============================================================================
14
29
# # Variable Packing and unpacking
@@ -29,6 +44,7 @@ function packVariable(dfg::G, v::DFGVariable)::Dict{String, Any} where G <: Abst
29
44
props[" dataEntry" ] = JSON2. write (Dict (keys (v. dataDict) .=> map (bde -> JSON. json (bde), values (v. dataDict))))
30
45
31
46
props[" dataEntryType" ] = JSON2. write (Dict (keys (v. dataDict) .=> map (bde -> typeof (bde), values (v. dataDict))))
47
+ props[" _version" ] = _getDFGVersion ()
32
48
return props
33
49
end
34
50
@@ -72,6 +88,8 @@ function unpackVariable(dfg::G,
72
88
unpackSolverData:: Bool = true ,
73
89
unpackBigData:: Bool = true ):: DFGVariable where G <: AbstractDFG
74
90
@debug " Unpacking variable:\r\n $packedProps "
91
+ # Version checking.
92
+ _versionCheck (packedProps)
75
93
label = Symbol (packedProps[" label" ])
76
94
# Make sure that the timestamp is correctly formatted with subseconds
77
95
packedProps[" timestamp" ] = replace (packedProps[" timestamp" ], r" :(\d )(\d )(Z|z|\+ |-)" => s " :\1\2 .000\3 " )
@@ -203,7 +221,7 @@ function packFactor(dfg::G, f::DFGFactor)::Dict{String, Any} where G <: Abstract
203
221
props[" fnctype" ] = String (_getname (fnctype))
204
222
props[" _variableOrderSymbols" ] = JSON2. write (f. _variableOrderSymbols)
205
223
props[" solvable" ] = getSolvable (f)
206
-
224
+ props[ " _version " ] = _getDFGVersion ()
207
225
return props
208
226
end
209
227
219
237
220
238
221
239
function unpackFactor (dfg:: G , packedProps:: Dict{String, Any} ):: DFGFactor where G <: AbstractDFG
240
+ # Version checking.
241
+ _versionCheck (packedProps)
242
+
222
243
label = packedProps[" label" ]
223
244
# Make sure that the timestamp is correctly formatted with subseconds
224
245
packedProps[" timestamp" ] = replace (packedProps[" timestamp" ], r" :(\d )(\d )(Z|z|\+ |-)" => s " :\1\2 .000\3 " )
0 commit comments