-
Notifications
You must be signed in to change notification settings - Fork 0
/
boltkv_iterator.go
54 lines (42 loc) · 970 Bytes
/
boltkv_iterator.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// Copyright (c) 2024 Benjamin Borbe All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package boltkv
import (
libkv "github.com/bborbe/kv"
bolt "go.etcd.io/bbolt"
)
type Iterator interface {
libkv.Iterator
Cursor() *bolt.Cursor
}
func NewIterator(boltCursor *bolt.Cursor) Iterator {
return &iterator{
boltCursor: boltCursor,
}
}
type iterator struct {
boltCursor *bolt.Cursor
key []byte
value []byte
}
func (i *iterator) Cursor() *bolt.Cursor {
return i.boltCursor
}
func (i *iterator) Close() {
}
func (i *iterator) Item() libkv.Item {
return libkv.NewByteItem(i.key, i.value)
}
func (i *iterator) Next() {
i.key, i.value = i.boltCursor.Next()
}
func (i *iterator) Valid() bool {
return i.key != nil
}
func (i *iterator) Rewind() {
i.key, i.value = i.boltCursor.First()
}
func (i *iterator) Seek(key []byte) {
i.key, i.value = i.boltCursor.Seek(key)
}