mirror of
https://github.com/kaspanet/kaspad.git
synced 2025-05-31 11:16:42 +00:00

* 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
25 lines
622 B
Go
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
|
|
}
|