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
6
+ using JSON
7
+ import JSON. show_json
8
+ import JSON. Writer: StructuralContext, JSONContext, show_json
9
+ import JSON. Serializations: CommonSerialization, StandardSerialization
10
+ JSON. show_json (io:: JSONContext , serialization:: CommonSerialization , uuid:: UUID ) = print (io. io, " \" $uuid \" " )
11
+
12
+
5
13
# #==============================================================================
6
14
# # Variable Packing and unpacking
7
15
# #==============================================================================
@@ -18,11 +26,46 @@ function packVariable(dfg::G, v::DFGVariable)::Dict{String, Any} where G <: Abst
18
26
props[" softtype" ] = string (typeof (getSofttype (v)))
19
27
# props["bigData"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> JSON2.write(bde), values(v.dataDict))))
20
28
# props["bigDataElemType"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> typeof(bde), values(v.dataDict))))
21
- props[" dataEntry" ] = JSON2. write (Dict (keys (v. dataDict) .=> map (bde -> JSON2. write (bde), values (v. dataDict))))
29
+ props[" dataEntry" ] = JSON2. write (Dict (keys (v. dataDict) .=> map (bde -> JSON. json (bde), values (v. dataDict))))
30
+
22
31
props[" dataEntryType" ] = JSON2. write (Dict (keys (v. dataDict) .=> map (bde -> typeof (bde), values (v. dataDict))))
23
32
return props
24
33
end
25
34
35
+ # Corrects any `::ZonedDateTime` fields of T in corresponding `interm::Dict` as `dateformat"yyyy-mm-ddTHH:MM:SS.ssszzz"`
36
+ function standardizeZDTString! (T, interm:: Dict )
37
+ @debug " About to look through types of" T
38
+ for (name, typ) in zip (fieldnames (T), T. types)
39
+ # @debug "name=$name"
40
+ # @debug "typ=$typ"
41
+ if typ <: ZonedDateTime
42
+ # Make sure that the timestamp is correctly formatted with subseconds
43
+ namestr = string (name)
44
+ @debug " must ensure SS.ssszzz on $name :: $typ -- $(interm[namestr]) "
45
+ # # FIXME copy #588, but doesnt work: https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/582#issuecomment-671884668
46
+ # # E.g.: interm[namestr] = replace(interm[namestr], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3") = "2020-08-11T04:05:59.82-04:00"
47
+ # @show interm[namestr] = replace(interm[namestr], r":(\d)(\d)(Z|z|\+|-)" => s":\1\2.000\3")
48
+ # @debug "after SS.ssszzz -- $(interm[namestr])"
49
+ # # DROP piece below once this cleaner copy #588 is working
50
+ supersec, subsec = split (interm[namestr], ' .' )
51
+ sss, zzz = split (subsec, ' -' )
52
+ # @debug "split time elements are $sss-$zzz"
53
+ # make sure milliseconds portion is precisely 3 characters long
54
+ if length (sss) < 3
55
+ # pad with zeros at the end
56
+ while length (sss) < 3
57
+ sss *= " 0"
58
+ end
59
+ newtimessszzz = supersec* " ." * sss* " -" * zzz
60
+ @debug " new time string: $newtimessszzz "
61
+ # reassembled ZonedDateTime is put back in the dict
62
+ interm[namestr] = newtimessszzz
63
+ end
64
+ end
65
+ end
66
+ nothing
67
+ end
68
+
26
69
function unpackVariable (dfg:: G ,
27
70
packedProps:: Dict{String, Any} ;
28
71
unpackPPEs:: Bool = true ,
@@ -76,7 +119,12 @@ function unpackVariable(dfg::G,
76
119
end
77
120
78
121
for (k,bdeInter) in dataIntermed
79
- fullVal = JSON2. read (bdeInter, getfield (DistributedFactorGraphs, dataElemTypes[k]))
122
+ # @debug "label=$label"
123
+ # @debug "bdeInter=$bdeInter"
124
+ interm = JSON. parse (bdeInter)
125
+ objType = getfield (DistributedFactorGraphs, dataElemTypes[k])
126
+ standardizeZDTString! (objType, interm)
127
+ fullVal = Unmarshal. unmarshal (objType, interm)
80
128
variable. dataDict[k] = fullVal
81
129
end
82
130
end
0 commit comments