diff options
Diffstat (limited to 'util/bloom/bloom.go')
-rw-r--r-- | util/bloom/bloom.go | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/util/bloom/bloom.go b/util/bloom/bloom.go index cee316e32..eeffc88ef 100644 --- a/util/bloom/bloom.go +++ b/util/bloom/bloom.go @@ -118,31 +118,22 @@ func BinaryMarshalLength(numElements int, falsePositiveRate float64) int64 { return filterBytes + 8 // adding 8 to match 4 prefix array, plus 4 bytes for the numHashes uint32 } -// UnmarshalBinary implements encoding.BinaryUnmarshaller interface -func (f *Filter) UnmarshalBinary(data []byte) error { +// UnmarshalBinary restores the state of the filter from raw data +func UnmarshalBinary(data []byte) (*Filter, error) { + f := &Filter{} if len(data) <= 8 { - return errors.New("short data") + return nil, errors.New("short data") } f.numHashes = binary.BigEndian.Uint32(data[0:4]) if f.numHashes > maxHashes { - return errors.New("too many hashes") + return nil, errors.New("too many hashes") } copy(f.prefix[:], data[4:8]) f.data = data[8:] f.preimageStagingBuffer = make([]byte, len(f.prefix), len(f.prefix)+32) f.hashStagingBuffer = make([]uint32, f.numHashes+3) copy(f.preimageStagingBuffer, f.prefix[:]) - return nil -} - -// UnmarshalBinary restores the state of the filter from raw data -func UnmarshalBinary(data []byte) (*Filter, error) { - f := &Filter{} - err := f.UnmarshalBinary(data) - if err != nil { - f = nil - } - return f, err + return f, nil } // MarshalJSON defines how this filter should be encoded to JSON |