Skip to content

Commit b57b604

Browse files
committed
top level JSON2.write only, Neo4jDFG broken
1 parent 11f6b2d commit b57b604

File tree

3 files changed

+34
-16
lines changed

3 files changed

+34
-16
lines changed

src/entities/DFGFactor.jl

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,6 @@ mutable struct GenericFunctionNodeData{T<:Union{<:AbstractPackedFactor, <:Abstra
4646
nullhypo::Float64
4747
solveInProgress::Int
4848
inflation::Float64
49-
# inner constructor needed for dual use
50-
# GenericFunctionNodeData{T}(x1::Bool,x2::Bool,x3,x4::T,args...) where T = new{T}(x1,x2,x3,x4,args...)
51-
# TODO deprecate all these inner constructors at end of DFG v0.9.x (was added for GFND.nullhypo::Float64 breaking change)
52-
# GenericFunctionNodeData{T}(el,po,ed,fn,mu::Vector{<:Real},ce::Vector{Int},so::Int) where T =
53-
# new{T}(el,po,ed,fn,mu,ce,0.0,so)
54-
# GenericFunctionNodeData{T}(el,po,ed,fn,mu::Vector{<:Real},ce::Vector{Int},nu::Real,so::Int,infl::Real) where T = new{T}(el,po,ed,fn,mu,ce,nu,so,infl)
5549
end
5650

5751
## Constructors

src/services/Serialization.jl

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -298,10 +298,11 @@ function _packSolverData(
298298
#
299299
packtype = convertPackedType(fnctype)
300300
try
301-
packed = convert( PackedFunctionNodeData{packtype}, getSolverData(f) )
302-
packedJson = JSON2.write(packed)
301+
packedJson = convert( PackedFunctionNodeData{packtype}, getSolverData(f) )
302+
# packedJson = JSON2.write(packed) # NOTE SINGLE TOP LEVEL JSON.write ONLY
303303
if base64Encode
304304
# 833
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,27 @@ function decodePackedType(dfg::AbstractDFG, varOrder::AbstractVector{Symbol}, ::
347348
return factordata
348349
end
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+
@show P
358+
GenericFunctionNodeData{P}(
359+
nt.eliminated,
360+
nt.potentialused,
361+
nt.edgeIDs,
362+
convert(P,nt.fnc),
363+
nt.multihypo,
364+
nt.certainhypo,
365+
nt.nullhypo,
366+
nt.solveInProgress,
367+
nt.inflation,
368+
)
369+
end
370+
371+
350372
# Returns `::DFGFactor`
351373
function unpackFactor(dfg::G, packedProps::Dict{String, Any}) where G <: AbstractDFG
352374
# Version checking.
@@ -383,8 +405,10 @@ function unpackFactor(dfg::G, packedProps::Dict{String, Any}) where G <: Abstrac
383405
Symbol.(packedProps["_variableOrderSymbols"])
384406
end
385407

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

test/testBlocks.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ struct TestAbstractPrior <: AbstractPrior end
3434
struct TestAbstractRelativeFactor <: AbstractRelativeRoots end
3535
struct TestAbstractRelativeFactorMinimize <: AbstractRelativeMinimize end
3636

37-
struct PackedTestFunctorInferenceType1 <: AbstractPackedFactor
38-
s::String
37+
Base.@kwdef struct PackedTestFunctorInferenceType1 <: AbstractPackedFactor
38+
s::String = ""
3939
end
40-
PackedTestFunctorInferenceType1() = PackedTestFunctorInferenceType1("")
40+
# PackedTestFunctorInferenceType1() = PackedTestFunctorInferenceType1("")
4141

4242
function Base.convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1)
4343
# @info "convert(::Type{PackedTestFunctorInferenceType1}, d::TestFunctorInferenceType1)"
@@ -55,10 +55,10 @@ function Base.convert(::Type{TestFunctorInferenceType1}, d::PackedTestFunctorInf
5555
end
5656

5757

58-
struct PackedTestAbstractPrior <: AbstractPackedFactor
58+
Base.@kwdef struct PackedTestAbstractPrior <: AbstractPackedFactor
5959
s::String
6060
end
61-
PackedTestAbstractPrior() = PackedTestAbstractPrior("")
61+
# PackedTestAbstractPrior() = PackedTestAbstractPrior("")
6262

6363
function Base.convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior)
6464
# @info "convert(::Type{PackedTestAbstractPrior}, d::TestAbstractPrior)"

0 commit comments

Comments
 (0)