35
35
typeModuleName (varT:: Type{<:InferenceVariable} ) = typeModuleName (varT ())
36
36
37
37
"""
38
- $(SIGNATURES)
38
+ $(SIGNATURES)
39
39
Get a type from the serialization module.
40
40
"""
41
41
function getTypeFromSerializationModule (_typeString:: AbstractString )
@@ -113,7 +113,7 @@ function unpackVariableNodeData(d::PackedVariableNodeData)
113
113
vals = Vector {getPointType(T)} (undef, length (val_))
114
114
# vals = getPoint.(T, val_)
115
115
for (i,v) in enumerate (val_)
116
- vals[i] = getPoint (T, v)
116
+ vals[i] = getPoint (T, v)
117
117
end
118
118
119
119
r4 = d. dimbw
@@ -191,6 +191,7 @@ function unpackVariable(variable::PackedVariable; skipVersionCheck::Bool=false)
191
191
solvable= variable. solvable )
192
192
end
193
193
194
+
194
195
# #==============================================================================
195
196
# # Factor Packing and unpacking
196
197
# #==============================================================================
@@ -251,16 +252,20 @@ end
251
252
function fncStringToData (packtype:: Type{<:AbstractPackedFactor} , data:: String )
252
253
253
254
# Convert string to Named Tuples for kwargs
254
- # packed = JSON3.read(data, GenericFunctionNodeData{packtype})
255
- fncData = JSON3. read (data, Dict{String,Any})
255
+ # packed_ = JSON3.read(data, GenericFunctionNodeData{packtype})
256
+ fncData = JSON3. read (data) # , NamedTuple) # Dict{String,Any})
257
+
256
258
257
259
# data isa AbstractString ? JSON2.read(data) : data
260
+ # JSON3.generate_type(packed.fnc)
261
+ # JSON3.generate_type(fncData["fnc"])
258
262
259
263
# TODO use kwdef constructors instead,
260
- @show fncData[" fnc" ]
261
- packT = JSON3. read (JSON3. write (fncData[" fnc" ]), packtype)
262
- # nt = NamedTuple{}
263
- # packtype(;fncData["fnc"]...)
264
+ # @info "user factor" fncData["fnc"]
265
+ restring = JSON3. write (fncData[" fnc" ])
266
+ # @show restring
267
+ # packT = JSON3.read(restring, packtype)
268
+ packT = packtype (;JSON2. read (restring)... )
264
269
265
270
packed = GenericFunctionNodeData {packtype} (
266
271
fncData[" eliminated" ],
@@ -297,82 +302,47 @@ function fncStringToData(fncType::String, data::T) where {T <: AbstractPackedFac
297
302
end
298
303
end
299
304
function fncStringToData (fncType:: String , data:: Union{String, <:NamedTuple} )
305
+ # FIXME , should rather just store the data as `PackedFactorX` rather than hard code the type change here???
300
306
packtype = DFG. getTypeFromSerializationModule (" Packed" * fncType)
301
307
fncStringToData (packtype, data)
302
308
end
303
309
304
310
305
- # Returns `::DFGFactor`
306
311
function unpackFactor (
307
- dfg:: G ,
308
- packedFactor :: PackedFactor ;
312
+ dfg:: AbstractDFG ,
313
+ factor :: PackedFactor ;
309
314
skipVersionCheck:: Bool = false
310
- ) where G <: AbstractDFG
311
- # Version checking.
312
- ! skipVersionCheck && _versionCheck (packedFactor)
313
-
314
- # id = if haskey(packedProps, "id") && packedProps["id"] !== nothing
315
- # UUID(packedProps["id"]) else nothing end
316
- # label = packedProps["label"]
317
-
318
- # # various formats in which the timestamp might be stored
319
- # packedProps["timestamp"] = getStandardZDTString(packedProps["timestamp"])
320
- # timestamp = ZonedDateTime(packedProps["timestamp"])
321
- # nstime = Nanosecond(get(packedProps, "nstime", 0))
322
-
323
- # Get the stored tags and variable order
324
- # @assert !(packedProps["tags"] isa String) "unpackFactor expecting JSON only data, packed `tags` should be a vector of strings (not a single string of elements)."
325
- # @assert !(packedProps["_variableOrderSymbols"] isa String) "unpackFactor expecting JSON only data, packed `_variableOrderSymbols` should be a vector of strings (not a single string of elements)."
326
- # tags = Symbol.(packedProps["tags"])
327
- # _variableOrderSymbols = Symbol.(packedProps["_variableOrderSymbols"])
328
-
329
- data = packedFactor. data
330
- # if(data isa AbstractString)
331
- # data = JSON3.read(data, NamedTuple) # was a JSON2
332
- # end
333
- datatype = packedFactor. fnctype
334
- @debug " DECODING factor type = '$(datatype) ' for factor '$label '"
335
- # packtype = getTypeFromSerializationModule("Packed"*datatype)
336
-
337
- # FIXME type instability from nothing to T
338
- packed = nothing
339
- fullFactorData = nothing
315
+ )
316
+ #
317
+ @debug " DECODING factor type = '$(factor. fnctype) ' for factor '$(factor. label) '"
318
+ ! skipVersionCheck && _versionCheck (factor)
340
319
320
+ fullFactorData = nothing
341
321
try
342
- packed = fncStringToData (datatype, data) # convert(GenericFunctionNodeData{packtype}, data)
322
+ packedFnc = fncStringToData (factor . fnctype, factor . data)
343
323
decodeType = getFactorOperationalMemoryType (dfg)
344
- fullFactorData = decodePackedType (dfg, packedFactor . _variableOrderSymbols, decodeType, packed )
324
+ fullFactorData = decodePackedType (dfg, factor . _variableOrderSymbols, decodeType, packedFnc )
345
325
catch ex
346
326
io = IOBuffer ()
347
327
showerror (io, ex, catch_backtrace ())
348
328
err = String (take! (io))
349
- msg = " Error while unpacking '$(packedFactor . label) ' as '$datatype ', please check the unpacking/packing converters for this factor - \r\n $err "
329
+ msg = " Error while unpacking '$(factor . label) ' as '$(factor . fnctype) ', please check the unpacking/packing converters for this factor - \r\n $err "
350
330
error (msg)
351
- end
352
-
353
- # solvable = packedProps["solvable"]
354
-
355
- smallData = JSON3. read (base64decode (packedFactor. metadata), Dict{Symbol, DFG. SmallDataTypes})
356
- # Rebuild DFGFactor
357
- # TODO use constuctor to create factor
358
- factor = DFGFactor ( packedFactor. label,
359
- packedFactor. timestamp,
360
- Nanosecond (packedFactor. nstime),
361
- Set (packedFactor. tags),
362
- fullFactorData,
363
- packedFactor. solvable,
364
- Tuple (packedFactor. _variableOrderSymbols);
365
- packedFactor. id,
366
- smallData)
367
- #
368
-
369
- # Note, once inserted, you still need to call rebuildFactorMetadata!
370
- return factor
331
+ end
332
+
333
+ metadata = JSON3. read (base64decode (factor. metadata), Dict{Symbol, DFG. SmallDataTypes})
334
+
335
+ return DFGFactor (
336
+ factor. label,
337
+ factor. timestamp,
338
+ Nanosecond (factor. nstime),
339
+ Set (factor. tags),
340
+ fullFactorData,
341
+ factor. solvable,
342
+ Tuple (factor. _variableOrderSymbols),
343
+ id= factor. id,
344
+ smallData = metadata
345
+ )
371
346
end
372
347
373
-
374
- # #==============================================================================
375
- # # Serialization
376
- # #==============================================================================
377
-
378
-
348
+ #
0 commit comments