Skip to content

Commit c0bc0c7

Browse files
authored
Merge pull request #589 from JuliaRobotics/blobstore_fix
Test fix for BlobStoreEntry
2 parents 309932b + bcdc685 commit c0bc0c7

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

src/services/Serialization.jl

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22
# For all types that pack their type into their own structure (e.g. PPE)
33
const TYPEKEY = "_type"
44

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+
513
##==============================================================================
614
## Variable Packing and unpacking
715
##==============================================================================
@@ -18,11 +26,46 @@ function packVariable(dfg::G, v::DFGVariable)::Dict{String, Any} where G <: Abst
1826
props["softtype"] = string(typeof(getSofttype(v)))
1927
# props["bigData"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> JSON2.write(bde), values(v.dataDict))))
2028
# 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+
2231
props["dataEntryType"] = JSON2.write(Dict(keys(v.dataDict) .=> map(bde -> typeof(bde), values(v.dataDict))))
2332
return props
2433
end
2534

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+
2669
function unpackVariable(dfg::G,
2770
packedProps::Dict{String, Any};
2871
unpackPPEs::Bool=true,
@@ -76,7 +119,12 @@ function unpackVariable(dfg::G,
76119
end
77120

78121
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)
80128
variable.dataDict[k] = fullVal
81129
end
82130
end

0 commit comments

Comments
 (0)