Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
10
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
dms3
bbloom
Commits
63d3899e
Commit
63d3899e
authored
Aug 23, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
json: return an error when failing to unmarshal
parent
7ef20da6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
11 additions
and
5 deletions
+11
-5
README.md
README.md
+1
-1
bbloom.go
bbloom.go
+6
-3
bbloom_test.go
bbloom_test.go
+4
-1
No files found.
README.md
View file @
63d3899e
...
...
@@ -96,7 +96,7 @@ Json = bf.JSONMarshal()
bf
.
Mtx
.
Unlock
()
// restore a bloom filter from storage
bfNew
:=
bbloom
.
JSONUnmarshal
(
Json
)
bfNew
,
_
:=
bbloom
.
JSONUnmarshal
(
Json
)
isInNew
:=
bfNew
.
Has
([]
byte
(
"butter"
))
// should be true
isNotInNew
:=
bfNew
.
Has
([]
byte
(
"Butter"
))
// should be false
...
...
bbloom.go
View file @
63d3899e
...
...
@@ -264,11 +264,14 @@ func (bl *Bloom) JSONMarshalTS() ([]byte, error) {
// JSONUnmarshal
// takes JSON-Object (type bloomJSONImExport) as []bytes
// returns bloom32 / bloom64 object
func
JSONUnmarshal
(
dbData
[]
byte
)
*
Bloom
{
func
JSONUnmarshal
(
dbData
[]
byte
)
(
*
Bloom
,
error
)
{
bloomImEx
:=
bloomJSONImExport
{}
json
.
Unmarshal
(
dbData
,
&
bloomImEx
)
err
:=
json
.
Unmarshal
(
dbData
,
&
bloomImEx
)
if
err
!=
nil
{
return
nil
,
err
}
bf
:=
NewWithBoolset
(
bloomImEx
.
FilterSet
,
bloomImEx
.
SetLocs
)
return
bf
return
bf
,
nil
}
// FillRatio returns the fraction of bits set.
...
...
bbloom_test.go
View file @
63d3899e
...
...
@@ -75,7 +75,10 @@ func TestM_JSON(t *testing.T) {
}
// create new bloomfilter from bloomfilter's JSON representation
bf2
:=
JSONUnmarshal
(
Json
)
bf2
,
err
:=
JSONUnmarshal
(
Json
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
cnt2
:=
0
for
i
:=
range
wordlist1
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment