Documentation
¶
Overview ¶
Package storage provides storage abstractions for the session layer. Implementations can use different backends (memory, LevelDB, Pebble, etc.)
Index ¶
- Variables
- type Batch
- type BatchWriter
- type BinaryCodec
- type Codec
- type IterableStore
- type Iterator
- type MemoryStore
- func (m *MemoryStore) Close() error
- func (m *MemoryStore) Delete(key []byte) error
- func (m *MemoryStore) Get(key []byte) ([]byte, error)
- func (m *MemoryStore) Has(key []byte) (bool, error)
- func (m *MemoryStore) NewBatch() Batch
- func (m *MemoryStore) NewIterator(start, end []byte) Iterator
- func (m *MemoryStore) Put(key, value []byte) error
- type Namespace
- type SessionStore
- type Store
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNotFound is returned when a key is not found. ErrNotFound = errors.New("not found") // ErrClosed is returned when the store is closed. ErrClosed = errors.New("store closed") )
var ( PrefixSession = []byte("session:") PrefixStep = []byte("step:") PrefixOracle = []byte("oracle:") PrefixReceipt = []byte("receipt:") PrefixAttestation = []byte("attest:") PrefixNode = []byte("node:") PrefixEpoch = []byte("epoch:") )
Storage namespaces (prefixes).
Functions ¶
This section is empty.
Types ¶
type Batch ¶
type Batch interface {
// Put adds a put operation to the batch.
Put(key, value []byte) error
// Delete adds a delete operation to the batch.
Delete(key []byte) error
// Write executes all operations in the batch.
Write() error
// Reset clears the batch.
Reset()
// Size returns the number of operations in the batch.
Size() int
}
Batch represents a batch of writes.
type BatchWriter ¶
BatchWriter supports batch writes for efficiency.
type BinaryCodec ¶
type BinaryCodec struct{}
BinaryCodec is a simple binary encoder/decoder.
func (*BinaryCodec) DecodeSession ¶
func (c *BinaryCodec) DecodeSession(data []byte) (*core.Session, error)
DecodeSession decodes bytes to a session.
func (*BinaryCodec) DecodeStep ¶
func (c *BinaryCodec) DecodeStep(data []byte) (*core.Step, error)
DecodeStep decodes bytes to a step.
func (*BinaryCodec) EncodeSession ¶
func (c *BinaryCodec) EncodeSession(s *core.Session) ([]byte, error)
EncodeSession encodes a session to bytes.
func (*BinaryCodec) EncodeStep ¶
func (c *BinaryCodec) EncodeStep(s *core.Step) ([]byte, error)
EncodeStep encodes a step to bytes.
type Codec ¶
type Codec interface {
// EncodeSession encodes a session to bytes.
EncodeSession(s *core.Session) ([]byte, error)
// DecodeSession decodes bytes to a session.
DecodeSession(data []byte) (*core.Session, error)
// EncodeStep encodes a step to bytes.
EncodeStep(s *core.Step) ([]byte, error)
// DecodeStep decodes bytes to a step.
DecodeStep(data []byte) (*core.Step, error)
}
Codec handles serialization and deserialization. Default implementation uses a simple binary format.
type IterableStore ¶
type IterableStore interface {
Store
// NewIterator creates an iterator over keys in [start, end).
NewIterator(start, end []byte) Iterator
}
IterableStore supports iteration over keys.
type Iterator ¶
type Iterator interface {
// Next advances the iterator.
Next() bool
// Key returns the current key.
Key() []byte
// Value returns the current value.
Value() []byte
// Error returns any error encountered.
Error() error
// Release releases the iterator.
Release()
}
Iterator iterates over keys in a range.
type MemoryStore ¶
type MemoryStore struct {
// contains filtered or unexported fields
}
MemoryStore is an in-memory implementation of Store. Useful for testing and ephemeral data.
func NewMemoryStore ¶
func NewMemoryStore() *MemoryStore
NewMemoryStore creates a new in-memory store.
func (*MemoryStore) Get ¶
func (m *MemoryStore) Get(key []byte) ([]byte, error)
Get retrieves a value by key.
func (*MemoryStore) Has ¶
func (m *MemoryStore) Has(key []byte) (bool, error)
Has checks if a key exists.
func (*MemoryStore) NewIterator ¶
func (m *MemoryStore) NewIterator(start, end []byte) Iterator
NewIterator creates an iterator over keys in [start, end).
func (*MemoryStore) Put ¶
func (m *MemoryStore) Put(key, value []byte) error
Put stores a value by key.
type Namespace ¶
type Namespace struct {
// contains filtered or unexported fields
}
Namespace prefixes keys for logical separation.
func NewNamespace ¶
NewNamespace creates a namespaced view of a store.
type SessionStore ¶
type SessionStore struct {
// contains filtered or unexported fields
}
SessionStore provides session-specific storage operations.
func NewSessionStore ¶
func NewSessionStore(store Store) *SessionStore
NewSessionStore creates a new session store.
func (*SessionStore) Delete ¶
func (s *SessionStore) Delete(id core.ID) error
Delete removes a session.
type Store ¶
type Store interface {
// Get retrieves a value by key.
Get(key []byte) ([]byte, error)
// Put stores a value by key.
Put(key, value []byte) error
// Delete removes a key.
Delete(key []byte) error
// Has checks if a key exists.
Has(key []byte) (bool, error)
// Close closes the store.
Close() error
}
Store is the core key-value storage interface. All storage implementations must satisfy this interface.