Skip to content

Commit 08b2109

Browse files
authored
Merge pull request #962 from JuliaRobotics/feature/prep_dfg20
Working through serialization and blobs for DFG 0.20
2 parents b0399e3 + 6e6f87f commit 08b2109

26 files changed

+1448
-1138
lines changed

Project.toml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
99
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
1010
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
1111
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
12-
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
13-
JSON2 = "2535ab7d-5cd8-5a07-80ac-9b1792aadce3"
1412
JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
1513
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
1614
ManifoldsBase = "3362f125-f0bb-47a3-aa74-596ffd7ef2fb"
@@ -22,6 +20,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2220
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2321
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2422
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
23+
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
2524
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
2625
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
2726
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
@@ -32,8 +31,6 @@ Distributions = "0.23, 0.24, 0.25"
3231
DocStringExtensions = "0.8, 0.9"
3332
GraphPlot = "0.5.0"
3433
Graphs = "1.4"
35-
JSON = "0.21"
36-
JSON2 = "0.3.1"
3734
JSON3 = "1"
3835
ManifoldsBase = "0.12, 0.13, 0.14"
3936
OrderedCollections = "1.4"
Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
11

22

3-
# @generated function ==(x::FileDataEntry, y::FileDataEntry)
3+
# @generated function ==(x::BlobEntry, y::BlobEntry)
44
# mapreduce(n -> :(x.$n == y.$n), (a,b)->:($a && $b), fieldnames(x))
55
# end
66

77
#
8-
# getHash(entry::AbstractDataEntry) = hex2bytes(entry.hash)
8+
# getHash(entry::AbstractBlobEntry) = hex2bytes(entry.hash)
99

1010

1111
##==============================================================================
12-
## FileDataEntry Common
12+
## BlobEntry Common
1313
##==============================================================================
14-
blobfilename(entry::FileDataEntry) = joinpath(entry.folder,"$(entry.id).dat")
15-
entryfilename(entry::FileDataEntry) = joinpath(entry.folder,"$(entry.id).json")
14+
blobfilename(entry::BlobEntry) = joinpath(entry.folder,"$(entry.id).dat")
15+
entryfilename(entry::BlobEntry) = joinpath(entry.folder,"$(entry.id).json")
1616

1717

1818
##==============================================================================
19-
## FileDataEntry Blob CRUD
19+
## BlobEntry Blob CRUD
2020
##==============================================================================
2121

22-
function getDataBlob(dfg::AbstractDFG, entry::FileDataEntry)
22+
function getBlob(dfg::AbstractDFG, entry::BlobEntry)
2323
if isfile(blobfilename(entry))
2424
open(blobfilename(entry)) do f
2525
return read(f)
@@ -30,7 +30,7 @@ function getDataBlob(dfg::AbstractDFG, entry::FileDataEntry)
3030
end
3131
end
3232

33-
function addDataBlob!(dfg::AbstractDFG, entry::FileDataEntry, data::Vector{UInt8})
33+
function addBlob!(dfg::AbstractDFG, entry::BlobEntry, data::Vector{UInt8})
3434
if isfile(blobfilename(entry))
3535
error("Key '$(entry.id)' blob already exists.")
3636
elseif isfile(entryfilename(entry))
@@ -42,37 +42,37 @@ function addDataBlob!(dfg::AbstractDFG, entry::FileDataEntry, data::Vector{UInt8
4242
open(entryfilename(entry), "w") do f
4343
JSON.print(f, entry)
4444
end
45-
return getDataBlob(dfg, entry)::Vector{UInt8}
45+
return getBlob(dfg, entry)::Vector{UInt8}
4646
end
4747
end
4848

49-
function updateDataBlob!(dfg::AbstractDFG, entry::FileDataEntry, data::Vector{UInt8})
49+
function updateBlob!(dfg::AbstractDFG, entry::BlobEntry, data::Vector{UInt8})
5050
if !isfile(blobfilename(entry))
5151
@warn "Entry '$(entry.id)' does not exist, adding."
52-
return addDataBlob!(dfg, entry, data)
52+
return addBlob!(dfg, entry, data)
5353
else
5454
# perhaps add an explicit force update flag and error otherwise
5555
@warn "Key '$(entry.id)' already exists, data will be overwritten."
56-
deleteDataBlob!(dfg, entry)
57-
return addDataBlob!(dfg, entry, data)
56+
deleteBlob!(dfg, entry)
57+
return addBlob!(dfg, entry, data)
5858
end
5959
end
6060

61-
function deleteDataBlob!(dfg::AbstractDFG, entry::FileDataEntry)
62-
data = getDataBlob(dfg, entry)
61+
function deleteBlob!(dfg::AbstractDFG, entry::BlobEntry)
62+
data = getBlob(dfg, entry)
6363
rm(blobfilename(entry))
6464
rm(entryfilename(entry))
6565
return data
6666
end
6767

6868
##==============================================================================
69-
## FileDataEntry CRUD Helpers
69+
## BlobEntry CRUD Helpers
7070
##==============================================================================
7171

72-
function addData!(::Type{FileDataEntry}, dfg::AbstractDFG, label::Symbol, key::Symbol, folder::String, blob::Vector{UInt8}, timestamp=now(localzone());
72+
function addData!(::Type{BlobEntry}, dfg::AbstractDFG, label::Symbol, key::Symbol, folder::String, blob::Vector{UInt8}, timestamp=now(localzone());
7373
id::UUID = uuid4(), hashfunction = sha256)
74-
fde = FileDataEntry(key, id, folder, bytes2hex(hashfunction(blob)), timestamp)
74+
fde = BlobEntry(key, id, folder, bytes2hex(hashfunction(blob)), timestamp)
7575
de = addDataEntry!(dfg, label, fde)
76-
db = addDataBlob!(dfg, fde, blob)
76+
db = addBlob!(dfg, fde, blob)
7777
return de=>db
7878
end

0 commit comments

Comments
 (0)