-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathBlobWrappers.jl
More file actions
198 lines (165 loc) · 4.92 KB
/
BlobWrappers.jl
File metadata and controls
198 lines (165 loc) · 4.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
##==============================================================================
## Blob + Blobentry CRUD interface
##==============================================================================
"""
Convenience wrapper to load a Blob for a given variable and Blobentry label.
$(METHODLIST)
"""
function loadBlob_Variable end
"""
Convenience wrapper to save a Blob to a Blobstore and a Blobentry to a variable.
$(METHODLIST)
"""
function saveBlob_Variable! end
"""
Convenience wrapper to delete a Blob form a Blobstore and its Blobentry from a variable.
$(METHODLIST)
"""
function deleteBlob_Variable! end
"""
Convenience wrapper to load a Blob for a given graph and Blobentry label.
$(METHODLIST)
"""
function loadBlob_Graph end
"""
Convenience wrapper to save a Blob to a Blobstore and a Blobentry to a graph.
$(METHODLIST)
"""
function saveBlob_Graph! end
"""
Convenience wrapper to delete a Blob from a Blobstore and its Blobentry from a graph.
$(METHODLIST)
"""
function deleteBlob_Graph! end
"""
Convenience wrapper to load a Blob for a given agent and Blobentry label.
$(METHODLIST)
"""
function loadBlob_Agent end
"""
Convenience wrapper to save a Blob to a Blobstore and a Blobentry to an agent.
$(METHODLIST)
"""
function saveBlob_Agent! end
"""
Convenience wrapper to delete a Blob from a Blobstore and its Blobentry from an agent.
$(METHODLIST)
"""
function deleteBlob_Agent! end
function loadBlob_Variable(
dfg::AbstractDFG,
variable_label::Symbol,
entry_label::Symbol;
# hashfunction = sha256,
# checkhash::Bool = true,
)
entry = getVariableBlobentry(dfg, variable_label, entry_label)
blob = getBlob(dfg, entry)
# checkhash && assertHash(de, db; hashfunction)
return entry, blob
end
function saveBlob_Variable!(
dfg::AbstractDFG,
variable_label::Symbol,
blob::Vector{UInt8},
entry::Blobentry,
)
addVariableBlobentry!(dfg, variable_label, entry)
addBlob!(dfg, entry, blob)
return entry
end
function saveBlob_Variable!(
dfg::AbstractDFG,
variable_label::Symbol,
blob::Vector{UInt8},
entry_label::Symbol,
blobstore::Symbol = :default;
blobentry_kwargs...,
)
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
return saveBlob_Variable!(dfg, variable_label, blob, entry)
end
function deleteBlob_Variable!(dfg::AbstractDFG, variable_label::Symbol, entry_label::Symbol)
entry = getVariableBlobentry(dfg, variable_label, entry_label)
deleteVariableBlobentry!(dfg, variable_label, entry_label)
deleteBlob!(dfg, entry)
return 2
end
function loadBlob_Graph(dfg::AbstractDFG, entry_label::Symbol;)
entry = getGraphBlobentry(dfg, entry_label)
blob = getBlob(dfg, entry)
return entry, blob
end
function saveBlob_Graph!(dfg::AbstractDFG, blob::Vector{UInt8}, entry::Blobentry)
addGraphBlobentry!(dfg, entry)
addBlob!(dfg, entry, blob)
return entry
end
function saveBlob_Graph!(
dfg::AbstractDFG,
blob::Vector{UInt8},
entry_label::Symbol,
blobstore::Symbol = :default;
blobentry_kwargs...,
)
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
return saveBlob_Graph!(dfg, blob, entry)
end
function deleteBlob_Graph!(dfg::AbstractDFG, entry_label::Symbol)
entry = getGraphBlobentry(dfg, entry_label)
deleteGraphBlobentry!(dfg, entry_label)
deleteBlob!(dfg, entry)
return 2
end
function loadBlob_Agent(dfg::AbstractDFG, entry_label::Symbol;)
entry = getAgentBlobentry(dfg, entry_label)
blob = getBlob(dfg, entry)
return entry, blob
end
function saveBlob_Agent!(dfg::AbstractDFG, blob::Vector{UInt8}, entry::Blobentry)
addAgentBlobentry!(dfg, entry)
addBlob!(dfg, entry, blob)
return entry
end
function saveBlob_Agent!(
dfg::AbstractDFG,
blob::Vector{UInt8},
entry_label::Symbol,
blobstore::Symbol = :default;
blobentry_kwargs...,
)
entry = Blobentry(entry_label, blobstore; blobentry_kwargs...)
return saveBlob_Agent!(dfg, blob, entry)
end
function deleteBlob_Agent!(dfg::AbstractDFG, entry_label::Symbol)
entry = getAgentBlobentry(dfg, entry_label)
deleteAgentBlobentry!(dfg, entry_label)
deleteBlob!(dfg, entry)
return 2
end
function saveImage_Variable!(
dfg::AbstractDFG,
variable_label::Symbol,
img::AbstractMatrix,
entry_label::Symbol,
blobstore::Symbol = :default;
entry_kwargs...,
)
mimeType = get(entry_kwargs, :mimeType, MIME("image/png"))
format = _MIMETypes[mimeType]
blob, mimeType = packBlob(format, img)
size = string(length(blob))
entry = Blobentry(
entry_label,
blobstore;
blobid = uuid4(),
entry_kwargs...,
size,
mimeType = string(mimeType),
)
return saveBlob_Variable!(dfg, variable_label, blob, entry)
end
function loadImage_Variable(dfg::AbstractDFG, variable_label::Symbol, entry_label::Symbol)
entry, blob = loadBlob_Variable(dfg, variable_label, entry_label)
return entry, unpackBlob(entry, blob)
end