diff options
author | EuAndreh <eu@euandre.org> | 2025-02-17 05:08:05 -0300 |
---|---|---|
committer | EuAndreh <eu@euandre.org> | 2025-02-17 05:08:05 -0300 |
commit | 66d11c734e3ee2490f0c5d132fc85ab44ac36bf9 (patch) | |
tree | e15d3a585e3d7514439e462b6c8f15deb2b0d9b4 | |
parent | src/dedo.go: Add DatabaseI.OnCommit() (diff) | |
download | dedo-66d11c734e3ee2490f0c5d132fc85ab44ac36bf9.tar.gz dedo-66d11c734e3ee2490f0c5d132fc85ab44ac36bf9.tar.xz |
src/dedo.go: Add public ID2Bytes() and Bytes2ID() functions
-rw-r--r-- | src/dedo.go | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/dedo.go b/src/dedo.go index 84c8857..ae15ff2 100644 --- a/src/dedo.go +++ b/src/dedo.go @@ -918,15 +918,19 @@ func (b *bucketT) Delete(key []byte) error { return bucketDelete(b, key) } -func bytesLE(num uint64) []byte { +func ID2Bytes(num uint64) []byte { arr := make([]byte, 8) - binary.LittleEndian.PutUint64(arr, uint64(num)) + binary.LittleEndian.PutUint64(arr, num) return arr } +func Bytes2ID(bytes []byte) uint64 { + return binary.LittleEndian.Uint64(bytes) +} + func bucketNextID(b *bucketT) []byte { id := g.Must(b.NextSequence()) - return bytesLE(id) + return ID2Bytes(id) } func (b *bucketT) NextID() []byte { @@ -1939,7 +1943,7 @@ func (bucket *inMemoryValueT) Put(key []byte, value []byte) error { func (bucket *inMemoryValueT) NextID() []byte { id := g.Must(bucket.NextSequence()) - return bytesLE(id) + return ID2Bytes(id) } func (bucket *inMemoryValueT) NextSequence() (uint64, error) { |