storage

package
v0.1.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 16, 2026 License: BSD-3-Clause Imports: 6 Imported by: 0

Documentation

Overview

Package storage provides storage abstractions for the session layer. Implementations can use different backends (memory, LevelDB, Pebble, etc.)

Index

Constants

This section is empty.

Variables

View Source
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")
)
View Source
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

type BatchWriter interface {
	Store

	// NewBatch creates a new batch.
	NewBatch() Batch
}

BatchWriter supports batch writes for efficiency.

type BinaryCodec

type BinaryCodec struct{}

BinaryCodec is a simple binary encoder/decoder.

func NewBinaryCodec

func NewBinaryCodec() *BinaryCodec

NewBinaryCodec creates a new binary codec.

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) Close

func (m *MemoryStore) Close() error

Close closes the store.

func (*MemoryStore) Delete

func (m *MemoryStore) Delete(key []byte) error

Delete removes a key.

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) NewBatch

func (m *MemoryStore) NewBatch() Batch

NewBatch creates a new batch.

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

func NewNamespace(store Store, prefix []byte) *Namespace

NewNamespace creates a namespaced view of a store.

func (*Namespace) Close

func (n *Namespace) Close() error

Close closes the underlying store.

func (*Namespace) Delete

func (n *Namespace) Delete(key []byte) error

Delete removes a key.

func (*Namespace) Get

func (n *Namespace) Get(key []byte) ([]byte, error)

Get retrieves a value by key.

func (*Namespace) Has

func (n *Namespace) Has(key []byte) (bool, error)

Has checks if a key exists.

func (*Namespace) Put

func (n *Namespace) Put(key, value []byte) error

Put stores a value by key.

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.

func (*SessionStore) Get

func (s *SessionStore) Get(id core.ID) (*core.Session, error)

Get retrieves a session by ID.

func (*SessionStore) Has

func (s *SessionStore) Has(id core.ID) (bool, error)

Has checks if a session exists.

func (*SessionStore) Put

func (s *SessionStore) Put(session *core.Session) error

Put stores 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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL