Skip to content

Commit d5d26e7

Browse files
GearsADdehann
andcommitted
Working through serialization and blobs.
Co-authored-by: Dehann Fourie <[email protected]>
1 parent b0399e3 commit d5d26e7

25 files changed

+1379
-1106
lines changed

Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ Reexport = "189a3867-3050-52da-a836-e630ba90ab69"
2222
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
2323
SHA = "ea8e919c-243c-51af-8825-aaa63cd721ce"
2424
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
25+
StructTypes = "856f2bd8-1eba-4b0a-8007-ebc267875bd4"
2526
TensorCast = "02d47bb6-7ce6-556a-be16-bb1710789e2b"
2627
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
2728
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
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)