github.com/ethersphere/bee/v2@v2.2.0/pkg/storage/statestore.go (about)

     1  // Copyright 2023 The Swarm Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package storage
     6  
     7  import (
     8  	"io"
     9  )
    10  
    11  // StateIterFunc is used when iterating through StateStorer key/value pairs
    12  type StateIterFunc func(key, val []byte) (stop bool, err error)
    13  
    14  // StateStorer is a storage interface for storing and retrieving key/value pairs.
    15  type StateStorer interface {
    16  	io.Closer
    17  
    18  	// Get unmarshalls object with the given key into the given obj.
    19  	Get(key string, obj interface{}) error
    20  
    21  	// Put inserts or updates the given obj stored under the given key.
    22  	Put(key string, obj interface{}) error
    23  
    24  	// Delete removes object form the store stored under the given key.
    25  	Delete(key string) error
    26  
    27  	// Iterate iterates over all keys with the given prefix and calls iterFunc.
    28  	Iterate(prefix string, iterFunc StateIterFunc) error
    29  }
    30  
    31  // StateStorerCleaner is the interface for cleaning the store.
    32  type StateStorerCleaner interface {
    33  	// Nuke the store so that only the bare essential entries are left.
    34  	Nuke() error
    35  	// ClearForHopping removes all data not required in a new neighborhood
    36  	ClearForHopping() error
    37  }
    38  
    39  // StateStorerManager defines all external methods of the state storage
    40  type StateStorerManager interface {
    41  	StateStorer
    42  	StateStorerCleaner
    43  }