Ori Newman ec446ac511
Adding DAA score (#1596)
* Save DAA score and DAA added blocks for each block

* Add test

* Add pruning support

* Replace 8 with uint64Length

* Separate DAABlocksStore cache size to DAA score and daaAddedBlocks
2021-03-14 09:44:44 +02:00

25 lines
622 B
Go

package binaryserialization
import (
"encoding/binary"
"github.com/pkg/errors"
)
const uint64Length = 8
// SerializeUint64 serializes a uint64
func SerializeUint64(value uint64) []byte {
var keyBytes [uint64Length]byte
binary.LittleEndian.PutUint64(keyBytes[:], value)
return keyBytes[:]
}
// DeserializeUint64 deserializes bytes to uint64
func DeserializeUint64(valueBytes []byte) (uint64, error) {
if len(valueBytes) != uint64Length {
return 0, errors.Errorf("the given value is %d bytes so it cannot be deserialized into uint64",
len(valueBytes))
}
return binary.LittleEndian.Uint64(valueBytes), nil
}