@@ -299,9 +299,10 @@ function _packSolverData(
299299 packtype = convertPackedType (fnctype)
300300 try
301301 packed = convert ( PackedFunctionNodeData{packtype}, getSolverData (f) )
302- packedJson = JSON2. write (packed)
302+ packedJson = packed # JSON2.write(packed) # NOTE SINGLE TOP LEVEL JSON.write ONLY
303303 if base64Encode
304- # 833
304+ # 833, 848, Neo4jDFG still using base64(JSON2.write(solverdata))...
305+ packedJson = JSON2. write (packed)
305306 packedJson = base64encode (packedJson)
306307 end
307308 return packedJson
@@ -321,13 +322,13 @@ function packFactor(dfg::AbstractDFG, f::DFGFactor)
321322 props[" label" ] = string (f. label)
322323 props[" timestamp" ] = Dates. format (f. timestamp, " yyyy-mm-ddTHH:MM:SS.ssszzz" )
323324 props[" nstime" ] = string (f. nstime. value)
324- props[" tags" ] = JSON2. write (f. tags)
325+ props[" tags" ] = String .(f . tags) # JSON2.write(f.tags)
325326 # Pack the node data
326327 fnctype = getSolverData (f). fnc. usrfnc!
327328 props[" data" ] = _packSolverData (f, fnctype)
328329 # Include the type
329330 props[" fnctype" ] = String (_getname (fnctype))
330- props[" _variableOrderSymbols" ] = JSON2. write (f. _variableOrderSymbols)
331+ props[" _variableOrderSymbols" ] = String .(f . _variableOrderSymbols) # JSON2.write(f._variableOrderSymbols)
331332 props[" solvable" ] = getSolvable (f)
332333 props[" _version" ] = _getDFGVersion ()
333334 return props
@@ -347,6 +348,26 @@ function decodePackedType(dfg::AbstractDFG, varOrder::AbstractVector{Symbol}, ::
347348 return factordata
348349end
349350
351+ function Base. convert (:: Type{PF} , nt:: NamedTuple ) where {PF <: AbstractPackedFactor }
352+ # Here we define a convention, must provide PackedType(;kw...) constructor, easiest is just use Base.@kwdef
353+ PF (;nt... )
354+ end
355+
356+ function Base. convert (:: Type{GenericFunctionNodeData{P}} , nt:: NamedTuple ) where P
357+ GenericFunctionNodeData {P} (
358+ nt. eliminated,
359+ nt. potentialused,
360+ nt. edgeIDs,
361+ convert (P,nt. fnc),
362+ nt. multihypo,
363+ nt. certainhypo,
364+ nt. nullhypo,
365+ nt. solveInProgress,
366+ nt. inflation,
367+ )
368+ end
369+
370+
350371# Returns `::DFGFactor`
351372function unpackFactor (dfg:: G , packedProps:: Dict{String, Any} ) where G <: AbstractDFG
352373 # Version checking.
@@ -367,6 +388,14 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any}) where G <: Abstrac
367388 tags = Vector {Symbol} ()
368389 end
369390 end
391+
392+ # Get the stored variable order
393+ _variableOrderSymbols = if packedProps[" _variableOrderSymbols" ] isa String
394+ JSON2. read (packedProps[" _variableOrderSymbols" ], Vector{Symbol})
395+ else
396+ Symbol .(packedProps[" _variableOrderSymbols" ])
397+ end
398+
370399 data = packedProps[" data" ]
371400 datatype = packedProps[" fnctype" ]
372401 @debug " DECODING factor type = '$(datatype) ' for factor '$label '"
@@ -376,15 +405,10 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any}) where G <: Abstrac
376405 packed = nothing
377406 fullFactorData = nothing
378407
379- # Get the stored variable order
380- _variableOrderSymbols = if packedProps[" _variableOrderSymbols" ] isa String
381- JSON2. read (packedProps[" _variableOrderSymbols" ], Vector{Symbol})
382- else
383- Symbol .(packedProps[" _variableOrderSymbols" ])
384- end
385-
408+ # @show packtype
409+ # @show data
386410 try
387- packed = JSON2. read (data, GenericFunctionNodeData{packtype})
411+ packed = convert (GenericFunctionNodeData{packtype}, data) # JSON2.read(data, GenericFunctionNodeData{packtype})
388412 decodeType = getFactorOperationalMemoryType (dfg)
389413 fullFactorData = decodePackedType (dfg, _variableOrderSymbols, decodeType, packed)
390414 catch ex
0 commit comments