You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
822 B
36 lines
822 B
3 years ago
|
package prefix
|
||
|
|
||
|
import (
|
||
|
"bytes"
|
||
|
|
||
|
"github.com/ethereum/go-ethereum/ethdb"
|
||
|
)
|
||
|
|
||
|
type PrefixBatchReplay struct {
|
||
|
prefix []byte
|
||
|
prefixLen int
|
||
|
w ethdb.KeyValueWriter
|
||
|
}
|
||
|
|
||
|
func newPrefixBatchReplay(prefix []byte, w ethdb.KeyValueWriter) *PrefixBatchReplay {
|
||
|
return &PrefixBatchReplay{prefix: prefix, prefixLen: len(prefix), w: w}
|
||
|
}
|
||
|
|
||
|
// Put inserts the given value into the key-value data store.
|
||
|
func (p *PrefixBatchReplay) Put(key []byte, value []byte) error {
|
||
|
if bytes.HasPrefix(key, p.prefix) {
|
||
|
return p.w.Put(key[p.prefixLen:], value)
|
||
|
} else {
|
||
|
return p.w.Put(key, value)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Delete removes the key from the key-value data store.
|
||
|
func (p *PrefixBatchReplay) Delete(key []byte) error {
|
||
|
if bytes.HasPrefix(key, p.prefix) {
|
||
|
return p.w.Delete(key[p.prefixLen:])
|
||
|
} else {
|
||
|
return p.w.Delete(key)
|
||
|
}
|
||
|
}
|