Skip to content

Commit 229913c

Browse files
authored
Merge pull request #834 from JuliaRobotics/833/base64encode_factors
Resolving 833 with the workaround.
2 parents 51799f3 + cfcfc5e commit 229913c

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

src/CloudGraphsDFG/services/CloudGraphsDFG.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,9 @@ function getFactor(dfg::CloudGraphsDFG, label::Union{Symbol, String})
270270
length(result.results[1]["data"][1]["row"]) != 1 && error("Cannot get factor '$label'")
271271
props = result.results[1]["data"][1]["row"][1]
272272

273+
# NOTE: Until we address #590, base64 decode the data to ensure robustness, #833
274+
props["data"] = String(base64decode(props["data"]))
275+
273276
return rebuildFactorMetadata!(dfg, unpackFactor(dfg, props))
274277
end
275278

@@ -290,8 +293,6 @@ function updateFactor!(dfg::CloudGraphsDFG, factor::DFGFactor; warn_if_absent::B
290293
!exists(dfg, vlabel) && error("Variable '$(vlabel)' not found in graph when creating Factor '$(factor.label)'")
291294
end
292295

293-
props = packFactor(dfg, factor)
294-
295296
# Create/update the factor
296297
# NOTE: We are no merging the factor tags into the labels anymore. We can index by that but not
297298
# going to pollute the graph with unnecessary (and potentially dangerous) labels.

src/CloudGraphsDFG/services/CommonFunctions.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,9 @@ function _structToNeo4jProps(inst::Union{<:User, <:Robot, <:Session, PVND, N, AP
180180
# TODO: Consolidate with packFactor in Serialization.jl - https://github.com/JuliaRobotics/DistributedFactorGraphs.jl/issues/525
181181
if fieldname == :solverData
182182
fnctype = getSolverData(inst).fnc.usrfnc!
183-
val = _packSolverData( inst, fnctype; replaceBackslashes=true )
183+
# NOTE: Until we resolve #590, make this robust by base64 encoding this so that
184+
# generic JSON-packed factors do not have issues.
185+
val = "\"$(_packSolverData( inst, fnctype; base64Encode=true ))\""
184186
fieldname = :data #Keeping with FileDFG format
185187
end
186188
end

src/DistributedFactorGraphs.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ module DistributedFactorGraphs
1515
##==============================================================================
1616

1717
using Base
18+
using Base64
1819
using DocStringExtensions
1920
using Requires
2021
using Dates

src/services/Serialization.jl

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,14 +294,15 @@ end
294294
function _packSolverData(
295295
f::DFGFactor,
296296
fnctype::AbstractFactor;
297-
replaceBackslashes::Bool=false )
297+
base64Encode::Bool=false )
298298
#
299299
packtype = convertPackedType(fnctype)
300300
try
301301
packed = convert( PackedFunctionNodeData{packtype}, getSolverData(f) )
302302
packedJson = JSON2.write(packed)
303-
if replaceBackslashes
304-
return "\"$(replace(packedJson, "\"" => "\\\""))\"" # Escape slashes too
303+
if base64Encode
304+
# 833
305+
packedJson = base64encode(packedJson)
305306
end
306307
return packedJson
307308
catch ex

0 commit comments

Comments
 (0)