Skip to content

Commit a5b636a

Browse files
committed
Add & test more packedVariable blobEntry functions
1 parent b3f0945 commit a5b636a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/DataBlobs/services/BlobEntry.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ function getBlobEntry(var::AbstractDFGVariable, key::Symbol)
7979
return var.dataDict[key]
8080
end
8181

82+
function getBlobEntry(var::PackedVariable, key::Symbol)
83+
if !hasBlobEntry(var, key)
84+
throw(KeyError("No dataEntry label $(key) found in variable $(getLabel(var)). Available keys: $(keys(var.dataDict))"))
85+
end
86+
return var.blobEntries[findfirst(x->x.label == key, var.blobEntries)]
87+
end
88+
8289
function getBlobEntry(var::AbstractDFGVariable, blobId::UUID)
8390
for (k,v) in var.dataDict
8491
if blobId in [v.originId, v.blobId]
@@ -204,6 +211,9 @@ Does a blob entry (element) exist with `blobLabel`.
204211
"""
205212
hasBlobEntry(var::AbstractDFGVariable, blobLabel::Symbol) = haskey(var.dataDict, blobLabel)
206213

214+
function hasBlobEntry(var::PackedVariable, label::Symbol)
215+
return label in getproperty.(var.blobEntries, :label)
216+
end
207217

208218
"""
209219
$(SIGNATURES)
@@ -271,6 +281,10 @@ function listBlobEntries(var::AbstractDFGVariable)
271281
collect(keys(var.dataDict))
272282
end
273283

284+
function listBlobEntries(var::PackedVariable)
285+
return getproperty.(var.blobEntries, :label)
286+
end
287+
274288
function listBlobEntries(dfg::AbstractDFG, label::Symbol)
275289
# !isVariable(dfg, label) && return nothing
276290
listBlobEntries(getVariable(dfg, label))

test/testBlocks.jl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -943,6 +943,16 @@ function DataEntriesTestBlock!(fg, v2)
943943
@test deleteBlobEntry!(fg, :a, :key2) == de2_update
944944
@test listBlobEntries(v1) == Symbol[]
945945
deleteBlobEntry!(fg, :b, :key2)
946+
947+
# packed variable data entries
948+
pacv = packVariable(v1)
949+
@test addBlobEntry!(pacv, de1) == de1
950+
@test hasBlobEntry(pacv, :key1)
951+
@test deepcopy(de1) == getBlobEntry(pacv, :key1)
952+
@test getBlobEntries(pacv) == [deepcopy(de1)]
953+
@test issetequal(listBlobEntries(pacv), [:key1])
954+
# @test deleteBlobEntry!(pacv, de1) == de1
955+
946956
end
947957

948958
function blobsStoresTestBlock!(fg)

0 commit comments

Comments
 (0)