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
b9a35a59
Commit
b9a35a59
authored
Aug 23, 2019
by
Steven Allen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
revert: don't allow marshal to fail
This is a _bug_, not an error.
parent
63d3899e
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
6 deletions
+14
-6
bbloom.go
bbloom.go
+12
-4
bbloom_test.go
bbloom_test.go
+2
-2
No files found.
bbloom.go
View file @
b9a35a59
...
...
@@ -24,6 +24,7 @@ import (
"encoding/binary"
"encoding/json"
"errors"
"log"
"math"
"math/bits"
"sync"
...
...
@@ -248,17 +249,24 @@ func (bl *Bloom) marshal() bloomJSONImExport {
// JSONMarshal
// returns JSON-object (type bloomJSONImExport) as []byte
func
(
bl
*
Bloom
)
JSONMarshal
()
(
[]
byte
,
error
)
{
func
(
bl
*
Bloom
)
JSONMarshal
()
[]
byte
{
data
,
err
:=
json
.
Marshal
(
bl
.
marshal
())
return
data
,
err
if
err
!=
nil
{
log
.
Fatal
(
"json.Marshal failed: "
,
err
)
}
return
data
}
// JSONMarshalTS is a thread-safe version of JSONMarshal
func
(
bl
*
Bloom
)
JSONMarshalTS
()
(
[]
byte
,
error
)
{
func
(
bl
*
Bloom
)
JSONMarshalTS
()
[]
byte
{
bl
.
Mtx
.
RLock
()
export
:=
bl
.
marshal
()
bl
.
Mtx
.
RUnlock
()
return
json
.
Marshal
(
export
)
data
,
err
:=
json
.
Marshal
(
export
)
if
err
!=
nil
{
log
.
Fatal
(
"json.Marshal failed: "
,
err
)
}
return
data
}
// JSONUnmarshal
...
...
bbloom_test.go
View file @
b9a35a59
...
...
@@ -69,13 +69,13 @@ func TestM_JSON(t *testing.T) {
}
}
J
son
,
err
:=
bf
.
JSONMarshal
()
j
son
:=
bf
.
JSONMarshal
()
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
// create new bloomfilter from bloomfilter's JSON representation
bf2
,
err
:=
JSONUnmarshal
(
J
son
)
bf2
,
err
:=
JSONUnmarshal
(
j
son
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
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