Commit 63d3899e authored by Steven Allen's avatar Steven Allen

json: return an error when failing to unmarshal

parent 7ef20da6
......@@ -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
......
......@@ -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.
......
......@@ -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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment